From e5bd611604e6b6058abe5a54fcee41f756966e68 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Thu, 9 Apr 2015 14:59:34 +0800 Subject: [PATCH] Test automation support:Make test cases didn't need to care about TestSuite when invoking Director::getInstance()->replaceScene. --- tests/cpp-tests/Classes/BaseTest.cpp | 9 +++++++-- tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp | 11 +---------- tests/cpp-tests/Classes/BugsTest/Bug-1159.h | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-914.cpp | 16 +--------------- tests/cpp-tests/Classes/BugsTest/Bug-914.h | 1 - .../CocoStudioComponentsTest/GameOverScene.cpp | 2 -- .../CocoStudioComponentsTest/SceneController.cpp | 4 ---- tests/cpp-tests/Classes/controller.cpp | 1 + tests/cpp-tests/Classes/controller.h | 3 +++ 9 files changed, 14 insertions(+), 35 deletions(-) diff --git a/tests/cpp-tests/Classes/BaseTest.cpp b/tests/cpp-tests/Classes/BaseTest.cpp index 692ca4eb83..0247d70fa0 100644 --- a/tests/cpp-tests/Classes/BaseTest.cpp +++ b/tests/cpp-tests/Classes/BaseTest.cpp @@ -290,14 +290,14 @@ void TestSuite::runThisTest() { if (!_childTestNames.empty()) { + TestController::getInstance()->setCurrTestSuite(this); + _currTestIndex = 0; auto scene = _testCallbacks[0](); auto testCase = getTestCase(scene); testCase->setTestSuite(this); testCase->setTestCaseName(_childTestNames[_currTestIndex]); Director::getInstance()->replaceScene(scene); - - } } @@ -437,6 +437,11 @@ void TestCase::onEnter() _titleLabel->setString(title()); _subtitleLabel->setString(subtitle()); + if (_testSuite == nullptr) + { + setTestSuite(TestController::getInstance()->getCurrTestSuite()); + } + if (_testSuite && _testSuite->getChildTestCount() < 2) { _priorTestItem->setVisible(false); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp index 92c5a3867c..a0c11b3502 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp @@ -11,15 +11,6 @@ USING_NS_CC; -Scene* Bug1159Layer::scene() -{ - auto scene = Scene::create(); - auto layer = Bug1159Layer::create(); - scene->addChild(layer); - - return scene; -} - bool Bug1159Layer::init() { if (BugsTestBase::init()) @@ -59,7 +50,7 @@ bool Bug1159Layer::init() void Bug1159Layer::callBack(Ref* sender) { - Director::getInstance()->replaceScene(TransitionPageTurn::create(1.0f, Bug1159Layer::scene(), false)); + Director::getInstance()->replaceScene(TransitionPageTurn::create(1.0f, Bug1159Layer::create(), false)); } void Bug1159Layer::onExit() diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1159.h b/tests/cpp-tests/Classes/BugsTest/Bug-1159.h index a4f5992e7f..bc8bc0b723 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1159.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1159.h @@ -8,7 +8,7 @@ class Bug1159Layer : public BugsTestBase public: virtual bool init() override; virtual void onExit() override; - static cocos2d::Scene* scene(); + void callBack(cocos2d::Ref* sender); CREATE_FUNC(Bug1159Layer); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp index 3e62a39ea4..f885f1866d 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp @@ -11,20 +11,6 @@ USING_NS_CC; -Scene* Bug914Layer::scene() -{ - // 'scene' is an autorelease object. - auto scene = Scene::create(); - // 'layer' is an autorelease object. - auto layer = Bug914Layer::create(); - - // add layer as a child to scene - scene->addChild(layer); - - // return the scene - return scene; -} - // on "init" you need to initialize your instance bool Bug914Layer::init() { @@ -81,5 +67,5 @@ void Bug914Layer::onTouchesBegan(const std::vector& touches, Event * eve void Bug914Layer::restart(Ref* sender) { - Director::getInstance()->replaceScene(Bug914Layer::scene()); + Director::getInstance()->replaceScene(Bug914Layer::create()); } diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-914.h b/tests/cpp-tests/Classes/BugsTest/Bug-914.h index 544c325023..5c95c20e1f 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-914.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-914.h @@ -6,7 +6,6 @@ class Bug914Layer : public BugsTestBase { public: - static cocos2d::Scene* scene(); virtual bool init() override; void onTouchesMoved(const std::vector& touches, cocos2d::Event* event); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp index 08ac48b6a3..cb7b3d84ba 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp @@ -83,8 +83,6 @@ void GameOverLayer::gameOverDone() { auto director = Director::getInstance(); auto newScene = CocoStudioComponentsTest::create(); - auto gameoverScene = (GameOverScene*)director->getRunningScene(); - newScene->setTestSuite(gameoverScene->getTestSuite()); director->replaceScene(newScene); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp index 744f986f73..65b9f7ed33 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp @@ -83,8 +83,6 @@ void SceneController::spriteMoveFinished(Node* sender) auto director = Director::getInstance(); auto gameOverScene = GameOverScene::create(); gameOverScene->getLayer()->getLabel()->setString("You Lose :["); - auto currScene = (CocoStudioComponentsTest*)director->getRunningScene(); - gameOverScene->setTestSuite(currScene->getTestSuite()); Director::getInstance()->replaceScene(gameOverScene); } @@ -107,8 +105,6 @@ void SceneController::increaseKillCount() auto director = Director::getInstance(); auto gameOverScene = GameOverScene::create(); gameOverScene->getLayer()->getLabel()->setString("You Win!"); - auto currScene = (CocoStudioComponentsTest*)director->getRunningScene(); - gameOverScene->setTestSuite(currScene->getTestSuite()); Director::getInstance()->replaceScene(gameOverScene); } } diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index 4bfb59e0d0..fd0cc7cd27 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -93,6 +93,7 @@ public: TestController::TestController() : _stopAutoTest(true) , _isRunInBackground(false) +, _testSuite(nullptr) { _rootTestList = new (std::nothrow) RootTests; _rootTestList->runThisTest(); diff --git a/tests/cpp-tests/Classes/controller.h b/tests/cpp-tests/Classes/controller.h index 16c09bd03d..5b86ddd659 100644 --- a/tests/cpp-tests/Classes/controller.h +++ b/tests/cpp-tests/Classes/controller.h @@ -59,6 +59,8 @@ public: bool blockTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event); + void setCurrTestSuite(TestSuite* testSuite) { _testSuite = testSuite; } + TestSuite* getCurrTestSuite() { return _testSuite; } private: TestController(); @@ -72,6 +74,7 @@ private: bool _isRunInBackground; TestList* _rootTestList; + TestSuite* _testSuite; std::thread _autoTestThread;