2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
#include "controller.h"
|
2013-06-04 13:33:52 +08:00
|
|
|
#include <functional>
|
2014-02-28 23:41:01 +08:00
|
|
|
#include <chrono>
|
2014-02-20 21:49:13 +08:00
|
|
|
#include "BaseTest.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "tests.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-03 11:54:39 +08:00
|
|
|
|
2015-06-24 18:24:16 +08:00
|
|
|
#define TEST_TIME_OUT 50
|
2015-04-03 11:54:39 +08:00
|
|
|
#define CREATE_TIME_OUT 25
|
|
|
|
#define LOG_INDENTATION " "
|
|
|
|
#define LOG_TAG "[TestController]"
|
|
|
|
|
2015-08-06 13:50:15 +08:00
|
|
|
static void initCrashCatch();
|
|
|
|
static void disableCrashCatch();
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
class RootTests : public TestList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RootTests()
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
// addTest("Node: Scene3D", [](){return new Scene3DTests(); });
|
2022-10-10 03:53:24 +08:00
|
|
|
#if defined(AX_PLATFORM_PC) || (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2022-02-25 19:03:09 +08:00
|
|
|
addTest("ImGui", []() { return new ImGuiTests(); });
|
2020-09-08 13:38:16 +08:00
|
|
|
#endif
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Texture2D", []() { return new Texture2DTests(); });
|
|
|
|
addTest("ActionManager", []() { return new ActionManagerTests(); });
|
|
|
|
addTest("Actions - Basic", []() { return new ActionsTests(); });
|
|
|
|
addTest("Actions - Ease", []() { return new ActionsEaseTests(); });
|
|
|
|
addTest("Actions - Progress", []() { return new ActionsProgressTests(); });
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Audio - NewAudioEngine", []() { return new AudioEngineTests(); });
|
2020-12-01 17:15:30 +08:00
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Box2D - Basic", []() { return new Box2DTests(); });
|
2022-07-15 19:17:01 +08:00
|
|
|
#if defined(AX_PLATFORM_PC)
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Box2D - TestBed", []() { return new Box2DTestBedTests(); });
|
2021-07-06 21:02:47 +08:00
|
|
|
#endif
|
2020-12-04 04:33:52 +08:00
|
|
|
addTest("Chipmunk2D - Basic", []() { return new ChipmunkTests(); });
|
2022-07-15 19:17:01 +08:00
|
|
|
#if defined(AX_PLATFORM_PC)
|
2021-06-16 19:34:09 +08:00
|
|
|
addTest("Chipmunk2D - TestBed", []() { return new ChipmunkTestBedTests(); });
|
2021-06-17 14:22:52 +08:00
|
|
|
#endif
|
2018-05-02 15:33:01 +08:00
|
|
|
addTest("Bugs", []() { return new BugsTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Click and Move", []() { return new ClickAndMoveTest(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Configuration", []() { return new ConfigurationTests(); });
|
|
|
|
addTest("Console", []() { return new ConsoleTests(); });
|
|
|
|
addTest("Curl", []() { return new CurlTests(); });
|
|
|
|
addTest("Current Language", []() { return new CurrentLanguageTests(); });
|
2021-07-04 16:40:34 +08:00
|
|
|
addTest("Network Test", []() { return new NetworkTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("EventDispatcher", []() { return new EventDispatcherTests(); });
|
|
|
|
addTest("Effects - Advanced", []() { return new EffectAdvanceTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Effects - Basic", []() { return new EffectTests(); });
|
2019-04-04 16:13:17 +08:00
|
|
|
addTest("Extensions", []() { return new ExtensionsTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("FileUtils", []() { return new FileUtilsTests(); });
|
|
|
|
addTest("Fonts", []() { return new FontTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Interval", []() { return new IntervalTests(); });
|
2022-07-15 19:17:01 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2015-11-08 04:57:05 +08:00
|
|
|
addTest("JNIHelper", []() { return new JNITests(); });
|
|
|
|
#endif
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Material System", []() { return new MaterialSystemTest(); });
|
|
|
|
addTest("Navigation Mesh", []() { return new NavMeshTests(); });
|
|
|
|
addTest("Node: BillBoard Test", []() { return new BillBoardTests(); });
|
|
|
|
addTest("Node: Camera3D Test", []() { return new Camera3DTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Node: Clipping", []() { return new ClippingNodeTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Node: Draw", []() { return new DrawPrimitivesTests(); });
|
|
|
|
addTest("Node: Label - New API", []() { return new NewLabelTests(); });
|
|
|
|
addTest("Node: Layer", []() { return new LayerTests(); });
|
|
|
|
addTest("Node: Light", []() { return new LightTests(); });
|
|
|
|
addTest("Node: Menu", []() { return new MenuTests(); });
|
|
|
|
addTest("Node: MotionStreak", []() { return new MotionStreakTests(); });
|
|
|
|
addTest("Node: Node", []() { return new CocosNodeTests(); });
|
|
|
|
addTest("Node: Parallax", []() { return new ParallaxTests(); });
|
|
|
|
addTest("Node: Particles", []() { return new ParticleTests(); });
|
|
|
|
addTest("Node: Particle3D (PU)", []() { return new Particle3DTests(); });
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_USE_PHYSICS
|
2020-12-20 14:11:13 +08:00
|
|
|
addTest("Node: Physics", []() { return new PhysicsTests(); });
|
2015-09-08 09:54:01 +08:00
|
|
|
#endif
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Node: Physics3D", []() { return new Physics3DTests(); });
|
|
|
|
addTest("Node: RenderTexture", []() { return new RenderTextureTests(); });
|
|
|
|
addTest("Node: Scene", []() { return new SceneTests(); });
|
|
|
|
addTest("Node: Spine", []() { return new SpineTests(); });
|
|
|
|
addTest("Node: Sprite", []() { return new SpriteTests(); });
|
2022-07-05 14:48:46 +08:00
|
|
|
addTest("Node: MeshRenderer", []() { return new MeshRendererTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Node: SpritePolygon", []() { return new SpritePolygonTest(); });
|
|
|
|
addTest("Node: Terrain", []() { return new TerrainTests(); });
|
|
|
|
addTest("Node: FastTileMap", []() { return new FastTileMapTests(); });
|
|
|
|
addTest("Node: Text Input", []() { return new TextInputTests(); });
|
|
|
|
addTest("Node: UI", []() { return new UITests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Mouse", []() { return new MouseTests(); });
|
2017-02-23 17:05:08 +08:00
|
|
|
addTest("MultiTouch", []() { return new MultiTouchTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Renderer", []() { return new NewRendererTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("ReleasePool", []() { return new ReleasePoolTests(); });
|
|
|
|
addTest("Rotate World", []() { return new RotateWorldTests(); });
|
|
|
|
addTest("Scheduler", []() { return new SchedulerTests(); });
|
2019-03-26 13:45:03 +08:00
|
|
|
addTest("Shader - Basic", []() { return new ShaderTests(); });
|
|
|
|
addTest("Shader - Sprite", []() { return new Shader2Tests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("TextureCache", []() { return new TextureCacheTests(); });
|
|
|
|
addTest("TexturePacker Encryption", []() { return new TextureAtlasEncryptionTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Touches", []() { return new TouchesTests(); });
|
|
|
|
addTest("Transitions", []() { return new TransitionsTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Unit Test", []() { return new UnitTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Unzip Test", []() { return new ZipTests(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("URL Open Test", []() { return new OpenURLTests(); });
|
|
|
|
addTest("UserDefault", []() { return new UserDefaultTests(); });
|
2022-07-15 19:17:01 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2015-06-25 17:36:57 +08:00
|
|
|
addTest("Vibrate", []() { return new VibrateTests(); });
|
2016-12-07 11:12:38 +08:00
|
|
|
#endif
|
2015-04-03 11:54:39 +08:00
|
|
|
addTest("Zwoptex", []() { return new ZwoptexTests(); });
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("SpriteFrameCache", []() { return new SpriteFrameCacheTests(); }); // TODO
|
2022-07-15 19:17:01 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC || AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || \
|
|
|
|
AX_TARGET_PLATFORM == AX_PLATFORM_LINUX)
|
2021-12-28 16:06:23 +08:00
|
|
|
addTest("Window Test", []() { return new WindowTests(); }); // TODO wrong effect
|
2016-10-31 14:02:02 +08:00
|
|
|
#endif
|
2015-04-03 11:54:39 +08:00
|
|
|
}
|
2013-06-04 13:33:52 +08:00
|
|
|
};
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
TestController::TestController() : _stopAutoTest(true), _isRunInBackground(false), _testSuite(nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_rootTestList = new RootTests;
|
2015-04-03 11:54:39 +08:00
|
|
|
_rootTestList->runThisTest();
|
|
|
|
_director = Director::getInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
_touchListener = EventListenerTouchOneByOne::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
_touchListener->onTouchBegan = AX_CALLBACK_2(TestController::blockTouchBegan, this);
|
2015-04-03 11:54:39 +08:00
|
|
|
_touchListener->setSwallowTouches(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
_director->getEventDispatcher()->addEventListenerWithFixedPriority(_touchListener, -200);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestController::~TestController()
|
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_director->getEventDispatcher()->removeEventListener(_touchListener);
|
|
|
|
|
|
|
|
_rootTestList->release();
|
|
|
|
_rootTestList = nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::startAutoTest()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
if (!_autoTestThread.joinable())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
_stopAutoTest = false;
|
2015-04-03 11:54:39 +08:00
|
|
|
_logIndentation = "";
|
2015-06-24 18:24:16 +08:00
|
|
|
_autoTestThread = std::thread(&TestController::traverseThreadFunc, this);
|
2015-04-03 11:54:39 +08:00
|
|
|
_autoTestThread.detach();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::stopAutoTest()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_stopAutoTest = true;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
if (_autoTestThread.joinable())
|
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_sleepCondition.notify_all();
|
|
|
|
_autoTestThread.join();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 18:24:16 +08:00
|
|
|
void TestController::traverseThreadFunc()
|
|
|
|
{
|
|
|
|
std::mutex sleepMutex;
|
2021-12-28 16:06:23 +08:00
|
|
|
auto lock = std::unique_lock<std::mutex>(sleepMutex);
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepUniqueLock = &lock;
|
|
|
|
traverseTestList(_rootTestList);
|
|
|
|
_sleepUniqueLock = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::traverseTestList(TestList* testList)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
if (testList == _rootTestList)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
else
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_logIndentation += LOG_INDENTATION;
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%s%sBegin traverse TestList:%s", LOG_TAG, _logIndentation.c_str(), testList->getTestName().c_str());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
auto scheduler = _director->getScheduler();
|
2021-12-28 16:06:23 +08:00
|
|
|
int testIndex = 0;
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&&callback : testList->_testCallbacks)
|
2015-04-03 11:54:39 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2015-04-03 11:54:39 +08:00
|
|
|
while (_isRunInBackground)
|
|
|
|
{
|
|
|
|
logEx("_director is paused");
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
2015-04-03 11:54:39 +08:00
|
|
|
}
|
|
|
|
if (callback)
|
|
|
|
{
|
|
|
|
auto test = callback();
|
|
|
|
test->setTestParent(testList);
|
|
|
|
test->setTestName(testList->_childTestNames[testIndex++]);
|
|
|
|
if (test->isTestList())
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
scheduler->performFunctionInCocosThread([&]() { test->runThisTest(); });
|
2013-10-05 01:07:39 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
traverseTestList((TestList*)test);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
traverseTestSuite((TestSuite*)test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-05 01:07:39 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
if (testList == _rootTestList)
|
2013-10-05 01:07:39 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_stopAutoTest = true;
|
2013-10-05 01:07:39 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
else
|
2013-10-05 01:07:39 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
if (!_stopAutoTest)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// Backs up one level and release TestList object.
|
|
|
|
scheduler->performFunctionInCocosThread([&]() { testList->_parentTest->runThisTest(); });
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
2015-04-03 11:54:39 +08:00
|
|
|
testList->release();
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
2013-10-05 01:07:39 +08:00
|
|
|
}
|
2013-10-31 14:19:36 +08:00
|
|
|
}
|
2014-02-19 16:13:32 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::traverseTestSuite(TestSuite* testSuite)
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto scheduler = _director->getScheduler();
|
|
|
|
int testIndex = 0;
|
2015-04-03 11:54:39 +08:00
|
|
|
float testCaseDuration = 0.0f;
|
|
|
|
_logIndentation += LOG_INDENTATION;
|
|
|
|
logEx("%s%sBegin traverse TestSuite:%s", LOG_TAG, _logIndentation.c_str(), testSuite->getTestName().c_str());
|
2014-05-19 13:46:17 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
_logIndentation += LOG_INDENTATION;
|
2015-08-25 10:28:18 +08:00
|
|
|
testSuite->_currTestIndex = -1;
|
2014-05-19 13:46:17 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
auto logIndentation = _logIndentation;
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&&callback : testSuite->_testCallbacks)
|
2015-04-03 11:54:39 +08:00
|
|
|
{
|
|
|
|
auto testName = testSuite->_childTestNames[testIndex++];
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
Scene* testScene = nullptr;
|
|
|
|
TestCase* testCase = nullptr;
|
2015-04-03 11:54:39 +08:00
|
|
|
TransitionScene* transitionScene = nullptr;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2015-08-25 10:28:18 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
while (_isRunInBackground)
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("_director is paused");
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
2014-05-19 13:46:17 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
// Run test case in the cocos[GL] thread.
|
|
|
|
scheduler->performFunctionInCocosThread([&, logIndentation, testName]() {
|
|
|
|
if (_stopAutoTest)
|
|
|
|
return;
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%s%sRun test:%s.", LOG_TAG, logIndentation.c_str(), testName.c_str());
|
2014-05-19 13:46:17 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
auto scene = callback();
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
return;
|
2015-04-03 11:54:39 +08:00
|
|
|
|
|
|
|
if (scene)
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
transitionScene = dynamic_cast<TransitionScene*>(scene);
|
|
|
|
if (transitionScene)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
testCase = (TestCase*)transitionScene->getInScene();
|
2015-04-03 11:54:39 +08:00
|
|
|
testCaseDuration = transitionScene->getDuration() + 0.5f;
|
|
|
|
}
|
|
|
|
else
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
testCase = (TestCase*)scene;
|
2015-04-03 11:54:39 +08:00
|
|
|
testCaseDuration = testCase->getDuration();
|
2014-05-19 13:46:17 +08:00
|
|
|
}
|
2015-08-25 10:28:18 +08:00
|
|
|
testSuite->_currTestIndex++;
|
2015-04-03 11:54:39 +08:00
|
|
|
testCase->setTestSuite(testSuite);
|
|
|
|
testCase->setTestCaseName(testName);
|
|
|
|
_director->replaceScene(scene);
|
|
|
|
|
|
|
|
testScene = scene;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2015-04-03 11:54:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// Wait for the test case be created.
|
2015-04-03 11:54:39 +08:00
|
|
|
float waitTime = 0.0f;
|
|
|
|
while (!testScene && !_stopAutoTest)
|
|
|
|
{
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50));
|
2015-04-03 11:54:39 +08:00
|
|
|
if (!_isRunInBackground)
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
waitTime += 0.05f;
|
2014-05-19 13:46:17 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
if (waitTime > CREATE_TIME_OUT)
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%sCreate test %s time out", LOG_TAG, testName.c_str());
|
|
|
|
_stopAutoTest = true;
|
2014-05-19 13:46:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2015-04-03 11:54:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// Wait for test completed.
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(int(1000 * testCaseDuration)));
|
2015-04-03 11:54:39 +08:00
|
|
|
|
|
|
|
if (transitionScene == nullptr)
|
2014-02-19 16:13:32 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
waitTime = 0.0f;
|
|
|
|
while (!_stopAutoTest && testCase->getRunTime() < testCaseDuration)
|
2014-02-19 17:55:32 +08:00
|
|
|
{
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50));
|
2015-04-03 11:54:39 +08:00
|
|
|
if (!_isRunInBackground)
|
2014-02-19 17:55:32 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
waitTime += 0.05f;
|
2014-02-19 17:55:32 +08:00
|
|
|
}
|
2014-02-20 21:49:13 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
if (waitTime > TEST_TIME_OUT)
|
2014-02-20 21:49:13 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%sRun test %s time out", LOG_TAG, testName.c_str());
|
|
|
|
_stopAutoTest = true;
|
|
|
|
break;
|
2014-02-20 21:49:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
if (!_stopAutoTest)
|
2014-02-28 23:02:22 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// Check the result of test.
|
2015-04-03 11:54:39 +08:00
|
|
|
checkTest(testCase);
|
2014-05-19 13:46:17 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_stopAutoTest)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// Backs up one level and release TestSuite object.
|
2015-04-03 11:54:39 +08:00
|
|
|
auto parentTest = testSuite->_parentTest;
|
2021-12-28 16:06:23 +08:00
|
|
|
scheduler->performFunctionInCocosThread([&]() { parentTest->runThisTest(); });
|
2015-04-03 11:54:39 +08:00
|
|
|
|
2015-06-24 18:24:16 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(1000));
|
2015-04-03 11:54:39 +08:00
|
|
|
testSuite->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
|
|
|
}
|
2014-02-28 23:02:22 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
bool TestController::checkTest(TestCase* testCase)
|
|
|
|
{
|
|
|
|
if (testCase)
|
|
|
|
{
|
|
|
|
switch (testCase->getTestType())
|
|
|
|
{
|
|
|
|
case TestCase::Type::UNIT:
|
|
|
|
{
|
|
|
|
if (testCase && testCase->getExpectedOutput() != testCase->getActualOutput())
|
2014-05-19 13:46:17 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%s %s test fail", LOG_TAG, testCase->getTestCaseName().c_str());
|
2014-02-28 23:02:22 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
else
|
2014-02-19 16:13:32 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
logEx("%s %s test pass", LOG_TAG, testCase->getTestCaseName().c_str());
|
2014-02-19 16:13:32 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
break;
|
2014-02-19 16:13:32 +08:00
|
|
|
}
|
2015-04-03 11:54:39 +08:00
|
|
|
case TestCase::Type::ROBUSTNESS:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TestCase::Type::MANUAL:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-02-20 17:58:21 +08:00
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::handleCrash()
|
2014-05-12 21:47:55 +08:00
|
|
|
{
|
2015-08-06 13:50:15 +08:00
|
|
|
disableCrashCatch();
|
|
|
|
|
2015-04-07 16:14:27 +08:00
|
|
|
logEx("%sCatch an crash event", LOG_TAG);
|
|
|
|
|
|
|
|
if (!_stopAutoTest)
|
|
|
|
{
|
|
|
|
stopAutoTest();
|
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::onEnterBackground()
|
2014-05-13 17:20:12 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_isRunInBackground = true;
|
2014-05-13 17:20:12 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::onEnterForeground()
|
2014-05-12 21:47:55 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
_isRunInBackground = false;
|
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void TestController::logEx(const char* format, ...)
|
2015-04-03 11:54:39 +08:00
|
|
|
{
|
|
|
|
char buff[1024];
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vsnprintf(buff, 1020, format, args);
|
|
|
|
strcat(buff, "\n");
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2022-10-01 16:24:52 +08:00
|
|
|
__android_log_print(ANDROID_LOG_DEBUG, "axmol debug info", "%s", buff);
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#elif AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
|
2021-12-28 16:06:23 +08:00
|
|
|
WCHAR wszBuf[1024] = {0};
|
2015-04-03 11:54:39 +08:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, buff, -1, wszBuf, sizeof(wszBuf));
|
|
|
|
OutputDebugStringW(wszBuf);
|
2014-05-12 21:47:55 +08:00
|
|
|
|
|
|
|
#else
|
2015-04-03 11:54:39 +08:00
|
|
|
// Linux, Mac, iOS, etc
|
|
|
|
fprintf(stdout, "%s", buff);
|
|
|
|
fflush(stdout);
|
2014-05-12 21:47:55 +08:00
|
|
|
#endif
|
2015-04-03 11:54:39 +08:00
|
|
|
va_end(args);
|
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
static TestController* s_testController = nullptr;
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
TestController* TestController::getInstance()
|
|
|
|
{
|
|
|
|
if (s_testController == nullptr)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
s_testController = new TestController;
|
2015-04-07 16:14:27 +08:00
|
|
|
|
|
|
|
initCrashCatch();
|
2015-04-03 11:54:39 +08:00
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
return s_testController;
|
|
|
|
}
|
2014-05-12 21:47:55 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
void TestController::destroyInstance()
|
|
|
|
{
|
|
|
|
if (s_testController)
|
2014-05-13 14:16:06 +08:00
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
s_testController->stopAutoTest();
|
|
|
|
delete s_testController;
|
|
|
|
s_testController = nullptr;
|
2014-05-13 14:16:06 +08:00
|
|
|
}
|
2015-08-06 13:50:15 +08:00
|
|
|
|
|
|
|
disableCrashCatch();
|
2014-05-12 21:47:55 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
bool TestController::blockTouchBegan(Touch* touch, Event* event)
|
|
|
|
{
|
|
|
|
return !_stopAutoTest;
|
|
|
|
}
|
2015-04-07 16:14:27 +08:00
|
|
|
|
|
|
|
//==================================================================================================
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
|
2021-12-28 16:06:23 +08:00
|
|
|
# include <windows.h>
|
2015-04-07 16:14:27 +08:00
|
|
|
|
|
|
|
static long __stdcall windowExceptionFilter(_EXCEPTION_POINTERS* excp)
|
|
|
|
{
|
|
|
|
if (s_testController)
|
|
|
|
{
|
|
|
|
s_testController->handleCrash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initCrashCatch()
|
|
|
|
{
|
|
|
|
SetUnhandledExceptionFilter(windowExceptionFilter);
|
|
|
|
}
|
2015-08-06 13:50:15 +08:00
|
|
|
static void disableCrashCatch()
|
|
|
|
{
|
|
|
|
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
|
|
|
|
}
|
2015-04-07 16:14:27 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#elif AX_TARGET_PLATFORM == AX_PLATFORM_MAC || AX_TARGET_PLATFORM == AX_PLATFORM_IOS || \
|
|
|
|
AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2015-04-07 16:14:27 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
# if AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2015-04-07 16:14:27 +08:00
|
|
|
static int s_fatal_signals[] = {
|
2021-12-28 16:06:23 +08:00
|
|
|
SIGILL, SIGABRT, SIGBUS, SIGFPE, SIGSEGV, SIGSTKFLT, SIGPIPE,
|
2015-04-07 16:14:27 +08:00
|
|
|
};
|
2021-12-28 16:06:23 +08:00
|
|
|
# else
|
2015-04-07 16:14:27 +08:00
|
|
|
static int s_fatal_signals[] = {
|
2021-12-28 16:06:23 +08:00
|
|
|
SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP, SIGTERM, SIGKILL,
|
2015-04-07 16:14:27 +08:00
|
|
|
};
|
2021-12-28 16:06:23 +08:00
|
|
|
# endif
|
2015-04-07 16:14:27 +08:00
|
|
|
|
|
|
|
static void signalHandler(int sig)
|
|
|
|
{
|
|
|
|
if (s_testController)
|
|
|
|
{
|
|
|
|
s_testController->handleCrash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initCrashCatch()
|
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&&sig : s_fatal_signals)
|
2015-08-06 13:50:15 +08:00
|
|
|
{
|
2015-04-07 16:14:27 +08:00
|
|
|
signal(sig, signalHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:50:15 +08:00
|
|
|
static void disableCrashCatch()
|
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&&sig : s_fatal_signals)
|
2015-08-06 13:50:15 +08:00
|
|
|
{
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 16:14:27 +08:00
|
|
|
#else
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
static void initCrashCatch() {}
|
2015-04-07 16:14:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
static void disableCrashCatch() {}
|
2015-04-07 16:14:27 +08:00
|
|
|
|
|
|
|
#endif
|