Add test case for issue#9898

This commit is contained in:
WenhaiLin 2015-01-13 18:37:45 +08:00
parent de645a7c9c
commit 13481ea5c2
2 changed files with 48 additions and 1 deletions

View File

@ -28,7 +28,8 @@ std::function<Layer*()> createFunctions[] =
CL(Issue4129),
CL(Issue4160),
CL(DanglingNodePointersTest),
CL(RegisterAndUnregisterWhileEventHanldingTest)
CL(RegisterAndUnregisterWhileEventHanldingTest),
CL(Issue9898)
};
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
@ -1454,3 +1455,36 @@ std::string RegisterAndUnregisterWhileEventHanldingTest::subtitle() const
{
return "Tap the square multiple times - should not crash!";
}
Issue9898::Issue9898()
{
auto origin = Director::getInstance()->getVisibleOrigin();
auto size = Director::getInstance()->getVisibleSize();
auto nodeA = Node::create();
addChild(nodeA);
_listener = cocos2d::EventListenerCustom::create("Issue9898", [&](cocos2d::EventCustom *event){
_eventDispatcher->removeEventListener(_listener);
_eventDispatcher->dispatchCustomEvent("Issue9898");
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, nodeA);
auto menuItem = MenuItemFont::create("Dispatch Custom Event", [&](Ref *sender) {
_eventDispatcher->dispatchCustomEvent("Issue9898");
});
menuItem->setPosition(origin.x + size.width/2, origin.y + size.height/2);
auto menu = Menu::create(menuItem, nullptr);
menu->setPosition(Vec2::ZERO);
addChild(menu);
}
std::string Issue9898::title() const
{
return "";
}
std::string Issue9898::subtitle() const
{
return "Should not crash if dispatch event after remove\n event listener in callback";
}

View File

@ -227,4 +227,17 @@ public:
virtual std::string subtitle() const override;
};
class Issue9898 : public EventDispatcherTestDemo
{
public:
CREATE_FUNC(Issue9898);
Issue9898();
virtual std::string title() const override;
virtual std::string subtitle() const override;
private:
EventListenerCustom* _listener;
};
#endif /* defined(__samples__NewEventDispatcherTest__) */