mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6809 from heliclei/autotest-stop
Support autotest stop command
This commit is contained in:
commit
034e2c6f75
|
@ -124,6 +124,7 @@ static void wait(int t)
|
||||||
|
|
||||||
TestController::TestController()
|
TestController::TestController()
|
||||||
: _beginPos(Vec2::ZERO)
|
: _beginPos(Vec2::ZERO)
|
||||||
|
,_exitThread(false)
|
||||||
{
|
{
|
||||||
// add close menu
|
// add close menu
|
||||||
auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, CC_CALLBACK_1(TestController::closeCallback, this) );
|
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)
|
#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()
|
void TestController::addConsoleAutoTest()
|
||||||
{
|
{
|
||||||
auto console = Director::getInstance()->getConsole();
|
auto console = Director::getInstance()->getConsole();
|
||||||
|
@ -262,7 +334,7 @@ void TestController::addConsoleAutoTest()
|
||||||
static struct Console::Command autotest = {
|
static struct Console::Command autotest = {
|
||||||
"autotest",
|
"autotest",
|
||||||
"testcpp autotest command, use -h to list available tests",
|
"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();
|
Scheduler *sched = Director::getInstance()->getScheduler();
|
||||||
if(args == "help" || args == "-h")
|
if(args == "help" || args == "-h")
|
||||||
|
@ -353,64 +425,16 @@ void TestController::addConsoleAutoTest()
|
||||||
|
|
||||||
if(args == "run")
|
if(args == "run")
|
||||||
{
|
{
|
||||||
for (int i = 0; i < g_testCount; i++)
|
_exitThread = false;
|
||||||
{
|
std::thread t = std::thread( &TestController::runAllTests, this, fd);
|
||||||
// create the test scene and run it
|
t.detach();
|
||||||
std::string msg("autotest: running test:");
|
return;
|
||||||
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];
|
if(args == "stop")
|
||||||
sched->performFunctionInCocosThread( [&](){
|
{
|
||||||
auto scene = currentController->callback();
|
_exitThread = true;
|
||||||
if(scene)
|
std::string msg("autotest: autotest stopped!");
|
||||||
{
|
|
||||||
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!");
|
|
||||||
send(fd, msg.c_str(), strlen(msg.c_str()),0);
|
send(fd, msg.c_str(), strlen(msg.c_str()),0);
|
||||||
send(fd, "\n",1,0);
|
send(fd, "\n",1,0);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,10 +21,12 @@ public:
|
||||||
void addConsoleAutoTest();
|
void addConsoleAutoTest();
|
||||||
void autorun();
|
void autorun();
|
||||||
void startAutoRun();
|
void startAutoRun();
|
||||||
|
void runAllTests(int fd);
|
||||||
ssize_t readline(int fd, char* ptr, size_t maxlen);
|
ssize_t readline(int fd, char* ptr, size_t maxlen);
|
||||||
private:
|
private:
|
||||||
Vec2 _beginPos;
|
Vec2 _beginPos;
|
||||||
Menu* _itemMenu;
|
Menu* _itemMenu;
|
||||||
|
bool _exitThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue