当前位置: 首页>>代码示例>>C++>>正文


C++ EventDispatcher::dispose方法代码示例

本文整理汇总了C++中EventDispatcher::dispose方法的典型用法代码示例。如果您正苦于以下问题:C++ EventDispatcher::dispose方法的具体用法?C++ EventDispatcher::dispose怎么用?C++ EventDispatcher::dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventDispatcher的用法示例。


在下文中一共展示了EventDispatcher::dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testCallbacks

static void testCallbacks() {
	EventDispatcher * dispatcher;
	char * sender1 = "1", * sender2 = "2";
	int callback1Context = 0, callback2Context = 0;
	int incrementation = 2;
	bool handled;
	Atom event1Atom, event2Atom;
	
	dispatcher = EventDispatcher_create(sender1);
	
	event1Atom = Atom_fromString("event1");
	event2Atom = Atom_fromString("event2");
	handled = dispatcher->dispatchEvent(dispatcher, event1Atom, &incrementation);
	TestCase_assert(!handled, "Event handled when no callbacks are registered");
	
	dispatcher->registerForEvent(dispatcher, event1Atom, callback1, &callback1Context);
	handled = dispatcher->dispatchEvent(dispatcher, event1Atom, &incrementation);
	TestCase_assert(handled, "Event not handled when appropriate callback was registered");
	TestCase_assert(callback1Context == 2, "Expected 2 but got %d", callback1Context);
	TestCase_assert(lastSender == sender1, "Expected %p but got %p", sender1, lastSender);
	
	incrementation = 3;
	dispatcher->dispatchEvent(dispatcher, event2Atom, &incrementation);
	TestCase_assert(callback1Context == 2, "Callback called for wrong type of event");
	
	dispatcher->registerForEvent(dispatcher, event2Atom, callback2, &callback2Context);
	handled = dispatcher->dispatchEvent(dispatcher, event2Atom, &incrementation);
	TestCase_assert(callback2Context == 3, "Expected 3 but got %d", callback2Context);
	TestCase_assert(!handled, "Expected false but got true");
	
	dispatcher->unregisterForEvent(dispatcher, event1Atom, callback1, NULL);
	handled = dispatcher->dispatchEvent(dispatcher, event1Atom, &incrementation);
	TestCase_assert(handled, "Event not still handled after unregistering callbacks with the wrong context");
	
	dispatcher->unregisterForEvent(dispatcher, event1Atom, callback1, &callback1Context);
	handled = dispatcher->dispatchEvent(dispatcher, event1Atom, &incrementation);
	TestCase_assert(!handled, "Event still handled after unregistering callbacks");
	
	incrementation = 1;
	handled = dispatcher->dispatchEvent(dispatcher, event2Atom, &incrementation);
	TestCase_assert(callback2Context == 4, "Expected 4 but got %d", callback2Context);
	TestCase_assert(!handled, "Expected false but got true");
	
	dispatcher->dispose(dispatcher);
	
	dispatcher = EventDispatcher_create(sender2);
	dispatcher->registerForEvent(dispatcher, event1Atom, callback1, &callback1Context);
	dispatcher->dispatchEvent(dispatcher, event1Atom, &incrementation);
	TestCase_assert(lastSender == sender2, "Expected %p but got %p", sender2, lastSender);
	
	dispatcher->dispose(dispatcher);
}
开发者ID:svn2github,项目名称:libstem,代码行数:52,代码来源:EventDispatcherTest.c


注:本文中的EventDispatcher::dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。