void PerformBasicLayer::toMainLayer(Ref* sender)
{
    auto scene = new (std::nothrow) PerformanceTestScene();
    scene->runThisTest();

    scene->release();
}
Esempio n. 2
0
void BugsTestBaseLayer::backCallback(Object* sender)
{
//    Director::getInstance()->enableRetinaDisplay(false);
    auto scene = new BugsTestScene();
    scene->runThisTest();
    scene->autorelease();
}
void NotificationCenterTest::toExtensionsMainLayer(cocos2d::Ref* sender)
{
    /* for testing removeAllObservers */
    int CC_UNUSED numObserversRemoved = NotificationCenter::getInstance()->removeAllObservers(this);
    CCASSERT(numObserversRemoved >= 3, "All observers were not removed!");

    auto scene = new (std::nothrow) ExtensionsTestScene();
    scene->runThisTest();
    scene->release();
}
Esempio n. 4
0
void AssetsManagerExTestLayer::backCallback(Ref* sender)
{
    if (AssetsManagerExLoaderScene::currentScene > 0)
    {
        AssetsManagerExLoaderScene::currentScene--;
    }
    else AssetsManagerExLoaderScene::currentScene = 2;
    auto scene = new AssetsManagerExLoaderScene();
    scene->runThisTest();
    scene->release();
}
Esempio n. 5
0
void AssetsManagerExTestLayer::nextCallback(Ref* sender)
{
    if (AssetsManagerExLoaderScene::currentScene < 2)
    {
        AssetsManagerExLoaderScene::currentScene++;
    }
    else
    {
        AssetsManagerExLoaderScene::currentScene = 0;
    }
    auto scene = new AssetsManagerExLoaderScene();
    scene->runThisTest();
    scene->release();
}
Esempio n. 6
0
void TestController::menuCallback(Ref * sender)
{
	Director::getInstance()->purgeCachedData();

    // get the userdata, it's the index of the menu item clicked
    auto menuItem = static_cast<MenuItem *>(sender);
    int idx = menuItem->getLocalZOrder() - 10000;

    // create the test scene and run it
    auto scene = g_aTestNames[idx].callback();

    if (scene)
    {
        scene->runThisTest();
        scene->release();
    }
}
void UnitTestLayer::menuCallback(Ref * sender)
{
	Director::getInstance()->purgeCachedData();
    
    // get the userdata, it's the index of the menu item clicked
    auto menuItem = static_cast<MenuItem *>(sender);
    int idx = menuItem->getLocalZOrder() - 10000;
    
    // create the test scene and run it
    auto scene = tests[idx].generator();
    
    if (scene)
    {
        scene->runThisTest();
        Director::getInstance()->pushScene(scene);
    }
}
Esempio n. 8
0
void TestList::tableCellTouched(TableView* table, TableViewCell* cell)
{
    if (_cellTouchEnabled)
    {
        auto index = cell->getIdx();
        if (_testCallbacks[index])
        {
            auto test = _testCallbacks[index]();
            if (test->getChildTestCount() > 0)
            {
                _tableOffset = table->getContentOffset();
                _shouldRestoreTableOffset = true;
                _cellTouchEnabled = false;
                test->setTestParent(this);
                test->runThisTest();
            }
            else
            {
                delete test;
            }
        }
    }
}
Esempio n. 9
0
void TestController::traverseTestList(TestList* testList)
{
    if (testList == _rootTestList)
    {
        _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
    }
    else
    {
        _logIndentation += LOG_INDENTATION;
        _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
    }
    logEx("%s%sBegin traverse TestList:%s", LOG_TAG, _logIndentation.c_str(), testList->getTestName().c_str());

    auto scheduler = _director->getScheduler();
    int testIndex = 0;
    for (auto& callback : testList->_testCallbacks)
    {
        if (_stopAutoTest) break;
        while (_isRunInBackground)
        {
            logEx("_director is paused");
            _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
        }
        if (callback)
        {
            auto test = callback();
            test->setTestParent(testList);
            test->setTestName(testList->_childTestNames[testIndex++]);
            if (test->isTestList())
            {
                scheduler->performFunctionInCocosThread([&](){
                    test->runThisTest();
                });

                traverseTestList((TestList*)test);
            }
            else
            {
                traverseTestSuite((TestSuite*)test);
            }
        }
    }

    if (testList == _rootTestList)
    {
        _stopAutoTest = true;
    }
    else
    {
        if (!_stopAutoTest)
        {
            //Backs up one level and release TestList object.
            scheduler->performFunctionInCocosThread([&](){
                testList->_parentTest->runThisTest();
            });
            _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
            testList->release();
        }
        
        _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
    }
}
Esempio n. 10
0
void TestController::traverseTestSuite(TestSuite* testSuite)
{
    auto scheduler = _director->getScheduler();
    int testIndex = 0;
    float testCaseDuration = 0.0f;
    _logIndentation += LOG_INDENTATION;
    logEx("%s%sBegin traverse TestSuite:%s", LOG_TAG, _logIndentation.c_str(), testSuite->getTestName().c_str());

    _logIndentation += LOG_INDENTATION;
    testSuite->_currTestIndex = -1;

    auto logIndentation = _logIndentation;
    for (auto& callback : testSuite->_testCallbacks)
    {
        auto testName = testSuite->_childTestNames[testIndex++];
        
        Scene* testScene = nullptr;
        TestCase* testCase = nullptr;
        TransitionScene* transitionScene = nullptr;

        if (_stopAutoTest) break;

        while (_isRunInBackground)
        {
            logEx("_director is paused");
            _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
        }
        //Run test case in the cocos[GL] thread.
        scheduler->performFunctionInCocosThread([&, logIndentation, testName](){
            if (_stopAutoTest) return;
            logEx("%s%sRun test:%s.", LOG_TAG, logIndentation.c_str(), testName.c_str());

            auto scene = callback();
            if (_stopAutoTest) return;

            if (scene)
            {
                transitionScene = dynamic_cast<TransitionScene*>(scene);
                if (transitionScene)
                {
                    testCase = (TestCase*)transitionScene->getInScene();
                    testCaseDuration = transitionScene->getDuration() + 0.5f;
                }
                else
                {
                    testCase = (TestCase*)scene;
                    testCaseDuration = testCase->getDuration();
                }
                testSuite->_currTestIndex++;
                testCase->setTestSuite(testSuite);
                testCase->setTestCaseName(testName);
                testCase->setAutoTesting(true);
                _director->replaceScene(scene);

                testScene = scene;
            }
        });

        if (_stopAutoTest) break;

        //Wait for the test case be created.
        float waitTime = 0.0f;
        while (!testScene && !_stopAutoTest)
        {
            _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50));
            if (!_isRunInBackground)
            {
                waitTime += 0.05f;
            }

            if (waitTime > CREATE_TIME_OUT)
            {
                logEx("%sCreate test %s time out", LOG_TAG, testName.c_str());
                _stopAutoTest = true;
                break;
            }
        }

        if (_stopAutoTest) break;

        //Wait for test completed.
        _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(int(1000 * testCaseDuration)));

        if (transitionScene == nullptr)
        {
            waitTime = 0.0f;
            while (!_stopAutoTest && testCase->isAutoTesting())
            {
                _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50));
                if (!_isRunInBackground)
                {
                    waitTime += 0.05f;
                }

                if (waitTime > TEST_TIME_OUT)
                {
                    logEx("%sRun test %s time out", LOG_TAG, testName.c_str());
                    _stopAutoTest = true;
                    break;
                }
            }

            if (!_stopAutoTest)
            {
                //Check the result of test.
                checkTest(testCase);
            }
        }
    }

    if (!_stopAutoTest)
    {
        //Backs up one level and release TestSuite object.
        auto parentTest = testSuite->_parentTest;
        scheduler->performFunctionInCocosThread([parentTest](){
            parentTest->runThisTest();
        });

        _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(1000));
        testSuite->release();
    }

    _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
    _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
}
Esempio n. 11
0
{
    LINE_SPACE = 40,
    kItemTagBasic = 1000,
};

static struct {
	const char *name;
	std::function<void(Object* sender)> callback;
} g_extensionsTests[] = {
	{ "NotificationCenterTest", [](Object* sender) { runNotificationCenterTest(); }
	},
    { "Scale9SpriteTest", [](Object* sender) {
            auto scene = new S9SpriteTestScene();
            if (scene)
            {
                scene->runThisTest();
                scene->release();
            }
        }
	},
	{ "CCControlButtonTest", [](Object *sender){
		ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager();
		auto scene = pManager->currentControlScene();
		Director::getInstance()->replaceScene(scene);
	}},
	{ "CocosBuilderTest", [](Object *sender) {
		auto scene = new CocosBuilderTestScene();
		if (scene)
		{
			scene->runThisTest();
			scene->release();
Esempio n. 12
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);
}
Esempio n. 13
0
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;
}
Esempio n. 14
0
void EditBoxTest::toExtensionsMainLayer(cocos2d::Object *sender)
{
    auto scene = new ExtensionsTestScene();
    scene->runThisTest();
    scene->release();
}