Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionManagerTests CrashTest refinment. #2156

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions tests/cpp-tests/Source/ActionManagerTest/ActionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,43 +68,71 @@ std::string ActionManagerTest::subtitle() const

//------------------------------------------------------------------
//
// Test1
// CrashTest
//
//------------------------------------------------------------------

void CrashTest::onEnter()
{
ActionManagerTest::onEnter();

auto child = Sprite::create(s_pathGrossini);
child->setPosition(VisibleRect::center());
addChild(child, 1, kTagGrossini);
auto explanationLabel = Label::createWithTTF("Remove Node during ongoing ActionInterval. AXMOL must not crash.", "fonts/Thonburi.ttf", 16.0f);
addChild(explanationLabel);
explanationLabel->setPosition(VisibleRect::center().x, VisibleRect::top().y - 75);

auto grossiniSprite = Sprite::create(s_pathGrossini);
grossiniSprite->setPosition(VisibleRect::center());
addChild(grossiniSprite, 1, kTagGrossini);

// Grossini should be rotated by 90 degrees during 3000ms,
// but rotation will be interruped at 1500ms by call of removeThis() callback.
AXLOGI("Create RotateBy ActionInterval which should last for 3000 ms");
grossiniSprite->runAction(RotateBy::create(3.0f, 90));

// This Sequence of 4 Actions will be started at the same frame as Grossini rotation,
// but also will not be finished because of removeThis() callback call.
AXLOGI("Create Sequence of 4 Actions: DelayTime (1500ms), CrashTest::logCbkAfterDelayTime, Fadeout (1500ms), CrashTest::logCbkAfterFadeOut");
grossiniSprite->runAction(Sequence::create(DelayTime::create(1.5f),
CallFunc::create(AX_CALLBACK_0(CrashTest::logCbkAfterDelayTime, this)),
FadeOut::create(1.5f),
CallFunc::create(AX_CALLBACK_0(CrashTest::logCbkAfterFadeOut, this)),
nullptr));

// This Sequence of 2 Actions will be started at the same frame as Grossini rotation.
// At 1500ms Grossini will be removed by the call of removeThis() callback. At that point
// RotateBy Action will still be ongoing and FadeOut Action will be created. AXMOL must not crash at that point.
AXLOGI("Create Sequence of 2 Actions: DelayTime (1500ms), CrashTest::removeThis");
grossiniSprite->runAction(Sequence::create(DelayTime::create(1.5f),
CallFunc::create(AX_CALLBACK_0(CrashTest::removeThis, this)),
nullptr));
}

// Sum of all action's duration is 1.5 second.
child->runAction(RotateBy::create(1.5f, 90));
child->runAction(Sequence::create(DelayTime::create(1.4f), FadeOut::create(1.1f), nullptr));
void CrashTest::removeThis()
{
AXLOGI("CrashTest::removeThis() is called");

// After 1.5 second, self will be removed.
child->runAction(Sequence::create(DelayTime::create(1.4f),
CallFunc::create(AX_CALLBACK_0(CrashTest::removeThis, this)), nullptr));
auto grossiniSprite = getChildByTag(kTagGrossini);
removeChild(grossiniSprite, true);
}

void CrashTest::removeThis()
void CrashTest::logCbkAfterDelayTime()
{
auto child = getChildByTag(kTagGrossini);
child->removeChild(child, true);
AXLOGI("CrashTest::logCbkAfterDelayTime() is called");
}

getTestSuite()->enterNextTest();
void CrashTest::logCbkAfterFadeOut()
{
AXLOGI("CrashTest::logCbkAfterFadeOut() is called");
}

std::string CrashTest::subtitle() const
{
return "Test 1. Should not crash";
return "CrashTest";
}

//------------------------------------------------------------------
//
// Test2
// LogicTest
//
//------------------------------------------------------------------
void LogicTest::onEnter()
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp-tests/Source/ActionManagerTest/ActionManagerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CrashTest : public ActionManagerTest
virtual std::string subtitle() const override;
virtual void onEnter() override;
void removeThis();
void logCbkAfterDelayTime();
void logCbkAfterFadeOut();
};

class LogicTest : public ActionManagerTest
Expand Down