本文整理汇总了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);
}