Merge pull request #6809 from heliclei/autotest-stop

Support autotest stop command
This commit is contained in:
minggo 2014-05-27 14:01:38 +08:00
commit 034e2c6f75
2 changed files with 84 additions and 58 deletions

View File

@ -124,6 +124,7 @@ static void wait(int t)
TestController::TestController()
: _beginPos(Vec2::ZERO)
,_exitThread(false)
{
// add close menu
auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, CC_CALLBACK_1(TestController::closeCallback, this) );
@ -255,6 +256,77 @@ void TestController::onMouseScroll(Event *event)
}
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
void TestController::runAllTests(int fd)
{
AppDelegate* app = (AppDelegate *)Application::getInstance();
Scheduler *sched = Director::getInstance()->getScheduler();
for (int i = 0; i < g_testCount; i++)
{
// create the test scene and run it
std::string msg("autotest: running test:");
msg += g_aTestNames[i].test_name;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
currentController = &g_aTestNames[i];
sched->performFunctionInCocosThread( [&](){
auto scene = currentController->callback();
if(scene)
{
scene->runThisTest();
scene->release();
}
} );
wait(1);
BaseTest* firstTest = app->getCurrentTest();
if(firstTest == nullptr)
{
continue;
}
std::string t1("");
t1 += firstTest->subtitle();
send(fd, t1.c_str(), strlen(t1.c_str()),0);
send(fd, "\n",1,0);
wait(2);
while(1)
{
if(_exitThread)
{
return;
}
//currentTest->nextCallback(nullptr);
sched->performFunctionInCocosThread( [&](){
BaseTest *t = app->getCurrentTest();
if(t != nullptr)
{
t->nextCallback(nullptr);
}
} );
wait(1);
BaseTest * curTest = app->getCurrentTest();
if(curTest == nullptr)
{
break;
}
std::string title("");
title += curTest->subtitle();
send(fd, title.c_str(), strlen(title.c_str()),0);
send(fd, "\n",1,0);
wait(2);
if(t1 == title)
{
break;
}
}
}
std::string msg("autotest run successfully!");
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
return;
}
void TestController::addConsoleAutoTest()
{
auto console = Director::getInstance()->getConsole();
@ -262,7 +334,7 @@ void TestController::addConsoleAutoTest()
static struct Console::Command autotest = {
"autotest",
"testcpp autotest command, use -h to list available tests",
[](int fd, const std::string& args)
[this](int fd, const std::string& args)
{
Scheduler *sched = Director::getInstance()->getScheduler();
if(args == "help" || args == "-h")
@ -353,64 +425,16 @@ void TestController::addConsoleAutoTest()
if(args == "run")
{
for (int i = 0; i < g_testCount; i++)
{
// create the test scene and run it
std::string msg("autotest: running test:");
msg += g_aTestNames[i].test_name;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
_exitThread = false;
std::thread t = std::thread( &TestController::runAllTests, this, fd);
t.detach();
return;
}
currentController = &g_aTestNames[i];
sched->performFunctionInCocosThread( [&](){
auto scene = currentController->callback();
if(scene)
{
scene->runThisTest();
scene->release();
}
} );
wait(1);
BaseTest* firstTest = app->getCurrentTest();
if(firstTest == nullptr)
{
continue;
}
std::string t1("");
t1 += firstTest->subtitle();
send(fd, t1.c_str(), strlen(t1.c_str()),0);
send(fd, "\n",1,0);
wait(2);
while(1)
{
//currentTest->nextCallback(nullptr);
sched->performFunctionInCocosThread( [&](){
BaseTest *t = app->getCurrentTest();
if(t != nullptr)
{
t->nextCallback(nullptr);
}
} );
wait(1);
BaseTest * curTest = app->getCurrentTest();
if(curTest == nullptr)
{
break;
}
std::string title("");
title += curTest->subtitle();
send(fd, title.c_str(), strlen(title.c_str()),0);
send(fd, "\n",1,0);
wait(2);
if(t1 == title)
{
break;
}
}
}
std::string msg("autotest run successfully!");
if(args == "stop")
{
_exitThread = true;
std::string msg("autotest: autotest stopped!");
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
return;

View File

@ -21,10 +21,12 @@ public:
void addConsoleAutoTest();
void autorun();
void startAutoRun();
void runAllTests(int fd);
ssize_t readline(int fd, char* ptr, size_t maxlen);
private:
Vec2 _beginPos;
Menu* _itemMenu;
bool _exitThread;
};
#endif