From e64a647563791d19008395121f152a5d9267ae47 Mon Sep 17 00:00:00 2001 From: heliclei Date: Thu, 20 Feb 2014 21:49:13 +0800 Subject: [PATCH] testcpp autotest:support next, back and restart test via console --- tests/test-cpp/Classes/AppDelegate.cpp | 11 ++++++ tests/test-cpp/Classes/AppDelegate.h | 7 +++- tests/test-cpp/Classes/BaseTest.cpp | 8 ++-- tests/test-cpp/Classes/controller.cpp | 52 ++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/tests/test-cpp/Classes/AppDelegate.cpp b/tests/test-cpp/Classes/AppDelegate.cpp index 17f22cad49..40eeea823a 100644 --- a/tests/test-cpp/Classes/AppDelegate.cpp +++ b/tests/test-cpp/Classes/AppDelegate.cpp @@ -35,6 +35,7 @@ USING_NS_CC; using namespace CocosDenshion; AppDelegate::AppDelegate() +:_curTest(nullptr) { } @@ -135,3 +136,13 @@ void AppDelegate::applicationWillEnterForeground() SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); SimpleAudioEngine::getInstance()->resumeAllEffects(); } + +void AppDelegate::setCurrentTest(BaseTest* curTest) +{ + _curTest = curTest; +} + +BaseTest* AppDelegate::getCurrentTest() +{ + return _curTest; +} \ No newline at end of file diff --git a/tests/test-cpp/Classes/AppDelegate.h b/tests/test-cpp/Classes/AppDelegate.h index bd170afca7..4cc79a14eb 100644 --- a/tests/test-cpp/Classes/AppDelegate.h +++ b/tests/test-cpp/Classes/AppDelegate.h @@ -27,7 +27,7 @@ #define _APP_DELEGATE_H_ #include "cocos2d.h" - +#include "BaseTest.h" /** @brief The cocos2d Application. @@ -57,6 +57,11 @@ public: @param the pointer of the application */ virtual void applicationWillEnterForeground(); + + BaseTest* getCurrentTest(); + void setCurrentTest(BaseTest* curTest); +private: + BaseTest* _curTest; }; #endif // _APP_DELEGATE_H_ diff --git a/tests/test-cpp/Classes/BaseTest.cpp b/tests/test-cpp/Classes/BaseTest.cpp index 529a1337ec..32accf7fbd 100644 --- a/tests/test-cpp/Classes/BaseTest.cpp +++ b/tests/test-cpp/Classes/BaseTest.cpp @@ -25,14 +25,15 @@ #include "BaseTest.h" #include "VisibleRect.h" #include "testResource.h" - +#include "AppDelegate.h" USING_NS_CC; void BaseTest::onEnter() { Layer::onEnter(); - + AppDelegate* app = (AppDelegate *)Application::getInstance(); + app->setCurrentTest(this); // add title and subtitle std::string str = title(); const char * pTitle = str.c_str(); @@ -62,11 +63,12 @@ void BaseTest::onEnter() item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); addChild(menu, 9999); - } void BaseTest::onExit() { + AppDelegate* app = (AppDelegate *)Application::getInstance(); + app->setCurrentTest(NULL); Layer::onExit(); } diff --git a/tests/test-cpp/Classes/controller.cpp b/tests/test-cpp/Classes/controller.cpp index 4f8f9bff2c..4b90ce88ca 100644 --- a/tests/test-cpp/Classes/controller.cpp +++ b/tests/test-cpp/Classes/controller.cpp @@ -5,6 +5,8 @@ #include // test inclues +#include "AppDelegate.h" +#include "BaseTest.h" #include "controller.h" #include "testResource.h" #include "tests.h" @@ -260,6 +262,15 @@ void TestController::addConsoleAutoTest() } const char help_main[] = "\tmain, return to main menu\n"; write(fd, help_main, sizeof(help_main)); + + const char help_next[] = "\tnext, run next test\n"; + write(fd, help_next, sizeof(help_next)); + + const char help_back[] = "\tback, run prev test\n"; + write(fd, help_back, sizeof(help_back)); + + const char help_restart[] = "\trestart, restart current test\n"; + write(fd, help_restart, sizeof(help_restart)); return; } if(args == "main") @@ -276,6 +287,47 @@ void TestController::addConsoleAutoTest() } ); return; } + const char msg_notest[] = "autotest: can't detect running test.\n"; + AppDelegate* app = (AppDelegate *)Application::getInstance(); + BaseTest* currentTest = app->getCurrentTest(); + if(args == "next") + { + if(currentTest != nullptr) + { + currentTest->nextCallback(nullptr); + } + else + { + write(fd, msg_notest, sizeof(msg_notest)); + } + return; + } + if(args == "back") + { + if(currentTest != nullptr) + { + currentTest->backCallback(nullptr); + } + else + { + write(fd, msg_notest, sizeof(msg_notest)); + } + return; + } + + if(args == "restart") + { + if(currentTest != nullptr) + { + currentTest->restartCallback(nullptr); + } + else + { + write(fd, msg_notest, sizeof(msg_notest)); + } + return; + } + for(int i = 0; i < g_testCount; i++) { if(args == g_aTestNames[i].test_name)