Merge pull request #5424 from heliclei/console-autotest

testcpp autotest:support next, back and restart test via console
This commit is contained in:
James Chen 2014-02-20 22:22:55 +08:00
commit 97a6ac65d3
4 changed files with 74 additions and 4 deletions

View File

@ -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;
}

View File

@ -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_

View File

@ -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();
}

View File

@ -5,6 +5,8 @@
#include <string>
// 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)