int main(int argc, char **argv) { ros::init(argc, argv); BaseTest b; printf("start\n"); BaseController bc; bc.Init(); while (b.ok()) { //bc.setVelocity(vx, vy, vw); //bc.Update(); usleep(1000); } ros::fini(); return 0; }
void TestController::addConsoleAutoTest() { auto console = Director::getInstance()->getConsole(); static struct Console::Command autotest = { "autotest", "testcpp autotest command, use -h to list available tests", [this](int fd, const std::string& args) { Scheduler *sched = Director::getInstance()->getScheduler(); if(args == "help" || args == "-h") { const char msg[] = "usage: autotest ActionsTest\n\tavailable tests: "; send(fd, msg, sizeof(msg),0); send(fd, "\n",1,0); for(int i = 0; i < g_testCount; i++) { send(fd, "\t",1,0); send(fd, g_aTestNames[i].test_name, strlen(g_aTestNames[i].test_name)+1,0); send(fd, "\n",1,0); } const char help_main[] = "\tmain, return to main menu\n"; send(fd, help_main, sizeof(help_main),0); const char help_next[] = "\tnext, run next test\n"; send(fd, help_next, sizeof(help_next),0); const char help_back[] = "\tback, run prev test\n"; send(fd, help_back, sizeof(help_back),0); const char help_restart[] = "\trestart, restart current test\n"; send(fd, help_restart, sizeof(help_restart),0); return; } if(args == "main") { sched->performFunctionInCocosThread( [&]() { auto scene = Scene::create(); auto layer = new TestController(); scene->addChild(layer); layer->release(); Director::getInstance()->replaceScene(scene); cocostudio::ArmatureDataManager::destroyInstance(); } ); 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); sched->performFunctionInCocosThread( [&](){ currentTest->nextCallback(nullptr); } ); } else { send(fd, msg_notest, sizeof(msg_notest),0); } return; } if(args == "back") { if(currentTest != nullptr) { sched->performFunctionInCocosThread( [&](){ currentTest->backCallback(nullptr); } ); } else { send(fd, msg_notest, sizeof(msg_notest),0); } return; } if(args == "restart") { if(currentTest != nullptr) { sched->performFunctionInCocosThread( [&](){ currentTest->restartCallback(nullptr); } ); } else { send(fd, msg_notest, sizeof(msg_notest),0); } return; } if(args == "run") { _exitThread = false; std::thread t = std::thread( &TestController::runAllTests, this, fd); t.detach(); return; } 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; } for(int i = 0; i < g_testCount; i++) { if(args == g_aTestNames[i].test_name) { currentController = &g_aTestNames[i]; std::string msg("autotest: running test:"); msg += args; send(fd, msg.c_str(), strlen(msg.c_str()),0); send(fd, "\n",1,0); sched->performFunctionInCocosThread( [&](){ auto scene = currentController->callback(); if(scene) { scene->runThisTest(); scene->release(); } } ); return; } } //no match found,print warning message std::string msg("autotest: could not find test:"); msg += args; send(fd, msg.c_str(), strlen(msg.c_str()),0); send(fd, "\n",1,0); } }; console->addCommand(autotest); }
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; }