From 0d51c1374395f5ae0a50551a20748946772c794e Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Fri, 3 Apr 2015 14:31:03 +0800 Subject: [PATCH] Make all test cases work fine with new test framework. --- .../ActionManagerTest/ActionManagerTest.cpp | 105 +- .../ActionManagerTest/ActionManagerTest.h | 29 +- .../ActionsEaseTest/ActionsEaseTest.cpp | 138 +-- .../Classes/ActionsEaseTest/ActionsEaseTest.h | 62 +- .../ActionsProgressTest.cpp | 101 +- .../ActionsProgressTest/ActionsProgressTest.h | 29 +- .../Classes/ActionsTest/ActionsTest.cpp | 182 ++-- .../Classes/ActionsTest/ActionsTest.h | 20 +- .../Classes/AllocatorTest/AllocatorTest.cpp | 298 +++--- .../Classes/AllocatorTest/AllocatorTest.h | 78 +- .../Classes/BillBoardTest/BillBoardTest.cpp | 111 +- .../Classes/BillBoardTest/BillBoardTest.h | 20 +- .../cpp-tests/Classes/Box2DTest/Box2dTest.cpp | 43 +- tests/cpp-tests/Classes/Box2DTest/Box2dTest.h | 18 +- .../Classes/Box2DTestBed/Box2dView.cpp | 129 +-- .../Classes/Box2DTestBed/Box2dView.h | 27 +- tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-1159.h | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-1174.h | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-350.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-350.h | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-422.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-422.h | 4 +- .../Classes/BugsTest/Bug-458/Bug-458.cpp | 2 +- .../Classes/BugsTest/Bug-458/Bug-458.h | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-624.cpp | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-624.h | 8 +- tests/cpp-tests/Classes/BugsTest/Bug-886.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-886.h | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-899.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-899.h | 4 +- tests/cpp-tests/Classes/BugsTest/Bug-914.cpp | 2 +- tests/cpp-tests/Classes/BugsTest/Bug-914.h | 6 +- .../cpp-tests/Classes/BugsTest/Bug-Child.cpp | 16 +- tests/cpp-tests/Classes/BugsTest/Bug-Child.h | 7 +- tests/cpp-tests/Classes/BugsTest/BugsTest.cpp | 145 +-- tests/cpp-tests/Classes/BugsTest/BugsTest.h | 26 +- .../Classes/Camera3DTest/Camera3DTest.cpp | 108 +- .../Classes/Camera3DTest/Camera3DTest.h | 22 +- .../Classes/ChipmunkTest/ChipmunkTest.cpp | 47 +- .../Classes/ChipmunkTest/ChipmunkTest.h | 20 +- .../ClickAndMoveTest/ClickAndMoveTest.cpp | 18 +- .../ClickAndMoveTest/ClickAndMoveTest.h | 14 +- .../ClippingNodeTest/ClippingNodeTest.cpp | 106 +- .../ClippingNodeTest/ClippingNodeTest.h | 27 +- .../CocosDenshionTest/CocosDenshionTest.cpp | 13 +- .../CocosDenshionTest/CocosDenshionTest.h | 14 +- .../CocosStudio3DTest/CocosStudio3DTest.cpp | 119 +-- .../CocosStudio3DTest/CocosStudio3DTest.h | 23 +- .../ConfigurationTest/ConfigurationTest.cpp | 88 +- .../ConfigurationTest/ConfigurationTest.h | 20 +- .../Classes/ConsoleTest/ConsoleTest.cpp | 75 +- .../Classes/ConsoleTest/ConsoleTest.h | 17 +- tests/cpp-tests/Classes/CurlTest/CurlTest.cpp | 14 +- tests/cpp-tests/Classes/CurlTest/CurlTest.h | 16 +- .../CurrentLanguageTest.cpp | 13 +- .../CurrentLanguageTest/CurrentLanguageTest.h | 14 +- .../DataVisitorTest/DataVisitorTest.cpp | 15 +- .../Classes/DataVisitorTest/DataVisitorTest.h | 14 +- .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 109 +- .../DrawPrimitivesTest/DrawPrimitivesTest.h | 25 +- .../EffectsAdvancedTest.cpp | 133 +-- .../EffectsAdvancedTest/EffectsAdvancedTest.h | 35 +- .../Classes/EffectsTest/EffectsTest.cpp | 91 +- .../Classes/EffectsTest/EffectsTest.h | 39 +- .../AssetsManagerExTest.cpp | 277 +++-- .../AssetsManagerExTest/AssetsManagerExTest.h | 45 +- .../ActionTimelineTestScene.cpp | 238 +---- .../ActionTimelineTestScene.h | 74 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 389 ++----- .../CocoStudioArmatureTest/ArmatureScene.h | 172 +-- .../ComponentsTestScene.cpp | 70 +- .../ComponentsTestScene.h | 19 +- .../GameOverScene.cpp | 21 +- .../CocoStudioComponentsTest/GameOverScene.h | 11 +- .../SceneController.cpp | 8 + .../SceneController.h | 6 +- .../CocoStudioSceneTest/SceneEditorTest.cpp | 290 ++---- .../CocoStudioSceneTest/SceneEditorTest.h | 100 +- .../CocosBuilderTest/CocosBuilderTest.cpp | 67 +- .../CocosBuilderTest/CocosBuilderTest.h | 12 +- .../CCControlButtonTest/CCControlButtonTest.h | 19 +- .../CCControlColourPickerTest.cpp | 25 - .../CCControlColourPickerTest.h | 29 +- .../CCControlPotentiometerTest.h | 4 +- .../ControlExtensionTest/CCControlScene.cpp | 60 +- .../ControlExtensionTest/CCControlScene.h | 38 +- .../CCControlSceneManager.cpp | 111 +- .../CCControlSceneManager.h | 22 +- .../CCControlSliderTest.cpp | 7 +- .../CCControlSliderTest/CCControlSliderTest.h | 6 +- .../CCControlStepperTest.h | 5 +- .../CCControlSwitchTest/CCControlSwitchTest.h | 4 +- .../Classes/ExtensionsTest/ExtensionsTest.cpp | 184 +--- .../Classes/ExtensionsTest/ExtensionsTest.h | 25 +- .../NetworkTest/HttpClientTest.cpp | 33 +- .../NetworkTest/HttpClientTest.h | 12 +- .../NetworkTest/SocketIOTest.cpp | 109 +- .../ExtensionsTest/NetworkTest/SocketIOTest.h | 18 +- .../NetworkTest/WebSocketTest.cpp | 121 +-- .../NetworkTest/WebSocketTest.h | 20 +- .../NotificationCenterTest.cpp | 26 +- .../NotificationCenterTest.h | 13 +- .../TableViewTest/TableViewTestScene.cpp | 33 +- .../TableViewTest/TableViewTestScene.h | 11 +- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 99 +- .../Classes/FileUtilsTest/FileUtilsTest.h | 15 +- tests/cpp-tests/Classes/FontTest/FontTest.cpp | 84 +- tests/cpp-tests/Classes/FontTest/FontTest.h | 34 +- .../cpp-tests/Classes/InputTest/MouseTest.cpp | 101 +- tests/cpp-tests/Classes/InputTest/MouseTest.h | 21 +- .../Classes/IntervalTest/IntervalTest.cpp | 20 +- .../Classes/IntervalTest/IntervalTest.h | 17 +- .../cpp-tests/Classes/LabelTest/LabelTest.cpp | 168 +-- tests/cpp-tests/Classes/LabelTest/LabelTest.h | 33 +- .../Classes/LabelTest/LabelTestNew.cpp | 184 +--- .../Classes/LabelTest/LabelTestNew.h | 33 +- .../cpp-tests/Classes/LayerTest/LayerTest.cpp | 131 +-- tests/cpp-tests/Classes/LayerTest/LayerTest.h | 30 +- .../cpp-tests/Classes/LightTest/LightTest.cpp | 88 +- tests/cpp-tests/Classes/LightTest/LightTest.h | 20 +- tests/cpp-tests/Classes/MenuTest/MenuTest.cpp | 45 +- tests/cpp-tests/Classes/MenuTest/MenuTest.h | 33 +- .../MotionStreakTest/MotionStreakTest.cpp | 76 +- .../MotionStreakTest/MotionStreakTest.h | 19 +- .../Classes/MutiTouchTest/MutiTouchTest.cpp | 31 +- .../Classes/MutiTouchTest/MutiTouchTest.h | 18 +- .../NewAudioEngineTest/NewAudioEngineTest.cpp | 92 +- .../NewAudioEngineTest/NewAudioEngineTest.h | 15 +- .../NewEventDispatcherTest.cpp | 130 +-- .../NewEventDispatcherTest.h | 14 +- .../NewRendererTest/NewRendererTest.cpp | 105 +- .../Classes/NewRendererTest/NewRendererTest.h | 33 +- tests/cpp-tests/Classes/NodeTest/NodeTest.cpp | 179 +--- tests/cpp-tests/Classes/NodeTest/NodeTest.h | 48 +- .../Classes/OpenURLTest/OpenURLTest.cpp | 14 +- .../Classes/OpenURLTest/OpenURLTest.h | 13 +- .../Classes/ParallaxTest/ParallaxTest.cpp | 115 +- .../Classes/ParallaxTest/ParallaxTest.h | 27 +- .../Classes/Particle3DTest/Particle3DTest.cpp | 108 +- .../Classes/Particle3DTest/Particle3DTest.h | 24 +- .../Classes/ParticleTest/ParticleTest.cpp | 184 +--- .../Classes/ParticleTest/ParticleTest.h | 78 +- .../Classes/PhysicsTest/PhysicsTest.cpp | 248 ++--- .../Classes/PhysicsTest/PhysicsTest.h | 56 +- .../ReleasePoolTest/ReleasePoolTest.cpp | 13 +- .../Classes/ReleasePoolTest/ReleasePoolTest.h | 10 +- .../RenderTextureTest/RenderTextureTest.cpp | 98 +- .../RenderTextureTest/RenderTextureTest.h | 27 +- .../RotateWorldTest/RotateWorldTest.cpp | 19 +- .../Classes/RotateWorldTest/RotateWorldTest.h | 10 +- .../cpp-tests/Classes/SceneTest/SceneTest.cpp | 17 +- tests/cpp-tests/Classes/SceneTest/SceneTest.h | 18 +- .../Classes/SchedulerTest/SchedulerTest.cpp | 139 +-- .../Classes/SchedulerTest/SchedulerTest.h | 23 +- .../Classes/ShaderTest/ShaderTest.cpp | 119 +-- .../cpp-tests/Classes/ShaderTest/ShaderTest.h | 32 +- .../Classes/ShaderTest/ShaderTest2.cpp | 79 +- .../Classes/ShaderTest/ShaderTest2.h | 22 +- .../cpp-tests/Classes/SpineTest/SpineTest.cpp | 109 +- tests/cpp-tests/Classes/SpineTest/SpineTest.h | 28 +- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 144 +-- .../Classes/Sprite3DTest/Sprite3DTest.h | 51 +- .../Classes/SpriteTest/SpriteTest.cpp | 241 ++--- .../cpp-tests/Classes/SpriteTest/SpriteTest.h | 30 +- .../Classes/TextInputTest/TextInputTest.cpp | 121 +-- .../Classes/TextInputTest/TextInputTest.h | 33 +- .../Classes/Texture2dTest/Texture2dTest.cpp | 214 ++-- .../Classes/Texture2dTest/Texture2dTest.h | 19 +- .../TextureCacheTest/TextureCacheTest.cpp | 16 +- .../TextureCacheTest/TextureCacheTest.h | 16 +- .../TextureAtlasEncryptionTest.cpp | 23 +- .../TextureAtlasEncryptionTest.h | 15 +- .../Classes/TileMapTest/TileMapTest.cpp | 158 +-- .../Classes/TileMapTest/TileMapTest.h | 101 +- .../Classes/TileMapTest/TileMapTest2.cpp | 175 +--- .../Classes/TileMapTest/TileMapTest2.h | 100 +- .../Classes/TouchesTest/TouchesTest.cpp | 23 +- .../Classes/TouchesTest/TouchesTest.h | 14 +- .../TransitionsTest/TransitionsTest.cpp | 217 +--- .../Classes/TransitionsTest/TransitionsTest.h | 24 +- .../CocoStudioGUITest/CocoStudioGUITest.cpp | 150 --- .../CocoStudioGUITest/CocoStudioGUITest.h | 23 - .../CocoStudioGUITest/CocosGUIScene.cpp | 415 +------- .../UITest/CocoStudioGUITest/CocosGUIScene.h | 32 +- .../CocostudioParserTest.cpp | 132 +-- .../CocoStudioGUITest/CocostudioParserTest.h | 30 +- .../CocostudioParserJsonTest.cpp | 46 +- .../CocostudioParserJsonTest.h | 14 +- .../CocoStudioGUITest/CustomGUIScene.cpp | 157 +-- .../UITest/CocoStudioGUITest/CustomGUIScene.h | 33 +- .../CustomImageTest/CustomImageTest.cpp | 66 +- .../CustomImageTest/CustomImageTest.h | 17 +- .../CustomParticleWidgetTest.cpp | 83 +- .../CustomParticleWidgetTest.h | 23 +- .../CustomWidgetCallbackBindTest.cpp | 51 +- .../CustomWidgetCallbackBindTest.h | 15 +- .../CocoStudioGUITest/GUIEditorTest.cpp | 387 +------ .../UITest/CocoStudioGUITest/GUIEditorTest.h | 26 +- .../UIButtonTest/UIButtonTest.cpp | 20 +- .../UIButtonTest/UIButtonTest.h | 86 +- .../UIButtonTest/UIButtonTest_Editor.cpp | 84 +- .../UIButtonTest/UIButtonTest_Editor.h | 12 +- .../UICheckBoxTest/UICheckBoxTest.cpp | 7 +- .../UICheckBoxTest/UICheckBoxTest.h | 14 +- .../UICheckBoxTest/UICheckBoxTest_Editor.cpp | 83 +- .../UICheckBoxTest/UICheckBoxTest_Editor.h | 12 +- .../CocoStudioGUITest/UIEditBoxTest.cpp | 9 +- .../UITest/CocoStudioGUITest/UIEditBoxTest.h | 10 +- .../UIFocusTest/UIFocusTest.cpp | 10 + .../UIFocusTest/UIFocusTest.h | 47 +- .../UIImageViewTest/UIImageViewTest.cpp | 10 +- .../UIImageViewTest/UIImageViewTest.h | 37 +- .../UIImageViewTest_Editor.cpp | 87 +- .../UIImageViewTest/UIImageViewTest_Editor.h | 9 +- .../UILayoutTest/UILayoutTest.cpp | 20 +- .../UILayoutTest/UILayoutTest.h | 70 +- .../UILayoutTest/UILayoutTest_Editor.cpp | 984 +----------------- .../UILayoutTest/UILayoutTest_Editor.h | 93 +- .../UIListViewTest/UIListViewTest.cpp | 8 +- .../UIListViewTest/UIListViewTest.h | 16 +- .../UIListViewTest/UIListViewTest_Editor.cpp | 211 +--- .../UIListViewTest/UIListViewTest_Editor.h | 18 +- .../UILoadingBarTest/UILoadingBarTest.cpp | 120 +-- .../UILoadingBarTest/UILoadingBarTest.h | 48 +- .../UILoadingBarTest_Editor.cpp | 104 +- .../UILoadingBarTest_Editor.h | 12 +- .../UIPageViewTest/UIPageViewTest.cpp | 11 +- .../UIPageViewTest/UIPageViewTest.h | 32 +- .../UIPageViewTest/UIPageViewTest_Editor.cpp | 116 +-- .../UIPageViewTest/UIPageViewTest_Editor.h | 10 +- .../UIRichTextTest/UIRichTextTest.cpp | 7 +- .../UIRichTextTest/UIRichTextTest.h | 10 +- .../CocoStudioGUITest/UIScale9SpriteTest.cpp | 26 + .../CocoStudioGUITest/UIScale9SpriteTest.h | 105 +- .../UITest/CocoStudioGUITest/UIScene.cpp | 79 +- .../UITest/CocoStudioGUITest/UIScene.h | 42 +- .../CocoStudioGUITest/UISceneManager.cpp | 471 --------- .../UITest/CocoStudioGUITest/UISceneManager.h | 146 --- .../UISceneManager_Editor.cpp | 194 ---- .../CocoStudioGUITest/UISceneManager_Editor.h | 65 -- .../CocoStudioGUITest/UIScene_Editor.cpp | 105 +- .../UITest/CocoStudioGUITest/UIScene_Editor.h | 38 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 13 +- .../UIScrollViewTest/UIScrollViewTest.h | 44 +- .../UIScrollViewTest_Editor.cpp | 374 +------ .../UIScrollViewTest_Editor.h | 38 +- .../UISliderTest/UISliderTest.cpp | 10 +- .../UISliderTest/UISliderTest.h | 29 +- .../UISliderTest/UISliderTest_Editor.cpp | 87 +- .../UISliderTest/UISliderTest_Editor.h | 11 +- .../UITextAtlasTest/UITextAtlasTest.cpp | 7 +- .../UITextAtlasTest/UITextAtlasTest.h | 11 +- .../UITextAtlasTest_Editor.cpp | 84 +- .../UITextAtlasTest/UITextAtlasTest_Editor.h | 10 +- .../UITextBMFontTest/UITextBMFontTest.cpp | 7 +- .../UITextBMFontTest/UITextBMFontTest.h | 9 +- .../UITextBMFontTest_Editor.cpp | 87 +- .../UITextBMFontTest_Editor.h | 8 +- .../UITextFieldTest/UITextFieldTest.cpp | 12 +- .../UITextFieldTest/UITextFieldTest.h | 38 +- .../UITextFieldTest_Editor.cpp | 85 +- .../UITextFieldTest/UITextFieldTest_Editor.h | 11 +- .../UITextTest/UITextTest.cpp | 10 +- .../CocoStudioGUITest/UITextTest/UITextTest.h | 36 +- .../UITextTest/UITextTest_Editor.cpp | 90 +- .../UITextTest/UITextTest_Editor.h | 8 +- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 5 + .../UIVideoPlayerTest/UIVideoPlayerTest.h | 4 +- .../UIWebViewTest/UIWebViewTest.cpp | 11 +- .../UIWebViewTest/UIWebViewTest.h | 6 +- .../UIWidgetAddNodeTest.cpp | 6 +- .../UIWidgetAddNodeTest/UIWidgetAddNodeTest.h | 10 +- .../UIWidgetAddNodeTest_Editor.cpp | 90 +- .../UIWidgetAddNodeTest_Editor.h | 11 +- tests/cpp-tests/Classes/UITest/UITest.cpp | 19 +- tests/cpp-tests/Classes/UITest/UITest.h | 10 +- tests/cpp-tests/Classes/UnitTest/UnitTest.cpp | 90 +- tests/cpp-tests/Classes/UnitTest/UnitTest.h | 19 +- .../UserDefaultTest/UserDefaultTest.cpp | 14 +- .../Classes/UserDefaultTest/UserDefaultTest.h | 13 +- .../Classes/ZwoptexTest/ZwoptexTest.cpp | 98 +- .../Classes/ZwoptexTest/ZwoptexTest.h | 26 +- 284 files changed, 3824 insertions(+), 14035 deletions(-) diff --git a/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.cpp b/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.cpp index cc681ab0f5..0143f503d6 100644 --- a/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.cpp +++ b/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.cpp @@ -9,61 +9,16 @@ enum kTagSequence, }; -Layer* nextActionManagerAction(); -Layer* backActionManagerAction(); -Layer* restartActionManagerAction(); - -static int sceneIdx = -1; - -#define MAX_LAYER 6 - -Layer* createActionManagerLayer(int nIndex) +ActionManagerTests::ActionManagerTests() { - switch(nIndex) - { - case 0: return new CrashTest(); - case 1: return new LogicTest(); - case 2: return new PauseTest(); - case 3: return new StopActionTest(); - case 4: return new StopAllActionsTest(); - case 5: return new ResumeTest(); - } - - return nullptr; + ADD_TEST_CASE(CrashTest); + ADD_TEST_CASE(LogicTest); + ADD_TEST_CASE(PauseTest); + ADD_TEST_CASE(StopActionTest); + ADD_TEST_CASE(StopAllActionsTest); + ADD_TEST_CASE(ResumeTest); } -Layer* nextActionManagerAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createActionManagerLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backActionManagerAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createActionManagerLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartActionManagerAction() -{ - auto layer = createActionManagerLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - //------------------------------------------------------------------ // // ActionManagerTest @@ -86,30 +41,6 @@ std::string ActionManagerTest::subtitle() const { return "No title"; } -void ActionManagerTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionManagerTestScene(); - s->addChild(restartActionManagerAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionManagerTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionManagerTestScene(); - s->addChild( nextActionManagerAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionManagerTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionManagerTestScene(); - s->addChild( backActionManagerAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} //------------------------------------------------------------------ // @@ -123,7 +54,7 @@ void CrashTest::onEnter() auto child = Sprite::create(s_pathGrossini); child->setPosition( VisibleRect::center() ); - addChild(child, 1); + addChild(child, 1, kTagGrossini); //Sum of all action's duration is 1.5 second. child->runAction(RotateBy::create(1.5f, 90)); @@ -134,7 +65,7 @@ void CrashTest::onEnter() ); //After 1.5 second, self will be removed. - runAction( Sequence::create( + child->runAction(Sequence::create( DelayTime::create(1.4f), CallFunc::create( CC_CALLBACK_0(CrashTest::removeThis,this)), nullptr) @@ -143,9 +74,10 @@ void CrashTest::onEnter() void CrashTest::removeThis() { - _parent->removeChild(this, true); + auto child = getChildByTag(kTagGrossini); + child->removeChild(child, true); - nextCallback(this); + getTestSuite()->enterNextTest(); } std::string CrashTest::subtitle() const @@ -357,16 +289,3 @@ void ResumeTest::resumeGrossini(float time) auto director = Director::getInstance(); director->getActionManager()->resumeTarget(pGrossini); } - -//------------------------------------------------------------------ -// -// ActionManagerTestScene -// -//------------------------------------------------------------------ -void ActionManagerTestScene::runThisTest() -{ - auto layer = nextActionManagerAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.h b/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.h index 25d65e9ca1..1527cf30d6 100644 --- a/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.h +++ b/tests/cpp-tests/Classes/ActionManagerTest/ActionManagerTest.h @@ -4,7 +4,9 @@ #include "../testBasic.h" #include "../BaseTest.h" -class ActionManagerTest: public BaseTest +DEFINE_TEST_SUITE(ActionManagerTests); + +class ActionManagerTest : public TestCase { protected: TextureAtlas* _atlas; @@ -12,19 +14,18 @@ protected: std::string _title; public: - ActionManagerTest(void); - ~ActionManagerTest(void); + ActionManagerTest(); + ~ActionManagerTest(); virtual std::string title() const override; virtual std::string subtitle() const override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class CrashTest : public ActionManagerTest { public: + CREATE_FUNC(CrashTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void removeThis(); @@ -33,6 +34,8 @@ public: class LogicTest : public ActionManagerTest { public: + CREATE_FUNC(LogicTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void bugMe(Node* node); @@ -41,6 +44,8 @@ public: class PauseTest : public ActionManagerTest { public: + CREATE_FUNC(PauseTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void unpause(float dt); @@ -49,6 +54,8 @@ public: class StopActionTest : public ActionManagerTest { public: + CREATE_FUNC(StopActionTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void stopAction(); @@ -57,6 +64,8 @@ public: class StopAllActionsTest : public ActionManagerTest { public: + CREATE_FUNC(StopAllActionsTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void stopAction(float time); @@ -65,15 +74,11 @@ public: class ResumeTest : public ActionManagerTest { public: + CREATE_FUNC(ResumeTest); + virtual std::string subtitle() const override; virtual void onEnter() override; void resumeGrossini(float time); }; -class ActionManagerTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp b/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp index 8dd9a64c82..3e9f980ddd 100644 --- a/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp +++ b/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp @@ -32,9 +32,6 @@ enum { kTagSlider = 1, }; -Layer* nextEaseAction(); -Layer* backEaseAction(); -Layer* restartEaseAction(); //------------------------------------------------------------------ // @@ -975,84 +972,34 @@ std::string SpeedTest::subtitle() const // //------------------------------------------------------------------ -enum +ActionsEaseTests::ActionsEaseTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; - -#define MAX_LAYER 24 - -Layer* createEaseLayer(int nIndex) -{ - switch(nIndex) - { - case 0: return new SpriteEase(); - case 1: return new SpriteEaseInOut(); - case 2: return new SpriteEaseExponential(); - case 3: return new SpriteEaseExponentialInOut(); - case 4: return new SpriteEaseSine(); - case 5: return new SpriteEaseSineInOut(); - case 6: return new SpriteEaseElastic(); - case 7: return new SpriteEaseElasticInOut(); - case 8: return new SpriteEaseBounce(); - case 9: return new SpriteEaseBounceInOut(); - case 10: return new SpriteEaseBack(); - case 11: return new SpriteEaseBackInOut(); - case 12: return new SpriteEaseBezier(); - case 13: return new SpriteEaseQuadratic(); - case 14: return new SpriteEaseQuadraticInOut(); - case 15: return new SpriteEaseQuartic(); - case 16: return new SpriteEaseQuarticInOut(); - case 17: return new SpriteEaseQuintic(); - case 18: return new SpriteEaseQuinticInOut(); - case 19: return new SpriteEaseCircle(); - case 20: return new SpriteEaseCircleInOut(); - case 21: return new SpriteEaseCubic(); - case 22: return new SpriteEaseCubicInOut(); - case MAX_LAYER-1: return new SpeedTest(); - } - - - return nullptr; + ADD_TEST_CASE(SpriteEase); + ADD_TEST_CASE(SpriteEaseInOut); + ADD_TEST_CASE(SpriteEaseExponential); + ADD_TEST_CASE(SpriteEaseExponentialInOut); + ADD_TEST_CASE(SpriteEaseSine); + ADD_TEST_CASE(SpriteEaseSineInOut); + ADD_TEST_CASE(SpriteEaseElastic); + ADD_TEST_CASE(SpriteEaseElasticInOut); + ADD_TEST_CASE(SpriteEaseBounce); + ADD_TEST_CASE(SpriteEaseBounceInOut); + ADD_TEST_CASE(SpriteEaseBack); + ADD_TEST_CASE(SpriteEaseBackInOut); + ADD_TEST_CASE(SpriteEaseBezier); + ADD_TEST_CASE(SpriteEaseQuadratic); + ADD_TEST_CASE(SpriteEaseQuadraticInOut); + ADD_TEST_CASE(SpriteEaseQuartic); + ADD_TEST_CASE(SpriteEaseQuarticInOut); + ADD_TEST_CASE(SpriteEaseQuintic); + ADD_TEST_CASE(SpriteEaseQuinticInOut); + ADD_TEST_CASE(SpriteEaseCircle); + ADD_TEST_CASE(SpriteEaseCircleInOut); + ADD_TEST_CASE(SpriteEaseCubic); + ADD_TEST_CASE(SpriteEaseCubicInOut); + ADD_TEST_CASE(SpeedTest); } -Layer* nextEaseAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createEaseLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backEaseAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createEaseLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartEaseAction() -{ - auto layer = createEaseLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - - EaseSpriteDemo::EaseSpriteDemo(void) { } @@ -1079,7 +1026,7 @@ std::string EaseSpriteDemo::subtitle() const void EaseSpriteDemo::onEnter() { - BaseTest::onEnter(); + TestCase::onEnter(); // Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too _grossini = Sprite::create(s_pathGrossini); _grossini->retain(); @@ -1094,36 +1041,3 @@ void EaseSpriteDemo::onEnter() _kathia->setPosition(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2.5f/5); _tamara->setPosition(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*4/5); } - -void EaseSpriteDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create(); - s->addChild(restartEaseAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void EaseSpriteDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create(); - s->addChild( nextEaseAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void EaseSpriteDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create(); - s->addChild( backEaseAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionsEaseTestScene::runThisTest() -{ - auto layer = nextEaseAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.h b/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.h index 6afc38f77f..0175cc6e06 100644 --- a/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.h +++ b/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.h @@ -32,7 +32,9 @@ USING_NS_CC; -class EaseSpriteDemo : public BaseTest +DEFINE_TEST_SUITE(ActionsEaseTests); + +class EaseSpriteDemo : public TestCase { protected: Sprite* _grossini; @@ -49,10 +51,6 @@ public: virtual void onEnter() override; void centerSprites(unsigned int numberOfSprites); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; void positionForTwo(); }; @@ -60,6 +58,8 @@ public: class SpriteEase : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEase); + void onEnter() override; virtual std::string subtitle() const override; @@ -69,6 +69,8 @@ public: class SpriteEaseInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -76,6 +78,8 @@ public: class SpriteEaseExponential : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseExponential); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -83,6 +87,8 @@ public: class SpriteEaseExponentialInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseExponentialInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -90,6 +96,8 @@ public: class SpriteEaseSine : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseSine); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -97,6 +105,8 @@ public: class SpriteEaseSineInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseSineInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -104,6 +114,8 @@ public: class SpriteEaseElastic : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseElastic); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -111,6 +123,8 @@ public: class SpriteEaseElasticInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseElasticInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -118,6 +132,8 @@ public: class SpriteEaseBounce : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseBounce); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -125,6 +141,8 @@ public: class SpriteEaseBounceInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseBounceInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -132,6 +150,8 @@ public: class SpriteEaseBack : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseBack); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -139,6 +159,8 @@ public: class SpriteEaseBackInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseBackInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -146,6 +168,8 @@ public: class SpriteEaseBezier : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseBezier); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -153,6 +177,8 @@ public: class SpriteEaseQuadratic : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuadratic); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -160,6 +186,8 @@ public: class SpriteEaseQuadraticInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuadraticInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -167,6 +195,8 @@ public: class SpriteEaseQuartic : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuartic); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -174,6 +204,8 @@ public: class SpriteEaseQuarticInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuarticInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -181,6 +213,8 @@ public: class SpriteEaseQuintic : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuintic); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -188,6 +222,8 @@ public: class SpriteEaseQuinticInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseQuinticInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -196,6 +232,8 @@ public: class SpriteEaseCircle : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseCircle); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -203,6 +241,8 @@ public: class SpriteEaseCircleInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseCircleInOut); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -210,6 +250,8 @@ public: class SpriteEaseCubic : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseCubic); + void onEnter() override; virtual std::string subtitle() const override; }; @@ -217,23 +259,21 @@ public: class SpriteEaseCubicInOut : public EaseSpriteDemo { public: + CREATE_FUNC(SpriteEaseCubicInOut); + void onEnter() override; virtual std::string title() const override; }; class SpeedTest : public EaseSpriteDemo { public: + CREATE_FUNC(SpeedTest); + void onEnter() override; virtual std::string subtitle() const override; void altertime(float dt); }; -class ActionsEaseTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.cpp b/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.cpp index 8025c67740..6b04c3827f 100644 --- a/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.cpp +++ b/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.cpp @@ -26,70 +26,17 @@ #include "ActionsProgressTest.h" #include "../testResource.h" -static int sceneIdx = -1; - -#define MAX_LAYER 7 - -Layer* nextAction(); -Layer* backAction(); -Layer* restartAction(); - -Layer* createLayer(int nIndex) +ActionsProgressTests::ActionsProgressTests() { - switch(nIndex) - { - case 0: return new SpriteProgressToRadial(); - case 1: return new SpriteProgressToHorizontal(); - case 2: return new SpriteProgressToVertical(); - case 3: return new SpriteProgressToRadialMidpointChanged(); - case 4: return new SpriteProgressBarVarious(); - case 5: return new SpriteProgressBarTintAndFade(); - case 6: return new SpriteProgressWithSpriteFrame(); - } - - return nullptr; + ADD_TEST_CASE(SpriteProgressToRadial); + ADD_TEST_CASE(SpriteProgressToHorizontal); + ADD_TEST_CASE(SpriteProgressToVertical); + ADD_TEST_CASE(SpriteProgressToRadialMidpointChanged); + ADD_TEST_CASE(SpriteProgressBarVarious); + ADD_TEST_CASE(SpriteProgressBarTintAndFade); + ADD_TEST_CASE(SpriteProgressWithSpriteFrame); } -Layer* nextAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartAction() -{ - auto layer = createLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - - -void ProgressActionsTestScene::runThisTest() -{ - addChild(nextAction()); - Director::getInstance()->replaceScene(this); -} - - //------------------------------------------------------------------ // // SpriteDemo @@ -108,44 +55,14 @@ std::string SpriteDemo::title() const return "ActionsProgressTest"; } -std::string SpriteDemo::subtitle() const -{ - return ""; -} - void SpriteDemo::onEnter() { - BaseTest::onEnter(); + TestCase::onEnter(); auto background = LayerColor::create(Color4B(255,0,0,255)); addChild(background, -10); } -void SpriteDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ProgressActionsTestScene(); - s->addChild(restartAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpriteDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ProgressActionsTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpriteDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ProgressActionsTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - //------------------------------------------------------------------ // // SpriteProgressToRadial diff --git a/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.h b/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.h index 5d6ac433a9..1818b957f1 100644 --- a/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.h +++ b/tests/cpp-tests/Classes/ActionsProgressTest/ActionsProgressTest.h @@ -29,24 +29,23 @@ #include "../testBasic.h" #include "../BaseTest.h" -class SpriteDemo : public BaseTest +DEFINE_TEST_SUITE(ActionsProgressTests); + +class SpriteDemo : public TestCase { public: SpriteDemo(void); ~SpriteDemo(void); virtual std::string title() const override; - virtual std::string subtitle() const override; virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class SpriteProgressToRadial : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressToRadial); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -54,6 +53,8 @@ public: class SpriteProgressToHorizontal : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressToHorizontal); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -61,6 +62,8 @@ public: class SpriteProgressToVertical : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressToVertical); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -68,6 +71,8 @@ public: class SpriteProgressToRadialMidpointChanged : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressToRadialMidpointChanged); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -75,6 +80,8 @@ public: class SpriteProgressBarVarious : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressBarVarious); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -82,6 +89,8 @@ public: class SpriteProgressBarTintAndFade : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressBarTintAndFade); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -89,14 +98,10 @@ public: class SpriteProgressWithSpriteFrame : public SpriteDemo { public: + CREATE_FUNC(SpriteProgressWithSpriteFrame); + virtual void onEnter() override; virtual std::string subtitle() const override; }; -class ProgressActionsTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _ACTIONS__PROGRESS_TEST_H_ diff --git a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp index 56849fab0f..1ddc819736 100644 --- a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp +++ b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp @@ -31,112 +31,69 @@ #include "renderer/CCCustomCommand.h" #include "renderer/CCGroupCommand.h" -static std::function createFunctions[] = { - - CL(ActionManual), - CL(ActionMove), - CL(ActionMove3D), - CL(ActionRotate), - CL(ActionRotateBy3D), - CL(ActionScale), - CL(ActionSkew), - CL(ActionRotationalSkew), - CL(ActionRotationalSkewVSStandardSkew), - CL(ActionSkewRotateScale), - CL(ActionJump), - CL(ActionCardinalSpline), - CL(ActionCatmullRom), - CL(ActionBezier), - CL(ActionBlink), - CL(ActionFade), - CL(ActionTint), - CL(ActionAnimate), - CL(ActionSequence), - CL(ActionSequence2), - CL(ActionRemoveSelf), - CL(ActionSpawn), - CL(ActionReverse), - CL(ActionDelayTime), - CL(ActionRepeat), - CL(ActionRepeatForever), - CL(ActionRotateToRepeat), - CL(ActionRotateJerk), - CL(ActionCallFunction), - CL(ActionCallFuncN), - CL(ActionCallFuncND), - CL(ActionCallFuncO), - CL(ActionReverseSequence), - CL(ActionReverseSequence2), - CL(ActionOrbit), - CL(ActionFollow), - CL(ActionTargeted), - CL(ActionTargetedReverse), - CL(ActionMoveStacked), - CL(ActionMoveJumpStacked), - CL(ActionMoveBezierStacked), - CL(ActionCardinalSplineStacked), - CL(ActionCatmullRomStacked), - CL(PauseResumeActions), - CL(Issue1305), - CL(Issue1305_2), - CL(Issue1288), - CL(Issue1288_2), - CL(Issue1327), - CL(Issue1398), - CL(Issue2599) -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() +ActionsTests::ActionsTests() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(ActionManual); + ADD_TEST_CASE(ActionMove); + ADD_TEST_CASE(ActionMove3D); + ADD_TEST_CASE(ActionRotate); + ADD_TEST_CASE(ActionRotateBy3D); + ADD_TEST_CASE(ActionScale); + ADD_TEST_CASE(ActionSkew); + ADD_TEST_CASE(ActionRotationalSkew); + ADD_TEST_CASE(ActionRotationalSkewVSStandardSkew); + ADD_TEST_CASE(ActionSkewRotateScale); + ADD_TEST_CASE(ActionJump); + ADD_TEST_CASE(ActionCardinalSpline); + ADD_TEST_CASE(ActionCatmullRom); + ADD_TEST_CASE(ActionBezier); + ADD_TEST_CASE(ActionBlink); + ADD_TEST_CASE(ActionFade); + ADD_TEST_CASE(ActionTint); + ADD_TEST_CASE(ActionAnimate); + ADD_TEST_CASE(ActionSequence); + ADD_TEST_CASE(ActionSequence2); + ADD_TEST_CASE(ActionRemoveSelf); + ADD_TEST_CASE(ActionSpawn); + ADD_TEST_CASE(ActionReverse); + ADD_TEST_CASE(ActionDelayTime); + ADD_TEST_CASE(ActionRepeat); + ADD_TEST_CASE(ActionRepeatForever); + ADD_TEST_CASE(ActionRotateToRepeat); + ADD_TEST_CASE(ActionRotateJerk); + ADD_TEST_CASE(ActionCallFunction); + ADD_TEST_CASE(ActionCallFuncN); + ADD_TEST_CASE(ActionCallFuncND); + ADD_TEST_CASE(ActionCallFuncO); + ADD_TEST_CASE(ActionReverseSequence); + ADD_TEST_CASE(ActionReverseSequence2); + ADD_TEST_CASE(ActionOrbit); + ADD_TEST_CASE(ActionFollow); + ADD_TEST_CASE(ActionTargeted); + ADD_TEST_CASE(ActionTargetedReverse); + ADD_TEST_CASE(ActionMoveStacked); + ADD_TEST_CASE(ActionMoveJumpStacked); + ADD_TEST_CASE(ActionMoveBezierStacked); + ADD_TEST_CASE(ActionCardinalSplineStacked); + ADD_TEST_CASE(ActionCatmullRomStacked); + ADD_TEST_CASE(PauseResumeActions); + ADD_TEST_CASE(Issue1305); + ADD_TEST_CASE(Issue1305_2); + ADD_TEST_CASE(Issue1288); + ADD_TEST_CASE(Issue1288_2); + ADD_TEST_CASE(Issue1327); + ADD_TEST_CASE(Issue1398); + ADD_TEST_CASE(Issue2599) } -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void ActionsTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(nextAction()); - - Director::getInstance()->replaceScene(this); -} - - std::string ActionsDemo::title() const { return "ActionsTest"; } -std::string ActionsDemo::subtitle() const -{ - return ""; -} - void ActionsDemo::onEnter() { - BaseTest::onEnter(); + TestCase::onEnter(); // Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too _grossini = Sprite::create(s_pathGrossini); @@ -163,31 +120,7 @@ void ActionsDemo::onExit() _tamara->release(); _kathia->release(); - BaseTest::onExit(); -} - -void ActionsDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsTestScene(); - s->addChild( restartAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionsDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionsDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ActionsTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); + TestCase::onExit(); } void ActionsDemo::centerSprites(unsigned int numberOfSprites) @@ -1464,9 +1397,9 @@ void ActionStacked::onEnter() this->centerSprites(0); - auto listener = EventListenerTouchAllAtOnce::create(); + /*auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(ActionStacked::onTouchesEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/ auto s = Director::getInstance()->getWinSize(); this->addNewSpriteWithCoords(Vec2(s.width/2, s.height/2)); @@ -1492,13 +1425,14 @@ void ActionStacked::runActionsInSprite(Sprite *sprite) // override me } +/* void ActionStacked::onTouchesEnded(const std::vector& touches, Event* event) { for ( auto &touch: touches ) { auto location = touch->getLocation(); addNewSpriteWithCoords( location ); } -} +}*/ std::string ActionStacked::title() const { diff --git a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.h b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.h index 9b33bea52c..3c20a1b7c2 100644 --- a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.h +++ b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.h @@ -28,21 +28,12 @@ #include "../testBasic.h" #include "../BaseTest.h" -////----#include "cocos2d.h" USING_NS_CC; +DEFINE_TEST_SUITE(ActionsTests); -// the class inherit from TestScene -// every Scene each test used must inherit from TestScene, -// make sure the test have the menu item for back to main menu -class ActionsTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -class ActionsDemo : public BaseTest +class ActionsDemo : public TestCase { protected: Sprite* _grossini; @@ -55,11 +46,6 @@ public: void centerSprites(unsigned int numberOfSprites); void alignSpritesLeft(unsigned int numberOfSprites); virtual std::string title() const override; - virtual std::string subtitle() const override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class ActionManual : public ActionsDemo @@ -421,7 +407,7 @@ public: virtual std::string subtitle() const override; virtual void addNewSpriteWithCoords(Vec2 p); virtual void runActionsInSprite(Sprite* sprite); - void onTouchesEnded(const std::vector& touches, Event* event) override; + //void onTouchesEnded(const std::vector& touches, Event* event) override; }; class ActionMoveStacked : public ActionStacked diff --git a/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.cpp b/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.cpp index b3dde9fa20..7e1ac5cd71 100644 --- a/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.cpp +++ b/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.cpp @@ -27,189 +27,131 @@ #include "cocos2d.h" #include -namespace AllocatorTestNS +AllocatorTests::AllocatorTests() { - + ADD_TEST_CASE(AllocatorTest); +} + +#define kNumberOfInstances 100000 +#define kObjectSize 952 // sizeof(Sprite) + +namespace +{ + class Test1; + + class Test1 + { + public: + + Test1() + { + memset(bytes, 0, sizeof(bytes)); + } + uint8_t bytes[kObjectSize]; + +#if CC_ENABLE_ALLOCATOR + typedef cocos2d::allocator::AllocatorStrategyPool tAllocator; + static tAllocator _allocator; +#endif // CC_ENABLE_ALLOCATOR + CC_USE_ALLOCATOR_POOL(Test1, _allocator); + }; + + class Test2 + { + public: + + Test2() + { + memset(bytes, 0, sizeof(bytes)); + } + uint8_t bytes[kObjectSize]; + }; + #if CC_ENABLE_ALLOCATOR Test1::tAllocator Test1::_allocator("Test1", kNumberOfInstances); #endif // CC_ENABLE_ALLOCATOR - - static int sceneIdx = -1; - - static std::function createFunctions[] = - { - CL(AllocatorTest) - }; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - - static Layer* nextAllocatorTestAction() - { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - static Layer* backAllocatorTestAction() - { - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - static Layer* restartAllocatorTestAction() - { - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - // - // AllocatorTest - // - - AllocatorTest::AllocatorTest() - { - typedef std::vector tTest1Container; - typedef std::vector tTest2Container; - - tTest1Container test1Container; - test1Container.reserve(kNumberOfInstances); - - tTest2Container test2Container; - test2Container.reserve(kNumberOfInstances); - - std::chrono::time_point alloc1Start, alloc1End, alloc2Start, alloc2End; - std::chrono::time_point free1Start, free1End, free2Start, free2End; - - alloc1Start = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < kNumberOfInstances; ++i) - test1Container.push_back(new Test1); - alloc1End = std::chrono::high_resolution_clock::now(); - - free1Start = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < kNumberOfInstances; ++i) - delete test1Container[i]; - free1End = std::chrono::high_resolution_clock::now(); - test1Container.clear(); +} - alloc2Start = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < kNumberOfInstances; ++i) - test2Container.push_back(new Test2); - alloc2End = std::chrono::high_resolution_clock::now(); +// +// AllocatorTest +// + +AllocatorTest::AllocatorTest() +{ + typedef std::vector tTest1Container; + typedef std::vector tTest2Container; + + tTest1Container test1Container; + test1Container.reserve(kNumberOfInstances); + + tTest2Container test2Container; + test2Container.reserve(kNumberOfInstances); + + std::chrono::time_point alloc1Start, alloc1End, alloc2Start, alloc2End; + std::chrono::time_point free1Start, free1End, free2Start, free2End; + + alloc1Start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < kNumberOfInstances; ++i) + test1Container.push_back(new Test1); + alloc1End = std::chrono::high_resolution_clock::now(); + + free1Start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < kNumberOfInstances; ++i) + delete test1Container[i]; + free1End = std::chrono::high_resolution_clock::now(); + test1Container.clear(); + + alloc2Start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < kNumberOfInstances; ++i) + test2Container.push_back(new Test2); + alloc2End = std::chrono::high_resolution_clock::now(); - free2Start = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < kNumberOfInstances; ++i) - delete test2Container[i]; - free2End = std::chrono::high_resolution_clock::now(); - - test2Container.clear(); - - std::chrono::duration elapsed_seconds_alloc1 = alloc1End - alloc1Start; - std::chrono::duration elapsed_seconds_alloc2 = alloc2End - alloc2Start; - std::chrono::duration elapsed_seconds_free1 = free1End - free1Start; - std::chrono::duration elapsed_seconds_free2 = free2End - free2Start; - - char buf[1000]; - - const float x_start = 240; - const float y_start = 100; - const float y_delta = 20; - float y = 0; - - sprintf(buf, "alloc1 %f", elapsed_seconds_alloc1.count()); - auto alloc1 = Label::createWithSystemFont(buf, "Helvetica", 12); - alloc1->setPosition(x_start, y++ * y_delta + y_start); - addChild(alloc1); - - sprintf(buf, "alloc2 %f", elapsed_seconds_alloc2.count()); - auto alloc2 = Label::createWithSystemFont(buf, "Helvetica", 12); - alloc2->setPosition(x_start, y++ * y_delta + y_start); - addChild(alloc2); - - sprintf(buf, "free1 %f", elapsed_seconds_free1.count()); - auto free1 = Label::createWithSystemFont(buf, "Helvetica", 12); - free1->setPosition(x_start, y++ * y_delta + y_start); - addChild(free1); - - sprintf(buf, "free2 %f", elapsed_seconds_free2.count()); - auto free2 = Label::createWithSystemFont(buf, "Helvetica", 12); - free2->setPosition(x_start, y++ * y_delta + y_start); - addChild(free2); - } - - AllocatorTest::~AllocatorTest() - { - } - - std::string AllocatorTest::title() const - { - return "Allocator Test"; - } - - std::string AllocatorTest::subtitle() const - { - return ""; - } - - void AllocatorTest::restartCallback( Ref* sender ) - { - auto s = new AllocatorTestScene(); - s->addChild(restartAllocatorTestAction()); - Director::getInstance()->replaceScene(s); - s->release(); - } - - void AllocatorTest::nextCallback( Ref* sender ) - { - auto s = new AllocatorTestScene(); - s->addChild( nextAllocatorTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); - } - - void AllocatorTest::backCallback( Ref* sender ) - { - auto s = new AllocatorTestScene(); - s->addChild( backAllocatorTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); - } - - void AllocatorTest::onEnter() - { - BaseTest::onEnter(); - } - - void AllocatorTest::onExit() - { - BaseTest::onExit(); - } - - void AllocatorTest::update(float delta) - { - } - - // - // AllocatorTestScene - // - - AllocatorTestScene::AllocatorTestScene() - { - } - - void AllocatorTestScene::runThisTest() - { - auto layer = nextAllocatorTestAction(); - addChild(layer); - Director::getInstance()->replaceScene(this); - } - -} // AllocatorTestNS + free2Start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < kNumberOfInstances; ++i) + delete test2Container[i]; + free2End = std::chrono::high_resolution_clock::now(); + test2Container.clear(); + + std::chrono::duration elapsed_seconds_alloc1 = alloc1End - alloc1Start; + std::chrono::duration elapsed_seconds_alloc2 = alloc2End - alloc2Start; + std::chrono::duration elapsed_seconds_free1 = free1End - free1Start; + std::chrono::duration elapsed_seconds_free2 = free2End - free2Start; + + char buf[1000]; + + const float x_start = 240; + const float y_start = 100; + const float y_delta = 20; + float y = 0; + + sprintf(buf, "alloc1 %f", elapsed_seconds_alloc1.count()); + auto alloc1 = Label::createWithSystemFont(buf, "Helvetica", 12); + alloc1->setPosition(x_start, y++ * y_delta + y_start); + addChild(alloc1); + + sprintf(buf, "alloc2 %f", elapsed_seconds_alloc2.count()); + auto alloc2 = Label::createWithSystemFont(buf, "Helvetica", 12); + alloc2->setPosition(x_start, y++ * y_delta + y_start); + addChild(alloc2); + + sprintf(buf, "free1 %f", elapsed_seconds_free1.count()); + auto free1 = Label::createWithSystemFont(buf, "Helvetica", 12); + free1->setPosition(x_start, y++ * y_delta + y_start); + addChild(free1); + + sprintf(buf, "free2 %f", elapsed_seconds_free2.count()); + auto free2 = Label::createWithSystemFont(buf, "Helvetica", 12); + free2->setPosition(x_start, y++ * y_delta + y_start); + addChild(free2); +} + +AllocatorTest::~AllocatorTest() +{ +} + +std::string AllocatorTest::title() const +{ + return "Allocator Test"; +} diff --git a/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.h b/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.h index 22ae2f3e96..75c54b80ae 100644 --- a/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.h +++ b/tests/cpp-tests/Classes/AllocatorTest/AllocatorTest.h @@ -29,71 +29,15 @@ #include "../BaseTest.h" #include "base/allocator/CCAllocatorStrategyPool.h" -namespace AllocatorTestNS +DEFINE_TEST_SUITE(AllocatorTests); + +class AllocatorTest : public TestCase { - - // - // Test Classes - // - -#define kNumberOfInstances 100000 -#define kObjectSize 952 // sizeof(Sprite) - - class Test1; - - class Test1 - { - public: - - Test1() - { - memset(bytes, 0, sizeof(bytes)); - } - uint8_t bytes[kObjectSize]; - -#if CC_ENABLE_ALLOCATOR - typedef cocos2d::allocator::AllocatorStrategyPool tAllocator; - static tAllocator _allocator; -#endif // CC_ENABLE_ALLOCATOR - CC_USE_ALLOCATOR_POOL(Test1, _allocator); - }; - - class Test2 - { - public: - - Test2() - { - memset(bytes, 0, sizeof(bytes)); - } - uint8_t bytes[kObjectSize]; - }; - - class AllocatorTest : public BaseTest - { - public: - CREATE_FUNC(AllocatorTest); - AllocatorTest(); - virtual ~AllocatorTest(); - - virtual std::string title() const override; - virtual std::string subtitle() const override; - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; - - virtual void onEnter() override; - virtual void onExit() override; - - virtual void update(float delta) override; - }; - - class AllocatorTestScene : public TestScene - { - public: - AllocatorTestScene(); - virtual void runThisTest(); - }; - -} // AllocatorTestNS +public: + CREATE_FUNC(AllocatorTest); + + AllocatorTest(); + virtual ~AllocatorTest(); + + virtual std::string title() const override; +}; diff --git a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp index 490be99e66..e48ed0e9e7 100644 --- a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp +++ b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp @@ -29,48 +29,10 @@ #include #include "../testResource.h" -enum +BillBoardTests::BillBoardTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; - - -static std::function createFunctions[] = -{ - CL(BillBoardRotationTest), - CL(BillBoardTest) -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartTest() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(BillBoardRotationTest); + ADD_TEST_CASE(BillBoardTest); } //------------------------------------------------------------------ @@ -137,31 +99,6 @@ std::string BillBoardRotationTest::subtitle() const return "All the sprites should still facing camera"; } -void BillBoardRotationTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(restartTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BillBoardRotationTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(nextTest()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BillBoardRotationTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(backTest()); - Director::getInstance()->replaceScene(s); - s->release(); -} - //------------------------------------------------------------------ // // Billboard Rendering Test @@ -171,9 +108,9 @@ BillBoardTest::BillBoardTest() : _camera(nullptr) { //Create touch listener - auto listener = EventListenerTouchAllAtOnce::create(); + /*auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesMoved = CC_CALLBACK_2(BillBoardTest::onTouchesMoved, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/ auto layer3D=Layer::create(); addChild(layer3D,0); @@ -333,6 +270,8 @@ void BillBoardTest::addNewAniBillBoradWithCoords(Vec3 p) void BillBoardTest::update(float dt) { } + +/* void BillBoardTest::onTouchesMoved(const std::vector& touches, Event* event) { if(touches.size()==1) @@ -355,43 +294,11 @@ void BillBoardTest::onTouchesMoved(const std::vector& touches, Event* ev cameraPos+=cameraRightDir*newPos.x*0.5; _camera->setPosition3D(cameraPos); } -} +}*/ + void BillBoardTest::rotateCameraCallback(Ref* sender,float value) { Vec3 rotation3D= _camera->getRotation3D(); rotation3D.y+= value; _camera->setRotation3D(rotation3D); } - - -void BillBoardTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(restartTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BillBoardTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(nextTest()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BillBoardTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) BillBoardTestScene(); - s->addChild(backTest()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BillBoardTestScene::runThisTest() -{ - auto layer = nextTest(); - addChild(layer); - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h index 34f79590d4..00114efabf 100644 --- a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h +++ b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h @@ -34,7 +34,7 @@ namespace cocos2d { class Camera; } -class BillBoardRotationTest : public BaseTest +class BillBoardRotationTest : public TestCase { public: CREATE_FUNC(BillBoardRotationTest); @@ -43,14 +43,10 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; - protected: }; -class BillBoardTest : public BaseTest +class BillBoardTest : public TestCase { public: virtual ~BillBoardTest(void); @@ -62,14 +58,10 @@ public: void addNewBillBoradWithCoords(Vec3 p); void addNewAniBillBoradWithCoords(Vec3 p); void rotateCameraCallback(Ref* sender,float value); - void onTouchesMoved(const std::vector& touches, Event* event) override; + //void onTouchesMoved(const std::vector& touches, Event* event) override; void menuCallback_orientedPoint(Ref* sender); void menuCallback_orientedPlane(Ref* sender); - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; protected: Camera* _camera; @@ -78,10 +70,6 @@ protected: std::vector _billboards; }; -class BillBoardTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(BillBoardTests); #endif diff --git a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp index 3bfc7fd686..604619f99f 100644 --- a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp +++ b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp @@ -12,7 +12,7 @@ enum { kTagParentNode = 1, }; -Box2DTestLayer::Box2DTestLayer() +Box2DTest::Box2DTest() : _spriteTexture(nullptr) , world(nullptr) { @@ -20,7 +20,7 @@ Box2DTestLayer::Box2DTestLayer() auto dispatcher = Director::getInstance()->getEventDispatcher(); auto touchListener = EventListenerTouchAllAtOnce::create(); - touchListener->onTouchesEnded = CC_CALLBACK_2(Box2DTestLayer::onTouchesEnded, this); + touchListener->onTouchesEnded = CC_CALLBACK_2(Box2DTest::onTouchesEnded, this); dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); // init physics @@ -60,14 +60,14 @@ Box2DTestLayer::Box2DTestLayer() #endif } -Box2DTestLayer::~Box2DTestLayer() +Box2DTest::~Box2DTest() { CC_SAFE_DELETE(world); //delete _debugDraw; } -void Box2DTestLayer::initPhysics() +void Box2DTest::initPhysics() { b2Vec2 gravity; gravity.Set(0.0f, -10.0f); @@ -119,15 +119,10 @@ void Box2DTestLayer::initPhysics() groundBody->CreateFixture(&groundBox,0); } -void Box2DTestLayer::createResetButton() +void Box2DTest::createResetButton() { - auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [](Ref *sender) { - auto s = new (std::nothrow) Box2DTestScene(); - auto child = new (std::nothrow) Box2DTestLayer(); - s->addChild(child); - child->release(); - Director::getInstance()->replaceScene(s); - s->release(); + auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [&](Ref *sender) { + getTestSuite()->restartCurrTest(); }); auto menu = Menu::create(reset, nullptr); @@ -137,14 +132,14 @@ void Box2DTestLayer::createResetButton() } -void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) +void Box2DTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // - Layer::draw(renderer, transform, flags); + Scene::draw(renderer, transform, flags); #if CC_ENABLE_BOX2D_INTEGRATION GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); @@ -155,7 +150,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t fl _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); - _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); + _customCommand.func = CC_CALLBACK_0(Box2DTest::onDraw, this); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); @@ -163,7 +158,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t fl } #if CC_ENABLE_BOX2D_INTEGRATION -void Box2DTestLayer::onDraw() +void Box2DTest::onDraw() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); @@ -175,7 +170,7 @@ void Box2DTestLayer::onDraw() } #endif -void Box2DTestLayer::addNewSpriteAtPosition(Vec2 p) +void Box2DTest::addNewSpriteAtPosition(Vec2 p) { CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); @@ -214,7 +209,7 @@ void Box2DTestLayer::addNewSpriteAtPosition(Vec2 p) } -void Box2DTestLayer::update(float dt) +void Box2DTest::update(float dt) { //It is recommended that a fixed time step is used with Box2D for stability //of the simulation, however, we are using a variable time step here. @@ -229,7 +224,7 @@ void Box2DTestLayer::update(float dt) world->Step(dt, velocityIterations, positionIterations); } -void Box2DTestLayer::onTouchesEnded(const std::vector& touches, Event* event) +void Box2DTest::onTouchesEnded(const std::vector& touches, Event* event) { //Add a new body/atlas sprite at the touched location @@ -245,7 +240,7 @@ void Box2DTestLayer::onTouchesEnded(const std::vector& touches, Event* e } /* -void Box2DTestLayer::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) +void Box2DTest::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) { static float prevX=0, prevY=0; @@ -266,12 +261,4 @@ void Box2DTestLayer::accelerometer(UIAccelerometer* accelerometer, Acceleration* } */ -void Box2DTestScene::runThisTest() -{ - auto layer = new (std::nothrow) Box2DTestLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h index 7d8e386825..3fbe556031 100644 --- a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h +++ b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.h @@ -3,17 +3,19 @@ #include "cocos2d.h" #include "Box2D/Box2D.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class Box2DTestLayer : public Layer +DEFINE_TEST_SUITE(Box2DTests); + +class Box2DTest : public TestCase { Texture2D* _spriteTexture; // weak ref b2World* world; // GLESDebugDraw* _debugDraw; public: - Box2DTestLayer(); - ~Box2DTestLayer(); + Box2DTest(); + ~Box2DTest(); void initPhysics(); void createResetButton(); @@ -21,7 +23,7 @@ public: void addNewSpriteAtPosition(Vec2 p); void update(float dt) override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); #if CC_ENABLE_BOX2D_INTEGRATION protected: @@ -31,10 +33,4 @@ protected: #endif } ; -class Box2DTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp index 57790d7eff..4795b76523 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp @@ -15,38 +15,40 @@ enum kTagBox2DNode, }; - -//------------------------------------------------------------------ -// -// MenuLayer -// -//------------------------------------------------------------------ -enum +Box2dTestBedSuite::Box2dTestBedSuite() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; + for (int entryId = 0; entryId < g_totalEntries; ++entryId) + { + addTestCase(g_testEntries[entryId].name, [&](){ + return Box2dTestBed::createWithEntryID(entryId); + }); + } +} +//------------------------------------------------------------------ +// +// Box2dTestBed +// +//------------------------------------------------------------------ -MenuLayer::MenuLayer(void) +Box2dTestBed::Box2dTestBed() { } -MenuLayer::~MenuLayer(void) +Box2dTestBed::~Box2dTestBed() { _eventDispatcher->removeEventListener(_touchListener); } -MenuLayer* MenuLayer::menuWithEntryID(int entryId) +Box2dTestBed* Box2dTestBed::createWithEntryID(int entryId) { - auto layer = new (std::nothrow) MenuLayer(); + auto layer = new (std::nothrow) Box2dTestBed(); layer->initWithEntryID(entryId); layer->autorelease(); return layer; } -bool MenuLayer::initWithEntryID(int entryId) +bool Box2dTestBed::initWithEntryID(int entryId) { auto director = Director::getInstance(); Vec2 visibleOrigin = director->getVisibleOrigin(); @@ -62,26 +64,13 @@ bool MenuLayer::initWithEntryID(int entryId) auto label = Label::createWithTTF(view->title().c_str(), "fonts/arial.ttf", 28); addChild(label, 1); label->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50); - - auto item1 = MenuItemImage::create("Images/b1.png", "Images/b2.png", CC_CALLBACK_1(MenuLayer::backCallback, this) ); - auto item2 = MenuItemImage::create("Images/r1.png","Images/r2.png", CC_CALLBACK_1( MenuLayer::restartCallback, this) ); - auto item3 = MenuItemImage::create("Images/f1.png", "Images/f2.png", CC_CALLBACK_1(MenuLayer::nextCallback, this) ); - - auto menu = Menu::create(item1, item2, item3, nullptr); - - menu->setPosition( Vec2::ZERO ); - item1->setPosition(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2); - item2->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2); - item3->setPosition(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2); - - addChild(menu, 1); // Adds touch event listener auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); - listener->onTouchBegan = CC_CALLBACK_2(MenuLayer::onTouchBegan, this); - listener->onTouchMoved = CC_CALLBACK_2(MenuLayer::onTouchMoved, this); + listener->onTouchBegan = CC_CALLBACK_2(Box2dTestBed::onTouchBegan, this); + listener->onTouchMoved = CC_CALLBACK_2(Box2dTestBed::onTouchMoved, this); _eventDispatcher->addEventListenerWithFixedPriority(listener, 1); @@ -90,62 +79,12 @@ bool MenuLayer::initWithEntryID(int entryId) return true; } -void MenuLayer::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) Box2dTestBedScene(); - auto box = MenuLayer::menuWithEntryID(m_entryID); - s->addChild( box ); - Director::getInstance()->replaceScene( s ); - s->release(); -} - -void MenuLayer::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) Box2dTestBedScene(); - int next = m_entryID + 1; - if( next >= g_totalEntries) - next = 0; - auto box = MenuLayer::menuWithEntryID(next); - s->addChild( box ); - Director::getInstance()->replaceScene( s ); - s->release(); -} - -void MenuLayer::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) Box2dTestBedScene(); - int next = m_entryID - 1; - if( next < 0 ) { - next = g_totalEntries - 1; - } - - auto box = MenuLayer::menuWithEntryID(next); - - s->addChild( box ); - Director::getInstance()->replaceScene( s ); - s->release(); -} - -//void MenuLayer::registerWithTouchDispatcher() -//{ -// auto director = Director::getInstance(); -// director->getTouchDispatcher()->addTargetedDelegate(this, 0, true); -//} - -bool MenuLayer::onTouchBegan(Touch* touch, Event* event) +bool Box2dTestBed::onTouchBegan(Touch* touch, Event* event) { return true; } -//-(void) MenuLayer::ccTouchEnded:(UITouch *)touch withEvent:(Event *)event -//{ -//} -// -//-(void) MenuLayer::ccTouchCancelled:(UITouch *)touch withEvent:(Event *)event -//{ -//} - -void MenuLayer::onTouchMoved(Touch* touch, Event* event) +void Box2dTestBed::onTouchMoved(Touch* touch, Event* event) { auto diff = touch->getDelta(); auto node = getChildByTag( kTagBox2DNode ); @@ -233,13 +172,6 @@ Box2DView::~Box2DView() _eventDispatcher->removeEventListener(_keyboardListener); delete m_test; } -// -//void Box2DView::registerWithTouchDispatcher() -//{ -// // higher priority than dragging -// auto director = Director::getInstance(); -// director->getTouchDispatcher()->addTargetedDelegate(this, -10, true); -//} bool Box2DView::onTouchBegan(Touch* touch, Event* event) { @@ -282,20 +214,3 @@ void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event) log("onKeyReleased, keycode: %d", code); m_test->KeyboardUp(static_cast(code)); } - -// void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) -// { -// //// Only run for valid values -// //if (acceleration.y!=0 && acceleration.x!=0) -// //{ -// // if (test) test->SetGravity((float)-acceleration.y,(float)acceleration.x); -// //} -// } - - -void Box2dTestBedScene::runThisTest() -{ - addChild(MenuLayer::menuWithEntryID(0)); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h index 0f484079e8..74905b97a6 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h @@ -1,30 +1,25 @@ #ifndef _BOX2D_VIEW_H_ #define _BOX2D_VIEW_H_ -//#include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" #include "renderer/CCCustomCommand.h" -class MenuLayer : public Layer +DEFINE_TEST_SUITE(Box2dTestBedSuite); + +class Box2dTestBed : public TestCase { int m_entryID; EventListenerTouchOneByOne* _touchListener; public: - MenuLayer(void); - virtual ~MenuLayer(void); + static Box2dTestBed* createWithEntryID(int entryId); + + Box2dTestBed(); + virtual ~Box2dTestBed(); bool initWithEntryID(int entryId); - void restartCallback(Ref* sender); - void nextCallback(Ref* sender); - void backCallback(Ref* sender); - - bool onTouchBegan(Touch* touch, Event* event); void onTouchMoved(Touch* touch, Event* event); - -public: - static MenuLayer* menuWithEntryID(int entryId); }; struct TestEntry; @@ -60,10 +55,4 @@ protected: CustomCommand _customCmd; }; -class Box2dTestBedScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp index eafe9c33b9..3236312b31 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1159.cpp @@ -20,7 +20,7 @@ Scene* Bug1159Layer::scene() bool Bug1159Layer::init() { - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { auto s = Director::getInstance()->getWinSize(); @@ -62,5 +62,5 @@ void Bug1159Layer::callBack(Ref* sender) void Bug1159Layer::onExit() { - BugsTestBaseLayer::onExit(); + BugsTestBase::onExit(); } diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1159.h b/tests/cpp-tests/Classes/BugsTest/Bug-1159.h index d3384138db..c02efce4fc 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1159.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1159.h @@ -3,7 +3,7 @@ #include "BugsTest.h" -class Bug1159Layer : public BugsTestBaseLayer +class Bug1159Layer : public BugsTestBase { public: virtual bool init() override; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp index 051607f2ce..5b4fae440e 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1174.cpp @@ -32,7 +32,7 @@ int check_for_error( Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, float s, float t ) bool Bug1174Layer::init() { - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { // // seed // srand(0); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-1174.h b/tests/cpp-tests/Classes/BugsTest/Bug-1174.h index 8349f704d4..c03487fff8 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-1174.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-1174.h @@ -3,9 +3,11 @@ #include "BugsTest.h" -class Bug1174Layer : public BugsTestBaseLayer +class Bug1174Layer : public BugsTestBase { public: + CREATE_FUNC(Bug1174Layer); + virtual bool init() override; }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-350.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-350.cpp index 5a609584cf..292638f6a6 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-350.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-350.cpp @@ -7,7 +7,7 @@ bool Bug350Layer::init() { - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { auto size = Director::getInstance()->getWinSize(); auto background = Sprite::create("Hello.png"); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-350.h b/tests/cpp-tests/Classes/BugsTest/Bug-350.h index 9182f34959..ff0023414c 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-350.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-350.h @@ -3,9 +3,11 @@ #include "BugsTest.h" -class Bug350Layer : public BugsTestBaseLayer +class Bug350Layer : public BugsTestBase { public: + CREATE_FUNC(Bug350Layer); + virtual bool init() override; }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-422.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-422.cpp index 1cfa8861ff..7c906d1be2 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-422.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-422.cpp @@ -7,7 +7,7 @@ bool Bug422Layer::init() { - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { reset(); return true; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-422.h b/tests/cpp-tests/Classes/BugsTest/Bug-422.h index 1de086e1d3..016fa70dc3 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-422.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-422.h @@ -3,9 +3,11 @@ #include "BugsTest.h" -class Bug422Layer : public BugsTestBaseLayer +class Bug422Layer : public BugsTestBase { public: + CREATE_FUNC(Bug422Layer); + virtual bool init() override; void reset(); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp index 7f07424b17..2c19aecab2 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp @@ -8,7 +8,7 @@ bool Bug458Layer::init() { - if(BugsTestBaseLayer::init()) + if(BugsTestBase::init()) { // ask director the the window size auto size = Director::getInstance()->getWinSize(); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h b/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h index 6b510353d7..ea3551cdd6 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h @@ -3,9 +3,11 @@ #include "../BugsTest.h" -class Bug458Layer : public BugsTestBaseLayer +class Bug458Layer : public BugsTestBase { public: + CREATE_FUNC(Bug458Layer); + virtual bool init() override; void selectAnswer(Ref* sender); }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-624.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-624.cpp index f27ec46059..d894ff6450 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-624.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-624.cpp @@ -17,7 +17,7 @@ Bug624Layer::~Bug624Layer() bool Bug624Layer::init() { - if(BugsTestBaseLayer::init()) + if(BugsTestBase::init()) { auto size = Director::getInstance()->getWinSize(); auto label = Label::createWithTTF("Layer1", "fonts/Marker Felt.ttf", 36.0f); @@ -63,7 +63,7 @@ Bug624Layer2::~Bug624Layer2() bool Bug624Layer2::init() { - if(BugsTestBaseLayer::init()) + if(BugsTestBase::init()) { auto size = Director::getInstance()->getWinSize(); auto label = Label::createWithTTF("Layer2", "fonts/Marker Felt.ttf", 36.0f); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-624.h b/tests/cpp-tests/Classes/BugsTest/Bug-624.h index 8d97a3a1f9..44e045363b 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-624.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-624.h @@ -3,24 +3,24 @@ #include "BugsTest.h" -class Bug624Layer : public BugsTestBaseLayer +class Bug624Layer : public BugsTestBase { public: virtual ~Bug624Layer(); virtual bool init() override; void switchLayer(float dt); - virtual void onAcceleration(Acceleration* acc, Event* event) override; + virtual void onAcceleration(Acceleration* acc, Event* event); CREATE_FUNC(Bug624Layer); }; -class Bug624Layer2 : public BugsTestBaseLayer +class Bug624Layer2 : public BugsTestBase { public: virtual ~Bug624Layer2(); virtual bool init() override; void switchLayer(float dt); - virtual void onAcceleration(Acceleration* acc, Event* event) override; + virtual void onAcceleration(Acceleration* acc, Event* event); CREATE_FUNC(Bug624Layer2); }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-886.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-886.cpp index 714cdefb16..178442d96e 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-886.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-886.cpp @@ -7,7 +7,7 @@ bool Bug886Layer::init() { - if(BugsTestBaseLayer::init()) + if(BugsTestBase::init()) { // ask director the the window size // auto size = [[Director sharedDirector] winSize]; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-886.h b/tests/cpp-tests/Classes/BugsTest/Bug-886.h index 5a72a48a18..6ec7ca57a3 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-886.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-886.h @@ -3,9 +3,11 @@ #include "BugsTest.h" -class Bug886Layer : public BugsTestBaseLayer +class Bug886Layer : public BugsTestBase { public: + CREATE_FUNC(Bug886Layer); + virtual bool init() override; }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-899.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-899.cpp index 80179ae490..15286676f0 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-899.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-899.cpp @@ -10,7 +10,7 @@ bool Bug899Layer::init() { // Director::getInstance()->enableRetinaDisplay(true); - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { auto bg = Sprite::create("Images/bugs/RetinaDisplay.jpg"); addChild(bg, 0); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-899.h b/tests/cpp-tests/Classes/BugsTest/Bug-899.h index 1877b7965a..fa2b2b82fb 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-899.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-899.h @@ -3,9 +3,11 @@ #include "BugsTest.h" -class Bug899Layer : public BugsTestBaseLayer +class Bug899Layer : public BugsTestBase { public: + CREATE_FUNC(Bug899Layer); + virtual bool init() override; }; diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp index 9ba973e494..85166f6b5a 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-914.cpp @@ -28,7 +28,7 @@ bool Bug914Layer::init() { // always call "super" init // Apple recommends to re-assign "self" with the "super" return value - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-914.h b/tests/cpp-tests/Classes/BugsTest/Bug-914.h index 580bce8f95..98b2bd09ac 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-914.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-914.h @@ -3,14 +3,14 @@ #include "BugsTest.h" -class Bug914Layer : public BugsTestBaseLayer +class Bug914Layer : public BugsTestBase { public: static Scene* scene(); virtual bool init() override; - void onTouchesMoved(const std::vector& touches, Event * event) override; - void onTouchesBegan(const std::vector& touches, Event * event) override; + void onTouchesMoved(const std::vector& touches, Event * event); + void onTouchesBegan(const std::vector& touches, Event * event); void restart(Ref* sender); CREATE_FUNC(Bug914Layer); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-Child.cpp b/tests/cpp-tests/Classes/BugsTest/Bug-Child.cpp index e162fcb632..d77cd6ed0a 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-Child.cpp +++ b/tests/cpp-tests/Classes/BugsTest/Bug-Child.cpp @@ -8,23 +8,9 @@ #include "Bug-Child.h" -Scene* BugChild::scene() -{ - // 'scene' is an autorelease object. - auto scene = Scene::create(); - // 'layer' is an autorelease object. - auto layer = BugChild::create(); - - // add layer as a child to scene - scene->addChild(layer); - - // return the scene - return scene; -} - bool BugChild::init() { - if (BugsTestBaseLayer::init()) + if (BugsTestBase::init()) { auto size = Director::getInstance()->getWinSize(); diff --git a/tests/cpp-tests/Classes/BugsTest/Bug-Child.h b/tests/cpp-tests/Classes/BugsTest/Bug-Child.h index a0a4f9c33e..7bd65a1d54 100644 --- a/tests/cpp-tests/Classes/BugsTest/Bug-Child.h +++ b/tests/cpp-tests/Classes/BugsTest/Bug-Child.h @@ -11,16 +11,15 @@ #include "BugsTest.h" -class BugChild : public BugsTestBaseLayer +class BugChild : public BugsTestBase { public: - static Scene* scene(); + CREATE_FUNC(BugChild); + virtual bool init() override; void switchChild(Ref* sender); - CREATE_FUNC(BugChild); - protected: Sprite* parent1; diff --git a/tests/cpp-tests/Classes/BugsTest/BugsTest.cpp b/tests/cpp-tests/Classes/BugsTest/BugsTest.cpp index a2576b3a08..3012dd1094 100644 --- a/tests/cpp-tests/Classes/BugsTest/BugsTest.cpp +++ b/tests/cpp-tests/Classes/BugsTest/BugsTest.cpp @@ -10,139 +10,16 @@ #include "Bug-1174.h" #include "Bug-Child.h" -#define TEST_BUG(__bug__) \ -{ \ - Scene* scene = Scene::create(); \ - Bug##__bug__##Layer* layer = new (std::nothrow) Bug##__bug__##Layer(); \ - layer->init(); \ - scene->addChild(layer); \ - Director::getInstance()->replaceScene(scene); \ - layer->autorelease(); \ -} - -enum +BugsTests::BugsTests() { - LINE_SPACE = 40, - kItemTagBasic = 5432, -}; - -static Vec2 s_tCurPos = Vec2::ZERO; - -struct { - const char *test_name; - std::function callback; -} g_bugs[] = { - { "Bug-Child", [](Ref* sender){Director::getInstance()->replaceScene(BugChild::scene());} }, - { "Bug-350", [](Ref* sender){ TEST_BUG(350)} }, - { "Bug-422", [](Ref* sender){ TEST_BUG(422)} }, - { "Bug-458", [](Ref* sender){ TEST_BUG(458)} }, - { "Bug-624", [](Ref* sender){ TEST_BUG(624)} }, - { "Bug-886", [](Ref* sender){ TEST_BUG(886)} }, - { "Bug-899", [](Ref* sender){ TEST_BUG(899)} }, - { "Bug-914", [](Ref* sender){ TEST_BUG(914)} }, - { "Bug-1159", [](Ref* sender){ TEST_BUG(1159)} }, - { "Bug-1174", [](Ref* sender){ TEST_BUG(1174)} }, -}; - -static const int g_maxitems = sizeof(g_bugs) / sizeof(g_bugs[0]); - - -//////////////////////////////////////////////////////// -// -// BugsTestMainLayer -// -//////////////////////////////////////////////////////// -void BugsTestMainLayer::onEnter() -{ - Layer::onEnter(); - - auto s = Director::getInstance()->getWinSize(); - _itmeMenu = Menu::create(); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxitems; ++i) - { - auto pItem = MenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback); - pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE); - _itmeMenu->addChild(pItem, kItemTagBasic + i); - } - - _itmeMenu->setPosition(s_tCurPos); - addChild(_itmeMenu); - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(BugsTestMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(BugsTestMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); -} - -void BugsTestMainLayer::onTouchesBegan(const std::vector& touches, Event *event) -{ - _beginPos = touches[0]->getLocation(); -} - -void BugsTestMainLayer::onTouchesMoved(const std::vector& touches, Event *event) -{ - auto touchLocation = touches[0]->getLocation(); - float nMoveY = touchLocation.y - _beginPos.y; - - auto curPos = _itmeMenu->getPosition(); - auto nextPos = Vec2(curPos.x, curPos.y + nMoveY); - auto winSize = Director::getInstance()->getWinSize(); - if (nextPos.y < 0.0f) - { - _itmeMenu->setPosition(Vec2::ZERO); - return; - } - - if (nextPos.y > ((g_maxitems + 1)* LINE_SPACE - winSize.height)) - { - _itmeMenu->setPosition(0, ((g_maxitems + 1)* LINE_SPACE - winSize.height)); - return; - } - - _itmeMenu->setPosition(nextPos); - _beginPos = touchLocation; - s_tCurPos = nextPos; -} - -//////////////////////////////////////////////////////// -// -// BugsTestBaseLayer -// -//////////////////////////////////////////////////////// -void BugsTestBaseLayer::onEnter() -{ - Layer::onEnter(); - - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - auto pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(BugsTestBaseLayer::backCallback, this)); - pMainItem->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25); - auto menu = Menu::create(pMainItem, nullptr); - menu->setPosition( Vec2::ZERO ); - addChild(menu); -} - -void BugsTestBaseLayer::backCallback(Ref* sender) -{ -// Director::getInstance()->enableRetinaDisplay(false); - auto scene = new (std::nothrow) BugsTestScene(); - scene->runThisTest(); - scene->autorelease(); -} - -//////////////////////////////////////////////////////// -// -// BugsTestScene -// -//////////////////////////////////////////////////////// -void BugsTestScene::runThisTest() -{ - auto layer = new (std::nothrow) BugsTestMainLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); + ADD_TEST_CASE(Bug350Layer); + ADD_TEST_CASE(Bug422Layer); + ADD_TEST_CASE(Bug458Layer); + ADD_TEST_CASE(Bug624Layer); + ADD_TEST_CASE(Bug886Layer); + ADD_TEST_CASE(Bug899Layer); + ADD_TEST_CASE(Bug914Layer); + ADD_TEST_CASE(Bug1159Layer); + ADD_TEST_CASE(Bug1174Layer); + ADD_TEST_CASE(BugChild); } diff --git a/tests/cpp-tests/Classes/BugsTest/BugsTest.h b/tests/cpp-tests/Classes/BugsTest/BugsTest.h index b579fa02b3..5e7e8e715f 100644 --- a/tests/cpp-tests/Classes/BugsTest/BugsTest.h +++ b/tests/cpp-tests/Classes/BugsTest/BugsTest.h @@ -1,32 +1,14 @@ #ifndef __BUGS_TEST_H__ #define __BUGS_TEST_H__ -#include "../testBasic.h" +#include "../BaseTest.h" -class BugsTestMainLayer : public Layer +class BugsTestBase : public TestCase { public: - virtual void onEnter() override; - - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector&touches, Event *event) override; - -protected: - Vec2 _beginPos; - Menu* _itmeMenu; + }; -class BugsTestBaseLayer : public Layer -{ -public: - virtual void onEnter() override; - void backCallback(Ref* sender); -}; - -class BugsTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(BugsTests); #endif diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 2ebaa31641..bb127d0ef3 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -32,82 +32,16 @@ enum IDC_RESTART }; -static int sceneIdx = -1; - -static std::function createFunctions[] = +Camera3DTests::Camera3DTests() { - CL(CameraRotationTest), - CL(Camera3DTestDemo), - CL(CameraCullingDemo), + ADD_TEST_CASE(CameraRotationTest); + ADD_TEST_CASE(Camera3DTestDemo); + ADD_TEST_CASE(CameraCullingDemo); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) // 3DEffect use custom shader which is not supported on WP8 yet. - CL(FogTestDemo), + ADD_TEST_CASE(FogTestDemo); #endif - CL(CameraArcBallDemo) -}; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer*nextTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer*backTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartTest() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void Camera3DTestScene::runThisTest() -{ - auto layer = nextTest(); - addChild(layer); - Director::getInstance()->replaceScene(this); -} - -//------------------------------------------------------------------ -// -// CameraBaseTest -// -//------------------------------------------------------------------ - -void CameraBaseTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) Camera3DTestScene(); - s->addChild(restartTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void CameraBaseTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) Camera3DTestScene(); - s->addChild(nextTest()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void CameraBaseTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) Camera3DTestScene(); - s->addChild(backTest()); - Director::getInstance()->replaceScene(s); - s->release(); + ADD_TEST_CASE(CameraArcBallDemo); } //------------------------------------------------------------------ @@ -220,12 +154,12 @@ std::string CameraRotationTest::subtitle() const void CameraRotationTest::onEnter() { - BaseTest::onEnter(); + CameraBaseTest::onEnter(); } void CameraRotationTest::onExit() { - BaseTest::onExit(); + CameraBaseTest::onExit(); } void CameraRotationTest::update(float dt) @@ -319,7 +253,7 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType) } void Camera3DTestDemo::onEnter() { - BaseTest::onEnter(); + CameraBaseTest::onEnter(); _sprite3D=nullptr; auto s = Director::getInstance()->getWinSize(); auto listener = EventListenerTouchAllAtOnce::create(); @@ -432,7 +366,7 @@ void Camera3DTestDemo::onEnter() } void Camera3DTestDemo::onExit() { - BaseTest::onExit(); + CameraBaseTest::onExit(); if (_camera) { _camera = nullptr; @@ -785,16 +719,16 @@ std::string CameraCullingDemo::title() const void CameraCullingDemo::onEnter() { - BaseTest::onEnter(); + CameraBaseTest::onEnter(); schedule(schedule_selector(CameraCullingDemo::update), 0.0f); auto s = Director::getInstance()->getWinSize(); - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(CameraCullingDemo::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(CameraCullingDemo::onTouchesMoved, this); - listener->onTouchesEnded = CC_CALLBACK_2(CameraCullingDemo::onTouchesEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + /*auto listener = EventListenerTouchAllAtOnce::create(); + listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this); + listener->onTouchesMoved = CC_CALLBACK_2(Camera3DTestDemo::onTouchesMoved, this); + listener->onTouchesEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesEnded, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/ auto layer3D=Layer::create(); addChild(layer3D,0); _layer3D=layer3D; @@ -847,7 +781,7 @@ void CameraCullingDemo::onEnter() void CameraCullingDemo::onExit() { - BaseTest::onExit(); + CameraBaseTest::onExit(); if (_cameraFirst) { _cameraFirst = nullptr; @@ -1070,7 +1004,7 @@ std::string CameraArcBallDemo::title() const void CameraArcBallDemo::onEnter() { - BaseTest::onEnter(); + CameraBaseTest::onEnter(); _rotationQuat.set(0.0f, 0.0f, 0.0f, 1.0f); schedule(schedule_selector(CameraArcBallDemo::update), 0.0f); auto s = Director::getInstance()->getWinSize(); @@ -1142,7 +1076,7 @@ void CameraArcBallDemo::onEnter() void CameraArcBallDemo::onExit() { - BaseTest::onExit(); + CameraBaseTest::onExit(); if (_camera) { _camera = nullptr; @@ -1287,7 +1221,7 @@ std::string FogTestDemo::title() const void FogTestDemo::onEnter() { - BaseTest::onEnter(); + CameraBaseTest::onEnter(); schedule(schedule_selector(FogTestDemo::update), 0.0f); Director::getInstance()->setClearColor(Color4F(0.5,0.5,0.5,1)); @@ -1437,7 +1371,7 @@ void FogTestDemo::switchTypeCallback(Ref* sender,int type) void FogTestDemo::onExit() { - BaseTest::onExit(); + CameraBaseTest::onExit(); Director::getInstance()->setClearColor(Color4F(0,0,0,1)); if (_camera) { diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h index a63394757a..f6f42334e6 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef _CAMERA3D_TEST_H_ #define _CAMERA3D_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" #include "../Sprite3DTest/DrawNode3D.h" #include @@ -59,18 +58,11 @@ enum class OperateCamType RotateCamera=1, }; -class Camera3DTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(Camera3DTests); -class CameraBaseTest : public BaseTest +class CameraBaseTest : public TestCase { public: - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; protected: BillBoard* bill1; @@ -114,9 +106,11 @@ public: // overrides virtual std::string title() const override; void addNewSpriteWithCoords(Vec3 p,std::string fileName,bool playAnimation=false,float scale=1.0f,bool bindCamera=false); - void onTouchesBegan(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesMoved(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesEnded(const std::vector& touches, cocos2d::Event *event) override; + + void onTouchesBegan(const std::vector& touches, cocos2d::Event *event); + void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); + void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); + void scaleCameraCallback(Ref* sender,float value); void rotateCameraCallback(Ref* sender,float value); void SwitchViewCallback(Ref* sender,CameraType cameraType); @@ -243,7 +237,7 @@ public: // overrides virtual std::string title() const override; - void onTouchesMoved(const std::vector& touches, cocos2d::Event *event) override; + void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); void switchTypeCallback(Ref* sender,int type); diff --git a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.cpp b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.cpp index 4a2cef2ec5..42c21cb2f4 100644 --- a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.cpp +++ b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.cpp @@ -17,17 +17,17 @@ enum { // callback to remove Shapes from the Space -ChipmunkTestLayer::ChipmunkTestLayer() +ChipmunkTest::ChipmunkTest() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // enable events auto touchListener = EventListenerTouchAllAtOnce::create(); - touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this); + touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTest::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); Device::setAccelerometerEnabled(true); - auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this)); + auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTest::onAcceleration, this)); _eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this); // title @@ -56,7 +56,7 @@ ChipmunkTestLayer::ChipmunkTestLayer() // menu for debug layer MenuItemFont::setFontSize(18); - auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this)); + auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTest::toggleDebugCallback, this)); auto menu = Menu::create(item, nullptr); this->addChild(menu); @@ -76,14 +76,14 @@ ChipmunkTestLayer::ChipmunkTestLayer() } -void ChipmunkTestLayer::toggleDebugCallback(Ref* sender) +void ChipmunkTest::toggleDebugCallback(Ref* sender) { #if CC_ENABLE_CHIPMUNK_INTEGRATION _debugLayer->setVisible(! _debugLayer->isVisible()); #endif } -ChipmunkTestLayer::~ChipmunkTestLayer() +ChipmunkTest::~ChipmunkTest() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // manually Free rogue shapes @@ -97,7 +97,7 @@ ChipmunkTestLayer::~ChipmunkTestLayer() #endif } -void ChipmunkTestLayer::initPhysics() +void ChipmunkTest::initPhysics() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // init chipmunk @@ -143,7 +143,7 @@ void ChipmunkTestLayer::initPhysics() #endif } -void ChipmunkTestLayer::update(float delta) +void ChipmunkTest::update(float delta) { // Should use a fixed size step based on the animation interval. int steps = 2; @@ -154,9 +154,9 @@ void ChipmunkTestLayer::update(float delta) } } -void ChipmunkTestLayer::createResetButton() +void ChipmunkTest::createResetButton() { - auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ChipmunkTestLayer::reset, this)); + auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ChipmunkTest::reset, this)); auto menu = Menu::create(reset, nullptr); @@ -164,17 +164,12 @@ void ChipmunkTestLayer::createResetButton() this->addChild(menu, -1); } -void ChipmunkTestLayer::reset(Ref* sender) +void ChipmunkTest::reset(Ref* sender) { - auto s = new (std::nothrow) ChipmunkAccelTouchTestScene(); - auto child = new (std::nothrow) ChipmunkTestLayer(); - s->addChild(child); - child->release(); - Director::getInstance()->replaceScene(s); - s->release(); + getTestSuite()->restartCurrTest(); } -void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Vec2 pos) +void ChipmunkTest::addNewSpriteAtPosition(cocos2d::Vec2 pos) { #if CC_ENABLE_CHIPMUNK_INTEGRATION int posx, posy; @@ -213,12 +208,12 @@ void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Vec2 pos) #endif } -void ChipmunkTestLayer::onEnter() +void ChipmunkTest::onEnter() { - Layer::onEnter(); + TestCase::onEnter(); } -void ChipmunkTestLayer::onTouchesEnded(const std::vector& touches, Event* event) +void ChipmunkTest::onTouchesEnded(const std::vector& touches, Event* event) { //Add a new body/atlas sprite at the touched location @@ -230,7 +225,7 @@ void ChipmunkTestLayer::onTouchesEnded(const std::vector& touches, Event } } -void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event) +void ChipmunkTest::onAcceleration(Acceleration* acc, Event* event) { static float prevX=0, prevY=0; @@ -247,12 +242,8 @@ void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event) _space->gravity = cpv(v.x, v.y); } -void ChipmunkAccelTouchTestScene::runThisTest() +ChipmunkTests::ChipmunkTests() { - auto layer = new (std::nothrow) ChipmunkTestLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); + ADD_TEST_CASE(ChipmunkTest); } diff --git a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h index 4ba87a0a45..db358b0c30 100644 --- a/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h +++ b/tests/cpp-tests/Classes/ChipmunkTest/ChipmunkTest.h @@ -6,16 +6,18 @@ #include "cocos2d.h" #include "chipmunk.h" -#include "../testBasic.h" +#include "../BaseTest.h" #include "extensions/cocos-ext.h" USING_NS_CC_EXT; -class ChipmunkTestLayer : public Layer +class ChipmunkTest : public TestCase { public: - ChipmunkTestLayer(); - ~ChipmunkTestLayer(); + CREATE_FUNC(ChipmunkTest); + + ChipmunkTest(); + ~ChipmunkTest(); void onEnter() override; void initPhysics(); void createResetButton(); @@ -24,8 +26,8 @@ public: void addNewSpriteAtPosition(cocos2d::Vec2 p); void update(float dt) override; void toggleDebugCallback(Ref* sender); - void onTouchesEnded(const std::vector& touches, Event* event) override; - virtual void onAcceleration(Acceleration* acc, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); + virtual void onAcceleration(Acceleration* acc, Event* event); private: Texture2D* _spriteTexture; // weak ref @@ -36,10 +38,6 @@ private: cpShape* _walls[4]; }; -class ChipmunkAccelTouchTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(ChipmunkTests); #endif /* __CHIPMUNKACCELTOUCHTEST_H__ */ diff --git a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp index 2187b5a0d1..6f847773b9 100644 --- a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp +++ b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.cpp @@ -6,20 +6,16 @@ enum kTagSprite = 1, }; -void ClickAndMoveTestScene::runThisTest() +ClickAndMoveTest::ClickAndMoveTest() { - auto layer = new (std::nothrow) MainLayer(); - layer->autorelease(); - - addChild(layer); - Director::getInstance()->replaceScene(this); + ADD_TEST_CASE(ClickAndMoveTestCase); } -MainLayer::MainLayer() +ClickAndMoveTestCase::ClickAndMoveTestCase() { auto listener = EventListenerTouchOneByOne::create(); - listener->onTouchBegan = CC_CALLBACK_2(MainLayer::onTouchBegan, this); - listener->onTouchEnded = CC_CALLBACK_2(MainLayer::onTouchEnded, this); + listener->onTouchBegan = CC_CALLBACK_2(ClickAndMoveTestCase::onTouchBegan, this); + listener->onTouchEnded = CC_CALLBACK_2(ClickAndMoveTestCase::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); auto sprite = Sprite::create(s_pathGrossini); @@ -40,12 +36,12 @@ MainLayer::MainLayer() )); } -bool MainLayer::onTouchBegan(Touch* touch, Event *event) +bool ClickAndMoveTestCase::onTouchBegan(Touch* touch, Event *event) { return true; } -void MainLayer::onTouchEnded(Touch* touch, Event *event) +void ClickAndMoveTestCase::onTouchEnded(Touch* touch, Event *event) { auto location = touch->getLocation(); diff --git a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.h b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.h index 833ced291e..dc7db15cd5 100644 --- a/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.h +++ b/tests/cpp-tests/Classes/ClickAndMoveTest/ClickAndMoveTest.h @@ -1,18 +1,16 @@ #ifndef _CLICK_AND_MOVE_TEST_H_ #define _CLICK_AND_MOVE_TEST_H_ -#include "../testBasic.h" +#include "../BaseTest.h" -class ClickAndMoveTestScene : public TestScene +DEFINE_TEST_SUITE(ClickAndMoveTest); + +class ClickAndMoveTestCase : public TestCase { public: - virtual void runThisTest(); -}; + CREATE_FUNC(ClickAndMoveTestCase); -class MainLayer : public Layer -{ -public: - MainLayer(); + ClickAndMoveTestCase(); bool onTouchBegan(Touch* touch, Event *event); void onTouchEnded(Touch* touch, Event *event); }; diff --git a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp index d8335d1d05..5913336b07 100644 --- a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -17,64 +17,33 @@ enum { kTagContentNode = 102, }; -static std::function createFunctions[] = { - CL(ScrollViewDemo), - CL(HoleDemo), - CL(ShapeTest), - CL(ShapeInvertedTest), - CL(SpriteTest), - CL(SpriteNoAlphaTest), - CL(SpriteInvertedTest), - CL(NestedTest), - CL(RawStencilBufferTest), - CL(RawStencilBufferTest2), - CL(RawStencilBufferTest3), - CL(RawStencilBufferTest4), - CL(RawStencilBufferTest5), - CL(RawStencilBufferTest6), - CL(ClippingToRenderTextureTest), - CL(ClippingRectangleNodeTest), -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() +ClippingNodeTests::ClippingNodeTests() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - - return layer; + ADD_TEST_CASE(ScrollViewDemo); + ADD_TEST_CASE(HoleDemo); + ADD_TEST_CASE(ShapeTest); + ADD_TEST_CASE(ShapeInvertedTest); + ADD_TEST_CASE(SpriteTest); + ADD_TEST_CASE(SpriteNoAlphaTest); + ADD_TEST_CASE(SpriteInvertedTest); + ADD_TEST_CASE(NestedTest); + ADD_TEST_CASE(RawStencilBufferTest); + ADD_TEST_CASE(RawStencilBufferTest2); + ADD_TEST_CASE(RawStencilBufferTest3); + ADD_TEST_CASE(RawStencilBufferTest4); + ADD_TEST_CASE(RawStencilBufferTest5); + ADD_TEST_CASE(RawStencilBufferTest6); + ADD_TEST_CASE(ClippingToRenderTextureTest); + ADD_TEST_CASE(ClippingRectangleNodeTest); } -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - - return layer; -} - //// Demo examples start here //@implementation BaseClippingNodeTest bool BaseClippingNodeTest::init() { - if (BaseTest::init()) { + if (TestCase::init()) { auto background = Sprite::create(s_back3); background->setAnchorPoint( Vec2::ZERO ); @@ -97,35 +66,6 @@ std::string BaseClippingNodeTest::title() const return "Clipping Demo"; } -std::string BaseClippingNodeTest::subtitle() const -{ - return ""; -} - -void BaseClippingNodeTest::restartCallback(Ref* sender) -{ - Scene *s = new (std::nothrow) ClippingNodeTestScene(); - s->addChild(restartAction()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseClippingNodeTest::nextCallback(Ref* sender) -{ - Scene *s = new (std::nothrow) ClippingNodeTestScene(); - s->addChild(nextAction()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseClippingNodeTest::backCallback(Ref* sender) -{ - Scene *s = new (std::nothrow) ClippingNodeTestScene(); - s->addChild(backAction()); - Director::getInstance()->replaceScene(s); - s->release(); -} - void BaseClippingNodeTest::setup() { @@ -1128,13 +1068,3 @@ void ClippingRectangleNodeTest::setup() content->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2); clipper->addChild(content); } - - -// main entry point - -void ClippingNodeTestScene::runThisTest() -{ - auto layer = nextAction(); - addChild(layer); - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.h b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.h index 0211e84d21..14080e39f8 100644 --- a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.h +++ b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.h @@ -1,12 +1,13 @@ #ifndef __CLIPPINGNODETEST_H__ #define __CLIPPINGNODETEST_H__ -#include "../testBasic.h" #include "../BaseTest.h" #include "renderer/CCCustomCommand.h" #include -class BaseClippingNodeTest : public BaseTest +DEFINE_TEST_SUITE(ClippingNodeTests); + +class BaseClippingNodeTest : public TestCase { public: CREATE_FUNC(BaseClippingNodeTest); @@ -15,12 +16,7 @@ public: virtual bool init() override; virtual std::string title() const override; - virtual std::string subtitle() const override; virtual void setup(); - - void backCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void restartCallback(Ref* sender) override; }; class BasicTest : public BaseClippingNodeTest @@ -118,7 +114,7 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; void pokeHoleAtPoint(Vec2 point); - void onTouchesBegan(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); private: ClippingNode* _outerClipper; Node* _holes; @@ -133,9 +129,9 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; virtual void setup() override; - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); private: bool _scrolling; Vec2 _lastPoint; @@ -254,13 +250,4 @@ public: virtual void setup() override; }; - -class ClippingNodeTestScene : public TestScene -{ -public: - CREATE_FUNC(ClippingNodeTestScene); - - virtual void runThisTest(); -}; - #endif //__CLIPPINGNODETEST_H__ diff --git a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp index c139d0c917..74dae4179e 100644 --- a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp +++ b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp @@ -1,6 +1,7 @@ #include "CocosDenshionTest.h" #include "cocos2d.h" #include "extensions/GUI/CCControlExtension/CCControlSlider.h" +#include "audio/include/SimpleAudioEngine.h" // android effect only support ogg #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) @@ -248,7 +249,7 @@ CocosDenshionTest::~CocosDenshionTest() void CocosDenshionTest::onExit() { - Layer::onExit(); + TestCase::onExit(); SimpleAudioEngine::end(); } @@ -416,11 +417,7 @@ void CocosDenshionTest::updateVolumes(float) } } -void CocosDenshionTestScene::runThisTest() +CocosDenshionTests::CocosDenshionTests() { - auto layer = new (std::nothrow) CocosDenshionTest(); - addChild(layer); - layer->autorelease(); - - Director::getInstance()->replaceScene(this); -} + ADD_TEST_CASE(CocosDenshionTest); +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.h b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.h index 4c608a4240..af970c724e 100644 --- a/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.h +++ b/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.h @@ -1,13 +1,17 @@ #ifndef __COCOS_DENSHION_TEST__ #define __COCOS_DENSHION_TEST__ -#include "../testBasic.h" +#include "../BaseTest.h" class AudioSlider; -class CocosDenshionTest : public Layer +DEFINE_TEST_SUITE(CocosDenshionTests); + +class CocosDenshionTest : public TestCase { public: + CREATE_FUNC(CocosDenshionTest); + CocosDenshionTest(void); ~CocosDenshionTest(void); @@ -30,10 +34,4 @@ private: AudioSlider *_sliderMusicVolume; }; -class CocosDenshionTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif //__COCOS_DENSHION_TEST__ diff --git a/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.cpp b/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.cpp index a0da56794f..438bba67ad 100644 --- a/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.cpp +++ b/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.cpp @@ -33,43 +33,12 @@ enum IDC_RESTART }; -static int sceneIdx = -1; - - -static std::function createFunctions[] = +CocosStudio3DTests::CocosStudio3DTests() { - CL(CSNode3DTest), - CL(CSSprite3DTest), - CL(CSUserCameraTest), - CL(CSParticle3DTest) -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextCocosStudio3DTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backCocosStudio3DTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartCocosStudio3DTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(CSNode3DTest); + ADD_TEST_CASE(CSSprite3DTest); + ADD_TEST_CASE(CSUserCameraTest); + ADD_TEST_CASE(CSParticle3DTest); } //------------------------------------------------------------------ @@ -79,7 +48,6 @@ static Layer* restartCocosStudio3DTestAction() //------------------------------------------------------------------ CocosStudio3DTestDemo::CocosStudio3DTestDemo(void) -: BaseTest() { } @@ -92,46 +60,10 @@ std::string CocosStudio3DTestDemo::title() const return "No title"; } -std::string CocosStudio3DTestDemo::subtitle() const -{ - return ""; -} - -void CocosStudio3DTestDemo::onEnter() -{ - BaseTest::onEnter(); -} - void CocosStudio3DTestDemo::onExit() { cocostudio::destroyCocosStudio(); - - BaseTest::onExit(); -} - -void CocosStudio3DTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) CS3DTestScene(); - s->addChild(restartCocosStudio3DTestAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void CocosStudio3DTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) CS3DTestScene(); - s->addChild( nextCocosStudio3DTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void CocosStudio3DTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) CS3DTestScene(); - s->addChild( backCocosStudio3DTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); + TestCase::onExit(); } //------------------------------------------------------------------ @@ -151,11 +83,6 @@ std::string CSNode3DTest::title() const return "Node3DReader Test"; } -std::string CSNode3DTest::subtitle() const -{ - return ""; -} - //------------------------------------------------------------------ // // CSSprite3DTest @@ -180,11 +107,6 @@ std::string CSSprite3DTest::title() const return "Sprite3DReader Test"; } -std::string CSSprite3DTest::subtitle() const -{ - return ""; -} - //------------------------------------------------------------------ // // CSUserCameraTest @@ -207,11 +129,6 @@ std::string CSUserCameraTest::title() const return "UserCameraReader Test"; } -std::string CSUserCameraTest::subtitle() const -{ - return ""; -} - //------------------------------------------------------------------ // // CSParticle3DTest @@ -228,27 +145,3 @@ std::string CSParticle3DTest::title() const { return "Particle3DReader Test"; } - -std::string CSParticle3DTest::subtitle() const -{ - return ""; -} - - -//------------------------------------------------------------------ -// -// CS3DTestScene -// -//------------------------------------------------------------------ -void CS3DTestScene::runThisTest() -{ - auto layer = nextCocosStudio3DTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -CS3DTestScene::CS3DTestScene() -{ - -} diff --git a/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.h b/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.h index 0a4597ed38..1ce606a6cc 100644 --- a/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.h +++ b/tests/cpp-tests/Classes/CocosStudio3DTest/CocosStudio3DTest.h @@ -29,24 +29,16 @@ #include "../BaseTest.h" #include -namespace cocos2d { +DEFINE_TEST_SUITE(CocosStudio3DTests); -} - -class CocosStudio3DTestDemo : public BaseTest +class CocosStudio3DTestDemo : public TestCase { public: CocosStudio3DTestDemo(void); virtual ~CocosStudio3DTestDemo(void); - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - // overrides virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; virtual void onExit() override; }; @@ -56,7 +48,6 @@ public: CREATE_FUNC(CSNode3DTest); CSNode3DTest(); virtual std::string title() const override; - virtual std::string subtitle() const override; }; class CSSprite3DTest : public CocosStudio3DTestDemo @@ -65,7 +56,6 @@ public: CREATE_FUNC(CSSprite3DTest); CSSprite3DTest(); virtual std::string title() const override; - virtual std::string subtitle() const override; }; class CSUserCameraTest : public CocosStudio3DTestDemo @@ -74,7 +64,6 @@ public: CREATE_FUNC(CSUserCameraTest); CSUserCameraTest(); virtual std::string title() const override; - virtual std::string subtitle() const override; }; class CSParticle3DTest : public CocosStudio3DTestDemo @@ -83,15 +72,7 @@ public: CREATE_FUNC(CSParticle3DTest); CSParticle3DTest(); virtual std::string title() const override; - virtual std::string subtitle() const override; }; -class CS3DTestScene : public TestScene -{ -public: - CS3DTestScene(); - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.cpp b/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.cpp index 48cf4b3d11..03d36803e9 100644 --- a/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.cpp +++ b/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.cpp @@ -3,96 +3,20 @@ #include "../testResource.h" #include "cocos2d.h" -static std::function createFunctions[] = { - CL(ConfigurationLoadConfig), - CL(ConfigurationQuery), - CL(ConfigurationInvalid), - CL(ConfigurationDefault), - CL(ConfigurationSet) -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() +ConfigurationTests::ConfigurationTests() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(ConfigurationLoadConfig); + ADD_TEST_CASE(ConfigurationQuery); + ADD_TEST_CASE(ConfigurationInvalid); + ADD_TEST_CASE(ConfigurationDefault); + ADD_TEST_CASE(ConfigurationSet); } -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void ConfigurationTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(nextAction()); - - Director::getInstance()->replaceScene(this); -} - - std::string ConfigurationBase::title() const { return "Configuration Test"; } -std::string ConfigurationBase::subtitle() const -{ - return ""; -} - -void ConfigurationBase::onEnter() -{ - BaseTest::onEnter(); -} - -void ConfigurationBase::onExit() -{ - BaseTest::onExit(); -} - -void ConfigurationBase::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConfigurationTestScene(); - s->addChild( restartAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ConfigurationBase::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConfigurationTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ConfigurationBase::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConfigurationTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - //------------------------------------------------------------------ // // ConfigurationLoadConfig diff --git a/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.h b/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.h index 852b32d797..a3c15fdbbc 100644 --- a/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.h +++ b/tests/cpp-tests/Classes/ConfigurationTest/ConfigurationTest.h @@ -6,30 +6,14 @@ USING_NS_CC; +DEFINE_TEST_SUITE(ConfigurationTests); -// the class inherit from TestScene -// every Scene each test used must inherit from TestScene, -// make sure the test have the menu item for back to main menu -class ConfigurationTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -class ConfigurationBase : public BaseTest +class ConfigurationBase : public TestCase { protected: public: - virtual void onEnter() override; - virtual void onExit() override; - virtual std::string title() const override; - virtual std::string subtitle() const override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class ConfigurationLoadConfig : public ConfigurationBase diff --git a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp index 347f4bf9e6..0bfa248d30 100644 --- a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp +++ b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.cpp @@ -47,43 +47,12 @@ // //------------------------------------------------------------------ -static int sceneIdx = -1; - -static std::function createFunctions[] = +ConsoleTests::ConsoleTests() { - CL(ConsoleCustomCommand), - CL(ConsoleUploadFile), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextConsoleTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(ConsoleCustomCommand); + ADD_TEST_CASE(ConsoleUploadFile); } -Layer* backConsoleTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartConsoleTest() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - - BaseTestConsole::BaseTestConsole() { } @@ -97,44 +66,6 @@ std::string BaseTestConsole::title() const return "No title"; } -void BaseTestConsole::onEnter() -{ - BaseTest::onEnter(); -} - -void BaseTestConsole::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConsoleTestScene(); - s->addChild(restartConsoleTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseTestConsole::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConsoleTestScene(); - s->addChild( nextConsoleTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseTestConsole::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ConsoleTestScene(); - s->addChild( backConsoleTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ConsoleTestScene::runThisTest() -{ - auto layer = nextConsoleTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - //------------------------------------------------------------------ // // ConsoleCustomCommand diff --git a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.h b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.h index 75bf0e2cfe..eb8f5f607c 100644 --- a/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.h +++ b/tests/cpp-tests/Classes/ConsoleTest/ConsoleTest.h @@ -25,24 +25,19 @@ #ifndef _CONSOLE_TEST_H_ #define _CONSOLE_TEST_H_ -////----#include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" USING_NS_CC; -class BaseTestConsole : public BaseTest +DEFINE_TEST_SUITE(ConsoleTests); + +class BaseTestConsole : public TestCase { public: BaseTestConsole(); ~BaseTestConsole(); virtual std::string title() const override; - virtual void onEnter() override; - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; }; @@ -85,10 +80,4 @@ private: CC_DISALLOW_COPY_AND_ASSIGN(ConsoleUploadFile); }; -class ConsoleTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _CONSOLE_TEST_H_ diff --git a/tests/cpp-tests/Classes/CurlTest/CurlTest.cpp b/tests/cpp-tests/Classes/CurlTest/CurlTest.cpp index 3b21ad24ff..feffc5e32d 100644 --- a/tests/cpp-tests/Classes/CurlTest/CurlTest.cpp +++ b/tests/cpp-tests/Classes/CurlTest/CurlTest.cpp @@ -3,6 +3,11 @@ #include "stdlib.h" #include "curl/curl.h" +CurlTests::CurlTests() +{ + ADD_TEST_CASE(CurlTest); +} + CurlTest::CurlTest() { auto label = Label::createWithTTF("Curl Test", "fonts/arial.ttf", 28); @@ -93,12 +98,3 @@ CurlTest::~CurlTest() { _label->release(); } - -void CurlTestScene::runThisTest() -{ - auto layer = new (std::nothrow) CurlTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/CurlTest/CurlTest.h b/tests/cpp-tests/Classes/CurlTest/CurlTest.h index 51875dd011..7a2dd63b4e 100644 --- a/tests/cpp-tests/Classes/CurlTest/CurlTest.h +++ b/tests/cpp-tests/Classes/CurlTest/CurlTest.h @@ -2,24 +2,22 @@ #define _CURL_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class CurlTest : public Layer +DEFINE_TEST_SUITE(CurlTests); + +class CurlTest : public TestCase { public: + CREATE_FUNC(CurlTest); + CurlTest(); ~CurlTest(); void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); private: - cocos2d::Label* _label; -}; - -class CurlTestScene : public TestScene -{ -public: - virtual void runThisTest(); + cocos2d::Label* _label; }; #endif // _CURL_TEST_H_ diff --git a/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.cpp b/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.cpp index cd27bef5c7..92256730bf 100644 --- a/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.cpp +++ b/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.cpp @@ -1,5 +1,10 @@ #include "CurrentLanguageTest.h" +CurrentLanguageTests::CurrentLanguageTests() +{ + ADD_TEST_CASE(CurrentLanguageTest); +} + CurrentLanguageTest::CurrentLanguageTest() { auto label = Label::createWithTTF("Current language Test", "fonts/arial.ttf", 28); @@ -73,11 +78,3 @@ CurrentLanguageTest::CurrentLanguageTest() addChild(labelLanguageCode); } -void CurrentLanguageTestScene::runThisTest() -{ - auto layer = new (std::nothrow) CurrentLanguageTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.h b/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.h index 2ec47500c6..8b8a85a38e 100644 --- a/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.h +++ b/tests/cpp-tests/Classes/CurrentLanguageTest/CurrentLanguageTest.h @@ -2,18 +2,16 @@ #define _CURRENT_LANGUAGE_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class CurrentLanguageTest : public Layer +DEFINE_TEST_SUITE(CurrentLanguageTests); + +class CurrentLanguageTest : public TestCase { public: + CREATE_FUNC(CurrentLanguageTest); + CurrentLanguageTest(); }; -class CurrentLanguageTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _CURRENT_LANGUAGE_TEST_H_ diff --git a/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.cpp b/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.cpp index 733513be0c..c0913a6acb 100644 --- a/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.cpp +++ b/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.cpp @@ -1,6 +1,10 @@ #include "DataVisitorTest.h" #include "../testResource.h" +DataVisitorTests::DataVisitorTests() +{ + ADD_TEST_CASE(PrettyPrinterDemo); +} std::string PrettyPrinterDemo::title() const { return "PrettyPrinter Test"; @@ -36,7 +40,7 @@ void PrettyPrinterDemo::addSprite() void PrettyPrinterDemo::onEnter() { - Layer::onEnter(); + TestCase::onEnter(); auto s = Director::getInstance()->getWinSize(); auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 28); @@ -75,12 +79,3 @@ void PrettyPrinterDemo::onEnter() // dict->acceptVisitor(vistor); // log("%s", vistor.getResult().c_str()); } - -void DataVisitorTestScene::runThisTest() -{ - auto layer = new (std::nothrow) PrettyPrinterDemo(); - layer->autorelease(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.h b/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.h index 27eb52d9ce..a1ed575cd2 100644 --- a/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.h +++ b/tests/cpp-tests/Classes/DataVisitorTest/DataVisitorTest.h @@ -1,13 +1,16 @@ #ifndef __DATAVISITOR_TEST_H__ #define __DATAVISITOR_TEST_H__ -#include "../testBasic.h" +#include "../BaseTest.h" #include -class PrettyPrinterDemo : public Layer +DEFINE_TEST_SUITE(DataVisitorTests); + +class PrettyPrinterDemo : public TestCase { public: + CREATE_FUNC(PrettyPrinterDemo); virtual std::string title() const; virtual std::string subtitle() const; virtual void onEnter() override; @@ -16,12 +19,5 @@ protected: std::string _title; }; -class DataVisitorTestScene : public TestScene -{ -public: - virtual void runThisTest(); - - CREATE_FUNC(DataVisitorTestScene); -}; #endif // __DATAVISITOR_TEST_H__ diff --git a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index 4d86468293..4c40fed336 100644 --- a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -11,110 +11,17 @@ using namespace std; -static int sceneIdx = -1; - - -Layer* nextSpriteTestAction(); -Layer* backSpriteTestAction(); -Layer* restartSpriteTestAction(); - -typedef Layer* (*NEWDRAWPRIMITIVESFUNC)(); -#define DRAWPRIMITIVES_CREATE_FUNC(className) \ -static Layer* create##className() \ -{ return new className(); } - -DRAWPRIMITIVES_CREATE_FUNC(DrawPrimitivesTest); -DRAWPRIMITIVES_CREATE_FUNC(DrawNodeTest); - -static NEWDRAWPRIMITIVESFUNC createFunctions[] = +DrawPrimitivesTests::DrawPrimitivesTests() { - createDrawPrimitivesTest, - createDrawNodeTest, -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - - return layer; + ADD_TEST_CASE(DrawPrimitivesTest); + ADD_TEST_CASE(DrawNodeTest); } -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - - return layer; -} - -// BaseLayer - -BaseLayer::BaseLayer() -{ - -} - -void BaseLayer::onEnter() -{ - BaseTest::onEnter(); -} - -void BaseLayer::restartCallback(cocos2d::Ref *pSender) -{ - auto s = new (std::nothrow) DrawPrimitivesTestScene(); - s->addChild(restartAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseLayer::nextCallback(cocos2d::Ref *pSender) -{ - auto s = new (std::nothrow) DrawPrimitivesTestScene();; - s->addChild(nextAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseLayer::backCallback(cocos2d::Ref *pSender) -{ - auto s = new (std::nothrow) DrawPrimitivesTestScene(); - s->addChild(backAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -string BaseLayer::title() const +string DrawPrimitivesBaseTest::title() const { return "No title"; } -string BaseLayer::subtitle() const -{ - return ""; -} - // DrawPrimitivesTest DrawPrimitivesTest::DrawPrimitivesTest() @@ -393,14 +300,6 @@ string DrawNodeTest::subtitle() const return "Testing DrawNode - batched draws. Concave polygons are BROKEN"; } -void DrawPrimitivesTestScene::runThisTest() -{ - auto layer = nextAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #pragma GCC diagnostic warning "-Wdeprecated-declarations" #elif _MSC_VER >= 1400 //vs 2005 or higher diff --git a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h index ee18b11be3..3756529aec 100644 --- a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h +++ b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h @@ -2,27 +2,22 @@ #define _DRAW_PRIMITIVES_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #include -class BaseLayer : public BaseTest +DEFINE_TEST_SUITE(DrawPrimitivesTests); + +class DrawPrimitivesBaseTest : public TestCase { public: - BaseLayer(); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; }; -class DrawPrimitivesTest : public BaseLayer +class DrawPrimitivesTest : public DrawPrimitivesBaseTest { public: + CREATE_FUNC(DrawPrimitivesTest); DrawPrimitivesTest(); virtual std::string title() const override; @@ -34,19 +29,15 @@ protected: CustomCommand _customCommand; }; -class DrawNodeTest : public BaseLayer +class DrawNodeTest : public DrawPrimitivesBaseTest { public: + CREATE_FUNC(DrawNodeTest); + DrawNodeTest(); virtual std::string title() const override; virtual std::string subtitle() const override; }; -class DrawPrimitivesTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp index 82bcd8275a..7b69304f52 100644 --- a/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -11,6 +11,16 @@ enum kTagLabel = 2, }; +EffectAdvanceTests::EffectAdvanceTests() +{ + ADD_TEST_CASE(Effect3); + ADD_TEST_CASE(Effect2); + ADD_TEST_CASE(Effect1); + ADD_TEST_CASE(Effect4); + ADD_TEST_CASE(Effect5); + ADD_TEST_CASE(Issue631); +} + //------------------------------------------------------------------ // // Effect1 @@ -18,7 +28,7 @@ enum //------------------------------------------------------------------ void Effect1::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); //auto target = getChildByTag(kTagBackground); @@ -53,7 +63,7 @@ std::string Effect1::title() const //------------------------------------------------------------------ void Effect2::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); //auto target = getChildByTag(kTagBackground); @@ -95,7 +105,7 @@ std::string Effect2::title() const //------------------------------------------------------------------ void Effect3::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); //auto bg = getChildByTag(kTagBackground); //auto target1 = bg->getChildByTag(kTagSprite1); //auto target2 = bg->getChildByTag(kTagSprite2); @@ -153,7 +163,7 @@ private: void Effect4::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); //Node* gridNode = NodeGrid::create(); auto lens = Lens3D::create(10, Size(32,24), Vec2(100,180), 150); @@ -189,7 +199,7 @@ std::string Effect4::title() const //------------------------------------------------------------------ void Effect5::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); //CCDirector::getInstance()->setProjection(DirectorProjection2D); @@ -214,7 +224,7 @@ std::string Effect5::title() const void Effect5::onExit() { - EffectAdvanceTextLayer::onExit(); + EffectAdvanceBaseTest::onExit(); Director::getInstance()->setProjection(Director::Projection::_3D); } @@ -226,7 +236,7 @@ void Effect5::onExit() //------------------------------------------------------------------ void Issue631::onEnter() { - EffectAdvanceTextLayer::onEnter(); + EffectAdvanceBaseTest::onEnter(); auto effect = Sequence::create( DelayTime::create(2.0f), Shaky3D::create(5.0f, Size(5, 5), 16, false), nullptr); @@ -267,76 +277,13 @@ std::string Issue631::subtitle() const //------------------------------------------------------------------ // -// EffectAdvanceTextLayer +// EffectAdvanceBaseTest // //------------------------------------------------------------------ -enum +void EffectAdvanceBaseTest::onEnter(void) { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; - -#define MAX_LAYER 6 - -Layer* nextEffectAdvanceAction(); -Layer* backEffectAdvanceAction(); -Layer* restartEffectAdvanceAction(); - -Layer* createEffectAdvanceLayer(int nIndex) -{ - switch(nIndex) - { - case 0: return new Effect3(); - case 1: return new Effect2(); - case 2: return new Effect1(); - case 3: return new Effect4(); - case 4: return new Effect5(); - case 5: return new Issue631(); - } - - return nullptr; -} - -Layer* nextEffectAdvanceAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createEffectAdvanceLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backEffectAdvanceAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createEffectAdvanceLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartEffectAdvanceAction() -{ - auto layer = createEffectAdvanceLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - - -void EffectAdvanceTextLayer::onEnter(void) -{ - BaseTest::onEnter(); + TestCase::onEnter(); _bgNode = NodeGrid::create(); _bgNode->setAnchorPoint(Vec2(0.5,0.5)); @@ -371,50 +318,16 @@ void EffectAdvanceTextLayer::onEnter(void) } -EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void) +EffectAdvanceBaseTest::~EffectAdvanceBaseTest(void) { } -std::string EffectAdvanceTextLayer::title() const +std::string EffectAdvanceBaseTest::title() const { return "No title"; } -std::string EffectAdvanceTextLayer::subtitle() const +std::string EffectAdvanceBaseTest::subtitle() const { return ""; } - -void EffectAdvanceTextLayer::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) EffectAdvanceScene(); - s->addChild(restartEffectAdvanceAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void EffectAdvanceTextLayer::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) EffectAdvanceScene(); - s->addChild( nextEffectAdvanceAction() ); - Director::getInstance()->replaceScene(s); - - s->release(); -} - -void EffectAdvanceTextLayer::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) EffectAdvanceScene(); - s->addChild( backEffectAdvanceAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void EffectAdvanceScene::runThisTest() -{ - auto layer = nextEffectAdvanceAction(); - - addChild(layer); - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h b/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h index 5d6cc437b9..c287f08da0 100644 --- a/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h +++ b/tests/cpp-tests/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -2,10 +2,11 @@ #define _EFFECT_ADVANCED_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class EffectAdvanceTextLayer: public BaseTest +DEFINE_TEST_SUITE(EffectAdvanceTests); + +class EffectAdvanceBaseTest: public TestCase { protected: TextureAtlas* _atlas; @@ -18,64 +19,60 @@ protected: public: virtual void onEnter() override; - ~EffectAdvanceTextLayer(void); + ~EffectAdvanceBaseTest(void); virtual std::string title() const override; virtual std::string subtitle() const override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; -class Effect1 : public EffectAdvanceTextLayer +class Effect1 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Effect1); virtual void onEnter() override; virtual std::string title() const override; }; -class Effect2 : public EffectAdvanceTextLayer +class Effect2 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Effect2); virtual void onEnter() override; virtual std::string title() const override; }; -class Effect3 : public EffectAdvanceTextLayer +class Effect3 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Effect3); virtual void onEnter() override; virtual std::string title() const override; }; -class Effect4 : public EffectAdvanceTextLayer +class Effect4 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Effect4); virtual void onEnter() override; virtual std::string title() const override; }; -class Effect5 : public EffectAdvanceTextLayer +class Effect5 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Effect5); virtual void onEnter() override; virtual void onExit() override; virtual std::string title() const override; }; -class Issue631 : public EffectAdvanceTextLayer +class Issue631 : public EffectAdvanceBaseTest { public: + CREATE_FUNC(Issue631); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; -class EffectAdvanceScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/EffectsTest/EffectsTest.cpp b/tests/cpp-tests/Classes/EffectsTest/EffectsTest.cpp index a09c4f8c24..34b07c6bec 100644 --- a/tests/cpp-tests/Classes/EffectsTest/EffectsTest.cpp +++ b/tests/cpp-tests/Classes/EffectsTest/EffectsTest.cpp @@ -8,7 +8,6 @@ enum { kTagLabel = 2, }; -static int actionIdx=0; static std::string effectsList[] = { "Shaky3D", @@ -35,6 +34,15 @@ static std::string effectsList[] = "PageTurn3D", }; +EffectTests::EffectTests() +{ + int index = 0; + for (auto& effectName : effectsList) + { + addTestCase(effectName, [index](){return EffectBaseTest::create(index); }); + index++; + } +} class Shaky3DDemo : public Shaky3D { @@ -281,10 +289,9 @@ public: //------------------------------------------------------------------ // -// TextLayer +// EffectBaseTest // //------------------------------------------------------------------ -#define MAX_LAYER 22 ActionInterval* createEffect(int nIndex, float t) { @@ -320,35 +327,20 @@ ActionInterval* createEffect(int nIndex, float t) return nullptr; } -ActionInterval* getAction() -{ - auto pEffect = createEffect(actionIdx, 3); - - return pEffect; -} - -void EffectTestScene::runThisTest() -{ - addChild(TextLayer::create()); - Director::getInstance()->replaceScene(this); -} - #define SID_RESTART 1 -TextLayer::TextLayer(void) -: BaseTest() +EffectBaseTest::EffectBaseTest(int actionIdx) { LayerColor *background = LayerColor::create( Color4B(32,128,32,255) ); this->addChild(background,-20); _gridNodeTarget = NodeGrid::create(); - auto effect = getAction(); + auto effect = createEffect(actionIdx, 3); _gridNodeTarget->runAction(effect); addChild(_gridNodeTarget, 0, kTagBackground); auto bg = Sprite::create(s_back3); _gridNodeTarget->addChild(bg, 0); -// bg->setAnchorPoint( Vec2::ZERO ); bg->setPosition(VisibleRect::center()); auto grossini = Sprite::create(s_pathSister2); @@ -371,69 +363,16 @@ TextLayer::TextLayer(void) addChild(label); label->setTag( kTagLabel ); - schedule( CC_SCHEDULE_SELECTOR(TextLayer::checkAnim) ); + schedule( CC_SCHEDULE_SELECTOR(EffectBaseTest::checkAnim) ); } -void TextLayer::checkAnim(float dt) +void EffectBaseTest::checkAnim(float dt) { //auto s2 = getChildByTag(kTagBackground); if ( _gridNodeTarget->getNumberOfRunningActions() == 0 && _gridNodeTarget->getGrid() != nullptr) _gridNodeTarget->setGrid(nullptr);; } - -TextLayer::~TextLayer(void) +EffectBaseTest::~EffectBaseTest(void) { } - -// TextLayer* TextLayer::node() -// { -// return TextLayer::create(); -// } - -TextLayer* TextLayer::create() -{ - auto layer = new (std::nothrow) TextLayer(); - layer->autorelease(); - - return layer; -} - -void TextLayer::onEnter() -{ - BaseTest::onEnter(); -} - -void TextLayer::newScene() -{ - auto s = new (std::nothrow) EffectTestScene(); - auto child = TextLayer::create(); - s->addChild(child); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TextLayer::restartCallback(Ref* sender) -{ - newScene(); -} - -void TextLayer::nextCallback(Ref* sender) -{ - // update the action index - actionIdx++; - actionIdx = actionIdx % MAX_LAYER; - - newScene(); -} - -void TextLayer::backCallback(Ref* sender) -{ - // update the action index - actionIdx--; - int total = MAX_LAYER; - if( actionIdx < 0 ) - actionIdx += total; - - newScene(); -} diff --git a/tests/cpp-tests/Classes/EffectsTest/EffectsTest.h b/tests/cpp-tests/Classes/EffectsTest/EffectsTest.h index 945d96e12a..6d6b16848e 100644 --- a/tests/cpp-tests/Classes/EffectsTest/EffectsTest.h +++ b/tests/cpp-tests/Classes/EffectsTest/EffectsTest.h @@ -1,35 +1,36 @@ #ifndef _EFFECTS_TEST_H_ #define _EFFECTS_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" -class EffectTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(EffectTests); -class TextLayer : public BaseTest +class EffectBaseTest : public TestCase { protected: //UxString _title; NodeGrid* _gridNodeTarget; public: - TextLayer(void); - ~TextLayer(void); + static EffectBaseTest* create(int index) + { + auto ret = new (std::nothrow) EffectBaseTest(index); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + delete ret; + ret = nullptr; + } + + return ret; + } + + EffectBaseTest(int index); + ~EffectBaseTest(); void checkAnim(float dt); - - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - void newScene(); - - static TextLayer* create(); }; #endif diff --git a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp index fb90880444..2470679307 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.cpp @@ -6,201 +6,177 @@ const char* sceneManifests[] = {"AMTestScene1/project.manifest", "AMTestScene2/p const char* storagePaths[] = {"CppTests/AssetsManagerExTest/scene1/", "CppTests/AssetsManagerExTest/scene2/", "CppTests/AssetsManagerExTest/scene3"}; const char* backgroundPaths[] = {"Images/assetMgrBackground1.jpg", "Images/assetMgrBackground2.png", "Images/assetMgrBackground3.png"}; -AssetsManagerExTestLayer::AssetsManagerExTestLayer(const std::string& spritePath) -: _spritePath(spritePath) +AssetsManagerExTests::AssetsManagerExTests() { + addTestCase("AssetsManager Test1", [](){ return AssetsManagerExLoaderScene::create(0); }); + addTestCase("AssetsManager Test2", [](){ return AssetsManagerExLoaderScene::create(1); }); + addTestCase("AssetsManager Test3", [](){ return AssetsManagerExLoaderScene::create(2); }); } -AssetsManagerExTestLayer::~AssetsManagerExTestLayer(void) +AssetsManagerExLoaderScene* AssetsManagerExLoaderScene::create(int testIndex) { -} - -std::string AssetsManagerExTestLayer::title() const -{ - return "AssetsManagerExTest"; -} - -void AssetsManagerExTestLayer::onEnter() -{ - BaseTest::onEnter(); - _background = Sprite::create(_spritePath); - if (_background) + auto scene = new (std::nothrow) AssetsManagerExLoaderScene(testIndex); + if (scene && scene->init()) { - addChild(_background, 1); - _background->setPosition( VisibleRect::center() ); - } -} - -void AssetsManagerExTestLayer::restartCallback(Ref* sender) -{ -} - -void AssetsManagerExTestLayer::nextCallback(Ref* sender) -{ - if (AssetsManagerExLoaderScene::currentScene < 2) - { - AssetsManagerExLoaderScene::currentScene++; + scene->autorelease(); } else { - AssetsManagerExLoaderScene::currentScene = 0; + delete scene; + scene = nullptr; } - auto scene = new AssetsManagerExLoaderScene(); - scene->runThisTest(); - scene->release(); + + return scene; } -void AssetsManagerExTestLayer::backCallback(Ref* sender) -{ - if (AssetsManagerExLoaderScene::currentScene > 0) - { - AssetsManagerExLoaderScene::currentScene--; - } - else AssetsManagerExLoaderScene::currentScene = 2; - auto scene = new AssetsManagerExLoaderScene(); - scene->runThisTest(); - scene->release(); -} - - -AssetsManagerExTestScene::AssetsManagerExTestScene(std::string background) -{ - auto layer = new AssetsManagerExTestLayer(background); - addChild(layer); - layer->release(); -} - -void AssetsManagerExTestScene::runThisTest() -{ -} - -int AssetsManagerExLoaderScene::currentScene = 0; -AssetsManagerExLoaderScene::AssetsManagerExLoaderScene() -: _progress(nullptr) +AssetsManagerExLoaderScene::AssetsManagerExLoaderScene(int testIndex) +: _testIndex(testIndex) +, _loadLayer(nullptr) +, _downloadMenu(nullptr) +, _am(nullptr) +, _progress(nullptr) , _amListener(nullptr) { + } -void AssetsManagerExLoaderScene::runThisTest() +bool AssetsManagerExLoaderScene::init() { - int currentId = currentScene; - std::string manifestPath = sceneManifests[currentId], storagePath = FileUtils::getInstance()->getWritablePath() + storagePaths[currentId]; - CCLOG("Storage path for this test : %s", storagePath.c_str()); - - Sprite *sprite = Sprite::create("Images/Icon.png"); - auto layer = Layer::create(); - addChild(layer); - layer->addChild(sprite); + if (!TestCase::init()) + { + return false; + } + + auto downloadLabel = Label::createWithTTF("Start Download", "fonts/arial.ttf", 16); + auto downloadItem = MenuItemLabel::create(downloadLabel, CC_CALLBACK_1(AssetsManagerExLoaderScene::startDownloadCallback, this)); + downloadItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 100)); + _downloadMenu = Menu::create(downloadItem, nullptr); + _downloadMenu->setPosition(Vec2::ZERO); + this->addChild(_downloadMenu, 1); + + _loadLayer = Layer::create(); + addChild(_loadLayer); + + auto sprite = Sprite::create("Images/Icon.png"); + _loadLayer->addChild(sprite); sprite->setPosition( VisibleRect::center() ); TTFConfig config("fonts/tahoma.ttf", 30); _progress = Label::createWithTTF(config, "0%", TextHAlignment::CENTER); _progress->setPosition( Vec2(VisibleRect::center().x, VisibleRect::center().y + 50) ); - layer->addChild(_progress); + _loadLayer->addChild(_progress); + std::string manifestPath = sceneManifests[_testIndex], storagePath = FileUtils::getInstance()->getWritablePath() + storagePaths[_testIndex]; + CCLOG("Storage path for this test : %s", storagePath.c_str()); _am = AssetsManagerEx::create(manifestPath, storagePath); _am->retain(); - + + return true; +} + +void AssetsManagerExLoaderScene::onLoadEnd() +{ + removeChild(_loadLayer, true); + _loadLayer = nullptr; + + auto backgroundSprite = Sprite::create(backgroundPaths[_testIndex]); + addChild(backgroundSprite, 1); + backgroundSprite->setPosition(VisibleRect::center()); +} + +void AssetsManagerExLoaderScene::startDownloadCallback(Ref* sender) +{ + removeChild(_downloadMenu); + _downloadMenu = nullptr; + if (!_am->getLocalManifest()->isLoaded()) { CCLOG("Fail to update assets, step skipped."); - AssetsManagerExTestScene *scene = new AssetsManagerExTestScene(backgroundPaths[currentId]); - Director::getInstance()->replaceScene(scene); - scene->release(); + onLoadEnd(); } else { - _amListener = cocos2d::extension::EventListenerAssetsManagerEx::create(_am, [currentId, this](EventAssetsManagerEx* event){ + int testIndex = _testIndex; + _amListener = cocos2d::extension::EventListenerAssetsManagerEx::create(_am, [testIndex, this](EventAssetsManagerEx* event){ static int failCount = 0; - AssetsManagerExTestScene *scene; switch (event->getEventCode()) { - case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST: + case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST: + { + CCLOG("No local manifest file found, skip assets update."); + this->onLoadEnd(); + } + break; + case EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION: + { + std::string assetId = event->getAssetId(); + float percent = event->getPercent(); + std::string str; + if (assetId == AssetsManagerEx::VERSION_ID) { - CCLOG("No local manifest file found, skip assets update."); - scene = new AssetsManagerExTestScene(backgroundPaths[currentId]); - Director::getInstance()->replaceScene(scene); - scene->release(); + str = StringUtils::format("Version file: %.2f", percent) + "%"; } - break; - case EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION: + else if (assetId == AssetsManagerEx::MANIFEST_ID) { - std::string assetId = event->getAssetId(); - float percent = event->getPercent(); - std::string str; - if (assetId == AssetsManagerEx::VERSION_ID) - { - str = StringUtils::format("Version file: %.2f", percent) + "%"; - } - else if (assetId == AssetsManagerEx::MANIFEST_ID) - { - str = StringUtils::format("Manifest file: %.2f", percent) + "%"; - } - else - { - str = StringUtils::format("%.2f", percent) + "%"; - CCLOG("%.2f Percent", percent); - } - if (this->_progress != nullptr) - this->_progress->setString(str); + str = StringUtils::format("Manifest file: %.2f", percent) + "%"; } - break; - case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST: - case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST: + else { - CCLOG("Fail to download manifest file, update skipped."); - scene = new AssetsManagerExTestScene(backgroundPaths[currentId]); - Director::getInstance()->replaceScene(scene); - scene->release(); + str = StringUtils::format("%.2f", percent) + "%"; + CCLOG("%.2f Percent", percent); } - break; - case EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE: - case EventAssetsManagerEx::EventCode::UPDATE_FINISHED: - { - CCLOG("Update finished. %s", event->getMessage().c_str()); - scene = new AssetsManagerExTestScene(backgroundPaths[currentId]); - Director::getInstance()->replaceScene(scene); - scene->release(); - } - break; - case EventAssetsManagerEx::EventCode::UPDATE_FAILED: - { - CCLOG("Update failed. %s", event->getMessage().c_str()); + if (this->_progress != nullptr) + this->_progress->setString(str); + } + break; + case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST: + case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST: + { + CCLOG("Fail to download manifest file, update skipped."); + this->onLoadEnd(); + } + break; + case EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE: + case EventAssetsManagerEx::EventCode::UPDATE_FINISHED: + { + CCLOG("Update finished. %s", event->getMessage().c_str()); + this->onLoadEnd(); + } + break; + case EventAssetsManagerEx::EventCode::UPDATE_FAILED: + { + CCLOG("Update failed. %s", event->getMessage().c_str()); - failCount ++; - if (failCount < 5) - { - _am->downloadFailedAssets(); - } - else - { - CCLOG("Reach maximum fail count, exit update process"); - failCount = 0; - scene = new AssetsManagerExTestScene(backgroundPaths[currentId]); - Director::getInstance()->replaceScene(scene); - scene->release(); - } - } - break; - case EventAssetsManagerEx::EventCode::ERROR_UPDATING: + failCount++; + if (failCount < 5) { - CCLOG("Asset %s : %s", event->getAssetId().c_str(), event->getMessage().c_str()); + _am->downloadFailedAssets(); } - break; - case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS: + else { - CCLOG("%s", event->getMessage().c_str()); + CCLOG("Reach maximum fail count, exit update process"); + failCount = 0; + this->onLoadEnd(); } - break; - default: - break; + } + break; + case EventAssetsManagerEx::EventCode::ERROR_UPDATING: + { + CCLOG("Asset %s : %s", event->getAssetId().c_str(), event->getMessage().c_str()); + } + break; + case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS: + { + CCLOG("%s", event->getMessage().c_str()); + } + break; + default: + break; } }); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_amListener, 1); - + _am->update(); - - Director::getInstance()->replaceScene(this); } } @@ -208,5 +184,10 @@ void AssetsManagerExLoaderScene::onExit() { _eventDispatcher->removeEventListener(_amListener); _am->release(); - Scene::onExit(); + TestCase::onExit(); +} + +std::string AssetsManagerExLoaderScene::title() const +{ + return "AssetsManagerExTest"; } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.h b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.h index cb0029751b..86ad25c979 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/AssetsManagerExTest/AssetsManagerExTest.h @@ -2,52 +2,37 @@ #define __AssetsManagerEx_Test_H__ #include "extensions/cocos-ext.h" -#include "../../testBasic.h" #include "../../BaseTest.h" USING_NS_CC; USING_NS_CC_EXT; -class AssetsManagerExTestLayer : public BaseTest -{ -public: - AssetsManagerExTestLayer(const std::string& spritePath); - ~AssetsManagerExTestLayer(void); - - virtual std::string title() const override; - void onEnter() override; - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; - -private: - Sprite *_background; - std::string _spritePath; -}; +DEFINE_TEST_SUITE(AssetsManagerExTests); -class AssetsManagerExTestScene : public TestScene +class AssetsManagerExLoaderScene : public TestCase { public: - AssetsManagerExTestScene(std::string background); - virtual void runThisTest() override; -}; + static AssetsManagerExLoaderScene* create(int testIndex); -class AssetsManagerExLoaderScene : public TestScene -{ -public: - AssetsManagerExLoaderScene(); - - virtual void runThisTest() override; + AssetsManagerExLoaderScene(int testIndex); + void startDownloadCallback(Ref* sender); + + virtual std::string title() const; + + virtual bool init() override; virtual void onExit() override; - static int currentScene; - private: + int _testIndex; + Layer* _loadLayer; + Menu* _downloadMenu; + AssetsManagerEx *_am; Label *_progress; EventListenerAssetsManagerEx* _amListener; + + void onLoadEnd(); }; #endif /* defined(__AssetsManagerEx_Test_H__) */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp index 83289698df..d0d8903965 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp @@ -8,207 +8,61 @@ using namespace cocos2d; using namespace cocostudio; -Layer *NextAnimationTest(); -Layer *BackAnimationTest(); -Layer *RestartAnimationTest(); - -static int s_nActionIdx = -1; - - -Layer *CreateAnimationLayer(int index) +CocoStudioActionTimelineTests::CocoStudioActionTimelineTests() { - Layer *pLayer = nullptr; - switch(index) + ADD_TEST_CASE(TestActionTimeline); + ADD_TEST_CASE(TestChangePlaySection); + ADD_TEST_CASE(TestTimelineFrameEvent); + ADD_TEST_CASE(TestTimelinePerformance); + ADD_TEST_CASE(TestTimelineAnimationList); + ADD_TEST_CASE(TestTimelineProjectNode); + ADD_TEST_CASE(TestProjectNodeForSimulator); + ADD_TEST_CASE(TestTimelineNodeLoadedCallback); +} + +CocoStudioActionTimelineTests::~CocoStudioActionTimelineTests() +{ + +} + +bool ActionTimelineBaseTest::init() +{ + if (TestCase::init()) { - case TEST_ANIMATIONELEMENT: - pLayer = new (std::nothrow) TestActionTimeline(); - break; - case TEST_CHANGE_PLAY_SECTION: - pLayer = new (std::nothrow) TestChangePlaySection(); - break; - /* - case TEST_TIMELINE_FRAME_EVENT: - pLayer = new (std::nothrow) TestTimelineFrameEvent(); - break; - */ - case TEST_TIMELINE_PERFORMACE: - pLayer = new (std::nothrow) TestTimelinePerformance(); - break; - case TEST_TIMELINEACTION_ANIMATIONLIST: - pLayer = new (std::nothrow) TestTimelineAnimationList(); - break; - case TEST_TIMELINEPROJECTNODE: - pLayer = new (std::nothrow) TestTimelineProjectNode(); - break; - case TEST_PROJECTNODEFORSIMALATOR: - pLayer = new (std::nothrow) TestProjectNodeForSimulator; - break; - case TEST_NODELOADEDCALLBACK: - pLayer = new (std::nothrow)TestTimelineNodeLoadedCallback; - break; - default: - CCLOG("NONE OF THIS TEST LAYER"); - break; + Sprite *bg = Sprite::create("armature/bg.jpg"); + bg->setPosition(VisibleRect::center()); + + float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; + float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; + + bg->setScaleX(scaleX); + bg->setScaleY(scaleY); + + addChild(bg); + + setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + + return true; } - - return pLayer; + return false; } - -Layer *NextAnimationTest() +void ActionTimelineBaseTest::onExit() { - ++s_nActionIdx; - s_nActionIdx = s_nActionIdx % TEST_ANIMATION_LAYER_COUNT; - - Layer *pLayer = CreateAnimationLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -Layer *BackAnimationTest() -{ - --s_nActionIdx; - if( s_nActionIdx < 0 ) - s_nActionIdx += TEST_ANIMATION_LAYER_COUNT; - - Layer *pLayer = CreateAnimationLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -Layer *RestartAnimationTest() -{ - Layer *pLayer = CreateAnimationLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - - -ActionTimelineTestScene::ActionTimelineTestScene(bool bPortrait) -{ - TestScene::init(); - - Sprite *bg = Sprite::create("armature/bg.jpg"); - bg->setPosition(VisibleRect::center()); - - float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; - float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; - - bg->setScaleX(scaleX); - bg->setScaleY(scaleY); - - addChild(bg); -} - -void ActionTimelineTestScene::runThisTest() -{ - s_nActionIdx = -1; - addChild(NextAnimationTest()); - - Director::getInstance()->replaceScene(this); -} - -void ActionTimelineTestScene::MainMenuCallback(Ref *pSender) -{ - //TestScene::MainMenuCallback(pSender); - - removeAllChildren(); -} - - - -void ActionTimelineTestLayer::onEnter() -{ - - Layer::onEnter(); - - // add title and subtitle - std::string str = title(); - const char *title = str.c_str(); - auto label = Label::createWithSystemFont(title, "Arial", 18); - label->setColor(Color3B(0, 0, 0)); - addChild(label, 1, 10000); - label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - auto l = Label::createWithSystemFont(strSubtitle.c_str(), "Arial", 18); - l->setColor(Color3B(0, 0, 0)); - addChild(l, 1, 10001); - l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60); - } - - // add menu - backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ActionTimelineTestLayer::backCallback, this) ); - restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ActionTimelineTestLayer::restartCallback, this) ); - nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ActionTimelineTestLayer::nextCallback, this) ); - - Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr); - - menu->setPosition(Point::ZERO); - backItem->setPosition(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - restartItem->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - nextItem->setPosition(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - - addChild(menu, 100); - - setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); - -} -void ActionTimelineTestLayer::onExit() -{ - removeAllChildren(); - - backItem = restartItem = nextItem = nullptr; - cocostudio::destroyCocosStudio(); - Layer::onExit(); + TestCase::onExit(); } -std::string ActionTimelineTestLayer::title() const +std::string ActionTimelineBaseTest::title() const { return "Armature Test Bed"; } -std::string ActionTimelineTestLayer::subtitle() const -{ - return ""; -} - -void ActionTimelineTestLayer::restartCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ActionTimelineTestScene(); - s->addChild( RestartAnimationTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ActionTimelineTestLayer::nextCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ActionTimelineTestScene(); - s->addChild( NextAnimationTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} -void ActionTimelineTestLayer::backCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ActionTimelineTestScene(); - auto a = BackAnimationTest(); - s->addChild( a); - Director::getInstance()->replaceScene(s); - s->release(); -} - - // TestActionTimeline void TestActionTimeline::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); @@ -232,7 +86,7 @@ std::string TestActionTimeline::title() const // TestActionTimeline void TestChangePlaySection::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); @@ -271,7 +125,7 @@ void TestChangePlaySection::onTouchesEnded(const std::vector& touches, E // TestFrameEvent void TestTimelineFrameEvent::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); @@ -316,7 +170,7 @@ void TestTimelineFrameEvent::onFrameEvent(Frame* frame) // TestTimelinePerformance void TestTimelinePerformance::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); for (int i = 0; i< 100; i++) { @@ -340,7 +194,7 @@ std::string TestTimelinePerformance::title() const // TestTimelineAnimationList void TestTimelineAnimationList::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb"); ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb"); cocostudio::timeline::AnimationInfo standinfo("stand", 0, 40); @@ -365,7 +219,7 @@ std::string TestTimelineAnimationList::title() const //InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame void TestTimelineProjectNode::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/TestAnimation.csb"); ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/TestAnimation.csb"); @@ -385,7 +239,7 @@ std::string TestTimelineProjectNode::title() const //InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame void TestProjectNodeForSimulator::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::getInstance()->createNodeWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd"); ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd"); @@ -411,7 +265,7 @@ std::string TestProjectNodeForSimulator::title() const //TestTimelineNodeLoadedCallback void TestTimelineNodeLoadedCallback::onEnter() { - ActionTimelineTestLayer::onEnter(); + ActionTimelineBaseTest::onEnter(); Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb", CC_CALLBACK_1(TestTimelineNodeLoadedCallback::nodeLoadedCallback, this)); @@ -439,4 +293,4 @@ void TestTimelineNodeLoadedCallback::nodeLoadedCallback(cocos2d::Ref *sender) CCLOG("node name = %s", node->getName().c_str()); CCLOG("node parent name = %s", node->getParent()->getName().c_str()); } -} \ No newline at end of file +} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h index 3c0968d012..914ba2199e 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h @@ -2,117 +2,107 @@ #define __ANIMATION_TEST_SCENE_H__ #include "cocos2d.h" -#include "../../VisibleRect.h" -#include "../../testBasic.h" +#include "../../BaseTest.h" #include "cocostudio/CocoStudio.h" using namespace cocostudio::timeline; - -class ActionTimelineTestScene : public TestScene +class CocoStudioActionTimelineTests : public TestSuite { -public: - ActionTimelineTestScene(bool bPortrait = false); - - virtual void runThisTest(); - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(Ref* pSender); +public: + CocoStudioActionTimelineTests(); + ~CocoStudioActionTimelineTests(); }; -enum { - TEST_ANIMATIONELEMENT = 0, - TEST_CHANGE_PLAY_SECTION, -// TEST_TIMELINE_FRAME_EVENT, - TEST_TIMELINE_PERFORMACE, - TEST_TIMELINEACTION_ANIMATIONLIST, - TEST_TIMELINEPROJECTNODE, - TEST_PROJECTNODEFORSIMALATOR, - TEST_NODELOADEDCALLBACK, - - TEST_ANIMATION_LAYER_COUNT -}; - -class ActionTimelineTestLayer : public Layer +class ActionTimelineBaseTest : public TestCase { public: virtual std::string title() const; - virtual std::string subtitle() const; - virtual void restartCallback(Ref* pSender); - virtual void nextCallback(Ref* pSender); - virtual void backCallback(Ref* pSender); + virtual bool init() override; // overrides - virtual void onEnter() override; virtual void onExit() override; protected: - MenuItemImage *restartItem; - MenuItemImage *nextItem; - MenuItemImage *backItem; }; -class TestActionTimeline : public ActionTimelineTestLayer +class TestActionTimeline : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestActionTimeline); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestChangePlaySection : public ActionTimelineTestLayer +class TestChangePlaySection : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestChangePlaySection); + virtual void onEnter() override; virtual std::string title() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); protected: ActionTimeline* action; }; -class TestTimelineFrameEvent : public ActionTimelineTestLayer +class TestTimelineFrameEvent : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestTimelineFrameEvent); + virtual void onEnter() override; virtual std::string title() const override; void onFrameEvent(Frame* frame); }; -class TestTimelinePerformance : public ActionTimelineTestLayer +class TestTimelinePerformance : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestTimelinePerformance); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestTimelineAnimationList : public ActionTimelineTestLayer +class TestTimelineAnimationList : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestTimelineAnimationList); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestTimelineProjectNode : public ActionTimelineTestLayer +class TestTimelineProjectNode : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestTimelineProjectNode); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestProjectNodeForSimulator : public ActionTimelineTestLayer +class TestProjectNodeForSimulator : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestProjectNodeForSimulator); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestTimelineNodeLoadedCallback : public ActionTimelineTestLayer +class TestTimelineNodeLoadedCallback : public ActionTimelineBaseTest { public: + CREATE_FUNC(TestTimelineNodeLoadedCallback); + virtual void onEnter() override; virtual std::string title() const override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 4ff27404f6..9342bfb93c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -6,251 +6,75 @@ using namespace cocos2d; using namespace cocostudio; -Layer *NextTest(); -Layer *BackTest(); -Layer *RestartTest(); - -static int s_nActionIdx = -1; - - -Layer *CreateLayer(int index) +CocoStudioArmatureTests::CocoStudioArmatureTests() { - Layer *pLayer = nullptr; - switch(index) - { - case TEST_ASYNCHRONOUS_LOADING: - pLayer = new (std::nothrow) TestAsynchronousLoading(); - break; - case TEST_DIRECT_LOADING: - pLayer = new (std::nothrow) TestDirectLoading(); - break; - case TEST_DRAGON_BONES_2_0: - pLayer = new (std::nothrow) TestDragonBones20(); - break; - case TEST_COCOSTUDIO_WITH_SKELETON: - pLayer = new (std::nothrow) TestCSWithSkeleton(); - break; - case TEST_PERFORMANCE: - pLayer = new (std::nothrow) TestPerformance(); - break; -// case TEST_PERFORMANCE_BATCHNODE: -// pLayer = new (std::nothrow) TestPerformanceBatchNode(); -// break; - case TEST_CHANGE_ZORDER: - pLayer = new (std::nothrow) TestChangeZorder(); - break; - case TEST_ANIMATION_EVENT: - pLayer = new (std::nothrow) TestAnimationEvent(); - break; - case TEST_FRAME_EVENT: - pLayer = new (std::nothrow) TestFrameEvent(); - break; - case TEST_PARTICLE_DISPLAY: - pLayer = new (std::nothrow) TestParticleDisplay(); - break; - case TEST_USE_DIFFERENT_PICTURE: - pLayer = new (std::nothrow) TestUseMutiplePicture(); - break; - case TEST_COLLIDER_DETECTOR: - pLayer = new (std::nothrow) TestColliderDetector(); - break; - case TEST_BOUDINGBOX: - pLayer = new (std::nothrow) TestBoundingBox(); - break; - case TEST_ANCHORPOINT: - pLayer = new (std::nothrow) TestAnchorPoint(); - break; - case TEST_ARMATURE_NESTING: - pLayer = new (std::nothrow) TestArmatureNesting(); - break; - case TEST_ARMATURE_NESTING_2: - pLayer = new (std::nothrow) TestArmatureNesting2(); - break; - case TEST_PLAY_SEVERAL_MOVEMENT: - pLayer = new (std::nothrow) TestPlaySeveralMovement(); - break; - case TEST_EASING: - pLayer = new (std::nothrow) TestEasing(); - break; - case TEST_CHANGE_ANIMATION_INTERNAL: - pLayer = new (std::nothrow) TestChangeAnimationInternal(); - break; - case TEST_DIRECT_FROM_BINARY: - pLayer = new (std::nothrow) TestLoadFromBinary(); - break; - case TEST_ARMATURE_NODE: - pLayer = new (std::nothrow) TestArmatureNode(); - break; - default: - break; - } - - return pLayer; + ADD_TEST_CASE(TestAsynchronousLoading); + ADD_TEST_CASE(TestDirectLoading); + ADD_TEST_CASE(TestDragonBones20); + ADD_TEST_CASE(TestCSWithSkeleton); + ADD_TEST_CASE(TestPerformance); + //ADD_TEST_CASE(TestPerformanceBatchNode); + ADD_TEST_CASE(TestChangeZorder); + ADD_TEST_CASE(TestAnimationEvent); + ADD_TEST_CASE(TestFrameEvent); + ADD_TEST_CASE(TestParticleDisplay); + ADD_TEST_CASE(TestUseMutiplePicture); + ADD_TEST_CASE(TestColliderDetector); + ADD_TEST_CASE(TestBoundingBox); + ADD_TEST_CASE(TestAnchorPoint); + ADD_TEST_CASE(TestArmatureNesting); + ADD_TEST_CASE(TestArmatureNesting2); + ADD_TEST_CASE(TestPlaySeveralMovement); + ADD_TEST_CASE(TestEasing); + ADD_TEST_CASE(TestChangeAnimationInternal); + ADD_TEST_CASE(TestLoadFromBinary); + ADD_TEST_CASE(TestArmatureNode); } - -Layer *NextTest() +CocoStudioArmatureTests::~CocoStudioArmatureTests() { - ++s_nActionIdx; - s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT; - - Layer *pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -Layer *BackTest() -{ - --s_nActionIdx; - if( s_nActionIdx < 0 ) - s_nActionIdx += TEST_LAYER_COUNT; - - Layer *pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - -Layer *RestartTest() -{ - Layer *pLayer = CreateLayer(s_nActionIdx); - pLayer->autorelease(); - - return pLayer; -} - - -ArmatureTestScene::ArmatureTestScene(bool bPortrait) -{ - TestScene::init(); - - Sprite *bg = Sprite::create("armature/bg.jpg"); - bg->setPosition(VisibleRect::center()); - - float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; - float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; - - bg->setScaleX(scaleX); - bg->setScaleY(scaleY); - - addChild(bg); -} -void ArmatureTestScene::runThisTest() -{ - - - s_nActionIdx = -1; - addChild(NextTest()); - - Director::getInstance()->replaceScene(this); -} -void ArmatureTestScene::MainMenuCallback(Ref *pSender) -{ - //TestScene::MainMenuCallback(pSender); - - removeAllChildren(); ArmatureDataManager::destroyInstance(); } - - -void ArmatureTestLayer::onEnter() +bool ArmatureBaseTest::init() { - - Layer::onEnter(); - - // add title and subtitle - std::string str = title(); - const char *pTitle = str.c_str(); - auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18); - label->setColor(Color3B::BLACK); - addChild(label, 1, 10000); - label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 30); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) + if (TestCase::init()) { - auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18); - l->setColor(Color3B::BLACK); - addChild(l, 1, 10001); - l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60); + Sprite *bg = Sprite::create("armature/bg.jpg"); + bg->setPosition(VisibleRect::center()); + + float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width; + float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height; + + bg->setScaleX(scaleX); + bg->setScaleY(scaleY); + + addChild(bg); + + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + + return true; } - // add menu - backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback, this) ); - restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this) ); - nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this) ); - - Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr); - - menu->setPosition(Vec2::ZERO); - backItem->setPosition(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - restartItem->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - nextItem->setPosition(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2); - - addChild(menu, 100); - - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); - -} -void ArmatureTestLayer::onExit() -{ - removeAllChildren(); - - backItem = restartItem = nextItem = nullptr; - - cocostudio::destroyCocosStudio(); - - Layer::onExit(); + return false; } -std::string ArmatureTestLayer::title() const +std::string ArmatureBaseTest::title() const { return "Armature Test Bed"; } -std::string ArmatureTestLayer::subtitle() const -{ - return ""; -} - -void ArmatureTestLayer::restartCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ArmatureTestScene(); - s->addChild( RestartTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} -void ArmatureTestLayer::nextCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ArmatureTestScene(); - s->addChild( NextTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} -void ArmatureTestLayer::backCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) ArmatureTestScene(); - s->addChild( BackTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} void TestAsynchronousLoading::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); - //CCLOG("armature version : %s", armatureVersion()); - - backItem->setEnabled(false); - restartItem->setEnabled(false); - nextItem->setEnabled(false); + _priorTestItem->setEnabled(false); + _restartTestItem->setEnabled(false); + _nextTestItem->setEnabled(false); char pszPercent[255]; sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f); - auto label = (Label *)getChildByTag(10001); - label->setString(pszPercent); - + _subtitleLabel->setString(pszPercent); //! create a new thread to load data ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded)); @@ -275,33 +99,33 @@ std::string TestAsynchronousLoading::subtitle() const return "current percent : "; } -void TestAsynchronousLoading::restartCallback(Ref* pSender) +void TestAsynchronousLoading::restartTestCallback(Ref* pSender) { ArmatureDataManager::destroyInstance(); - ArmatureTestLayer::restartCallback(pSender); + ArmatureBaseTest::restartTestCallback(pSender); } + void TestAsynchronousLoading::dataLoaded(float percent) { - auto label = (Label *)getChildByTag(10001); - if (label) + if (_subtitleLabel) { char pszPercent[255]; sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100); - label->setString(pszPercent); + _subtitleLabel->setString(pszPercent); } - if (percent >= 1 && backItem && restartItem && nextItem) + if (percent >= 1) { - backItem->setEnabled(true); - restartItem->setEnabled(true); - nextItem->setEnabled(true); + _priorTestItem->setEnabled(true); + _restartTestItem->setEnabled(true); + _nextTestItem->setEnabled(true); } } void TestDirectLoading::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); // remove sigle resource ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson"); @@ -322,7 +146,7 @@ std::string TestDirectLoading::title() const void TestCSWithSkeleton::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); Armature *armature = nullptr; armature = Armature::create("Cowboy"); armature->getAnimation()->playWithIndex(0); @@ -337,12 +161,9 @@ std::string TestCSWithSkeleton::title() const return "Test Export From CocoStudio With Skeleton Effect"; } - - - void TestDragonBones20::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); Armature *armature = nullptr; armature = Armature::create("Dragon"); @@ -358,8 +179,6 @@ std::string TestDragonBones20::title() const return "Test Export From DragonBones version 2.0"; } - - #define ArmaturePerformanceTag 20000 TestPerformance::~TestPerformance() @@ -367,7 +186,7 @@ TestPerformance::~TestPerformance() } void TestPerformance::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); MenuItemFont::setFontSize(65); @@ -441,8 +260,7 @@ void TestPerformance::refreshTitle() { char pszCount[255]; sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount); - auto label = (Label *)getChildByTag(10001); - label->setString(pszCount); + _subtitleLabel->setString(pszCount); } @@ -469,7 +287,7 @@ void TestPerformanceBatchNode::removeArmatureFromParent(int tag) void TestChangeZorder::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); Armature *armature = nullptr; currentTag = -1; @@ -514,12 +332,9 @@ void TestChangeZorder::changeZorder(float dt) currentTag = currentTag % 3; } - - - void TestAnimationEvent::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); armature = Armature::create("Cowboy"); armature->getAnimation()->play("Fire"); armature->setScaleX(-0.24f); @@ -568,13 +383,11 @@ void TestAnimationEvent::callback2() armature->getAnimation()->play("Fire", 10); } - - #define FRAME_EVENT_ACTION_TAG 10000 void TestFrameEvent::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); _gridNode = NodeGrid::create(); Armature *armature = Armature::create("HeroAnimation"); armature->getAnimation()->play("attack"); @@ -615,11 +428,9 @@ void TestFrameEvent::checkAction(float dt) _gridNode->setGrid(nullptr); } - - void TestParticleDisplay::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestParticleDisplay::onTouchesEnded, this); @@ -657,7 +468,7 @@ void TestParticleDisplay::onEnter() void TestParticleDisplay::onExit() { - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } std::string TestParticleDisplay::title() const @@ -679,7 +490,7 @@ void TestParticleDisplay::onTouchesEnded(const std::vector& touches, Eve void TestUseMutiplePicture::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestUseMutiplePicture::onTouchesEnded, this); @@ -715,7 +526,7 @@ void TestUseMutiplePicture::onEnter() void TestUseMutiplePicture::onExit() { - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } std::string TestUseMutiplePicture::title() const @@ -740,7 +551,7 @@ TestColliderDetector::~TestColliderDetector() } void TestColliderDetector::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); scheduleUpdate(); @@ -852,7 +663,7 @@ void TestColliderDetector::onExit() CC_SAFE_DELETE(listener); CC_SAFE_DELETE(debugDraw); - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { @@ -978,7 +789,7 @@ void TestColliderDetector::onExit() cpSpaceFree(space); - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } void TestColliderDetector::update(float delta) @@ -1112,12 +923,9 @@ void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint3 #endif - - - void TestBoundingBox::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); armature = Armature::create("Cowboy"); armature->getAnimation()->playWithIndex(0); @@ -1144,7 +952,7 @@ void TestBoundingBox::draw(Renderer *renderer, const Mat4 &transform, uint32_t f void TestAnchorPoint::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); for (int i = 0; i < 5; i++) { @@ -1169,7 +977,7 @@ std::string TestAnchorPoint::title() const void TestArmatureNesting::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting::onTouchesEnded, this); @@ -1187,7 +995,7 @@ void TestArmatureNesting::onEnter() void TestArmatureNesting::onExit() { - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } std::string TestArmatureNesting::title() const @@ -1224,7 +1032,7 @@ Hero *Hero::create(const char *name) Hero::Hero() : m_pMount(nullptr) - , m_pLayer(nullptr) + , _scene(nullptr) { } @@ -1241,8 +1049,7 @@ void Hero::changeMount(Armature *armature) //Set position to current position setPosition(m_pMount->getPosition()); - //Add to layer - m_pLayer->addChild(this); + _scene->addChild(this); release(); @@ -1286,7 +1093,7 @@ void Hero::playWithIndex(int index) void TestArmatureNesting2::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting2::onTouchesEnded, this); @@ -1306,7 +1113,7 @@ void TestArmatureNesting2::onEnter() //Create a hero hero = Hero::create("hero"); - hero->setLayer(this); + hero->setScene(this); hero->playWithIndex(0); hero->setPosition(VisibleRect::left().x + 20, VisibleRect::left().y); addChild(hero); @@ -1321,7 +1128,7 @@ void TestArmatureNesting2::onEnter() } void TestArmatureNesting2::onExit() { - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } std::string TestArmatureNesting2::title() const { @@ -1390,11 +1197,7 @@ Armature * TestArmatureNesting2::createMount(const char *name, Vec2 position) void TestPlaySeveralMovement::onEnter() { - ArmatureTestLayer::onEnter(); - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + ArmatureBaseTest::onEnter(); std::string name[] = {"Walk", "FireMax", "Fire"}; std::vector names(name, name+3); @@ -1423,12 +1226,7 @@ std::string TestPlaySeveralMovement::subtitle()const void TestEasing::onEnter() { - ArmatureTestLayer::onEnter(); - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - + ArmatureBaseTest::onEnter(); animationID = 0; armature = Armature::create("testEasing"); @@ -1460,17 +1258,12 @@ void TestEasing::onTouchesEnded(const std::vector& touches, Event* event void TestEasing::updateSubTitle() { std::string str = subtitle() + armature->getAnimation()->getCurrentMovementID(); - auto label = (Label *)getChildByTag(10001); - label->setString(str.c_str()); + _subtitleLabel->setString(str.c_str()); } void TestChangeAnimationInternal::onEnter() { - ArmatureTestLayer::onEnter(); - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + ArmatureBaseTest::onEnter(); Armature *armature = nullptr; armature = Armature::create("Cowboy"); @@ -1483,7 +1276,7 @@ void TestChangeAnimationInternal::onEnter() void TestChangeAnimationInternal::onExit() { Director::getInstance()->setAnimationInterval(1/60.0f); - ArmatureTestLayer::onExit(); + ArmatureBaseTest::onExit(); } std::string TestChangeAnimationInternal::title() const { @@ -1519,7 +1312,7 @@ const char* TestLoadFromBinary::m_armatureNames[BINARYFILECOUNT] ={"bear","hors void TestLoadFromBinary::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestLoadFromBinary::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); @@ -1592,34 +1385,30 @@ void TestLoadFromBinary::onTouchesEnded(const std::vector& touches, Even void TestLoadFromBinary::dataLoaded( float percent ) { - Label *label = (Label *)getChildByTag(10001); - if (label) + if (_subtitleLabel) { char pszPercent[255]; sprintf(pszPercent, "%s %f", "Asynchronous loading: ", percent * 100); - label->setString(pszPercent); + _subtitleLabel->setString(pszPercent); } if (percent >= 1) { - label->setString("Touch to change armature"); + _subtitleLabel->setString("Touch to change armature"); m_armatureIndex = 0; } } - - //TestArmatureNode void TestArmatureNode::onEnter() { - ArmatureTestLayer::onEnter(); + ArmatureBaseTest::onEnter(); auto node = CSLoader::createNode("TestArmatureNode.csb"); addChild(node); } - std::string TestArmatureNode::title() const { return "Test Armature Node"; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 318d88c400..2bd4fae241 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -3,8 +3,7 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "../../VisibleRect.h" -#include "../../testBasic.h" +#include "../../BaseTest.h" #include "cocostudio/CocoStudio.h" #if ENABLE_PHYSICS_BOX2D_DETECT @@ -14,100 +13,71 @@ #include "chipmunk.h" #endif -class ArmatureTestScene : public TestScene +class CocoStudioArmatureTests : public TestSuite { -public: - ArmatureTestScene(bool bPortrait = false); +public: + CocoStudioArmatureTests(); + ~CocoStudioArmatureTests(); - virtual void runThisTest(); +private: - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(Ref* pSender); }; -enum { - TEST_ASYNCHRONOUS_LOADING = 0, - TEST_DIRECT_LOADING, - TEST_COCOSTUDIO_WITH_SKELETON, - TEST_DRAGON_BONES_2_0, - TEST_PERFORMANCE, -// TEST_PERFORMANCE_BATCHNODE, - TEST_CHANGE_ZORDER, - TEST_ANIMATION_EVENT, - TEST_FRAME_EVENT, - TEST_PARTICLE_DISPLAY, - TEST_USE_DIFFERENT_PICTURE, - TEST_COLLIDER_DETECTOR, - TEST_BOUDINGBOX, - TEST_ANCHORPOINT, - TEST_ARMATURE_NESTING, - TEST_ARMATURE_NESTING_2, - TEST_PLAY_SEVERAL_MOVEMENT, - TEST_EASING, - TEST_CHANGE_ANIMATION_INTERNAL, - TEST_DIRECT_FROM_BINARY, - TEST_ARMATURE_NODE, - - TEST_LAYER_COUNT -}; - -class ArmatureTestLayer : public Layer +class ArmatureBaseTest : public TestCase { public: virtual std::string title() const; - virtual std::string subtitle() const; - - virtual void restartCallback(Ref* pSender); - virtual void nextCallback(Ref* pSender); - virtual void backCallback(Ref* pSender); - - // overrides - virtual void onEnter() override; - virtual void onExit() override; + virtual bool init() override; protected: - MenuItemImage *restartItem; - MenuItemImage *nextItem; - MenuItemImage *backItem; }; - -class TestAsynchronousLoading : public ArmatureTestLayer +class TestAsynchronousLoading : public ArmatureBaseTest { public: + CREATE_FUNC(TestAsynchronousLoading); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void restartCallback(Ref* pSender); + virtual void restartTestCallback(Ref* pSender) override; void dataLoaded(float percent); }; -class TestDirectLoading : public ArmatureTestLayer +class TestDirectLoading : public ArmatureBaseTest { public: + CREATE_FUNC(TestDirectLoading); virtual void onEnter() override; virtual std::string title() const override; }; -class TestCSWithSkeleton : public ArmatureTestLayer +class TestCSWithSkeleton : public ArmatureBaseTest { +public: + CREATE_FUNC(TestCSWithSkeleton); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestDragonBones20 : public ArmatureTestLayer +class TestDragonBones20 : public ArmatureBaseTest { public: + CREATE_FUNC(TestDragonBones20); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestPerformance : public ArmatureTestLayer +class TestPerformance : public ArmatureBaseTest { public: + CREATE_FUNC(TestPerformance); + ~TestPerformance(); virtual void onEnter() override; @@ -130,6 +100,9 @@ public: class TestPerformanceBatchNode : public TestPerformance { +public: + CREATE_FUNC(TestPerformanceBatchNode); + virtual void onEnter() override; virtual std::string title() const override; virtual void addArmatureToParent(cocostudio::Armature *armature); @@ -138,8 +111,11 @@ class TestPerformanceBatchNode : public TestPerformance cocostudio::BatchNode *batchNode; }; -class TestChangeZorder : public ArmatureTestLayer +class TestChangeZorder : public ArmatureBaseTest { +public: + CREATE_FUNC(TestChangeZorder); + virtual void onEnter() override; virtual std::string title() const override; void changeZorder(float dt); @@ -148,9 +124,10 @@ class TestChangeZorder : public ArmatureTestLayer }; -class TestAnimationEvent : public ArmatureTestLayer +class TestAnimationEvent : public ArmatureBaseTest { public: + CREATE_FUNC(TestAnimationEvent); virtual void onEnter() override; virtual std::string title() const override; @@ -162,9 +139,11 @@ public: }; -class TestFrameEvent : public ArmatureTestLayer +class TestFrameEvent : public ArmatureBaseTest { public: + CREATE_FUNC(TestFrameEvent); + virtual void onEnter() override; virtual std::string title() const override; void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex); @@ -174,40 +153,46 @@ protected: }; -class TestUseMutiplePicture : public ArmatureTestLayer +class TestUseMutiplePicture : public ArmatureBaseTest { +public: + CREATE_FUNC(TestUseMutiplePicture); + virtual void onEnter() override; virtual void onExit() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); int displayIndex; cocostudio::Armature *armature; }; -class TestParticleDisplay : public ArmatureTestLayer +class TestParticleDisplay : public ArmatureBaseTest { +public: + CREATE_FUNC(TestParticleDisplay); + virtual void onEnter() override; virtual void onExit() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); int animationID; cocostudio::Armature *armature; }; - - #if ENABLE_PHYSICS_BOX2D_DETECT class ContactListener; -class TestColliderDetector : public ArmatureTestLayer +class TestColliderDetector : public ArmatureBaseTest { public: + CREATE_FUNC(TestColliderDetector); + ~TestColliderDetector(); virtual void onEnter() override; @@ -235,9 +220,11 @@ public: #elif ENABLE_PHYSICS_CHIPMUNK_DETECT -class TestColliderDetector : public ArmatureTestLayer +class TestColliderDetector : public ArmatureBaseTest { public: + CREATE_FUNC(TestColliderDetector); + ~TestColliderDetector(); virtual void onEnter() override; @@ -264,9 +251,11 @@ public: void destroyCPBody(cpBody *body); }; #elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX -class TestColliderDetector : public ArmatureTestLayer +class TestColliderDetector : public ArmatureBaseTest { public: + CREATE_FUNC(TestColliderDetector); + ~TestColliderDetector(); virtual void onEnter() override; @@ -286,12 +275,11 @@ public: #endif - - - -class TestBoundingBox : public ArmatureTestLayer +class TestBoundingBox : public ArmatureBaseTest { public: + CREATE_FUNC(TestBoundingBox); + virtual void onEnter() override; virtual std::string title() const override; virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; @@ -303,20 +291,24 @@ protected: DrawNode* _drawNode; }; -class TestAnchorPoint : public ArmatureTestLayer +class TestAnchorPoint : public ArmatureBaseTest { public: + CREATE_FUNC(TestAnchorPoint); + virtual void onEnter() override; virtual std::string title() const override; }; -class TestArmatureNesting : public ArmatureTestLayer +class TestArmatureNesting : public ArmatureBaseTest { public: + CREATE_FUNC(TestArmatureNesting); + virtual void onEnter() override; virtual void onExit() override; virtual std::string title() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); cocostudio::Armature *armature; int weaponIndex; @@ -332,17 +324,19 @@ public: virtual void playWithIndex(int index); CC_SYNTHESIZE(cocostudio::Armature*, m_pMount, Mount); - CC_SYNTHESIZE(cocos2d::Layer*, m_pLayer, Layer); + CC_SYNTHESIZE(cocos2d::Scene*, _scene, Scene); }; -class TestArmatureNesting2 : public ArmatureTestLayer +class TestArmatureNesting2 : public ArmatureBaseTest { public: + CREATE_FUNC(TestArmatureNesting2); + virtual void onEnter() override; virtual void onExit() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void changeMountCallback(Ref* pSender); virtual cocostudio::Armature *createMount(const char *name, Vec2 position); @@ -358,50 +352,58 @@ private: bool touchedMenu; }; -class TestPlaySeveralMovement : public ArmatureTestLayer +class TestPlaySeveralMovement : public ArmatureBaseTest { public: + CREATE_FUNC(TestPlaySeveralMovement); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; -class TestEasing : public ArmatureTestLayer +class TestEasing : public ArmatureBaseTest { public: + CREATE_FUNC(TestEasing); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void updateSubTitle(); int animationID; cocostudio::Armature *armature; }; -class TestChangeAnimationInternal : public ArmatureTestLayer +class TestChangeAnimationInternal : public ArmatureBaseTest { public: + CREATE_FUNC(TestChangeAnimationInternal); + virtual void onEnter()override; virtual void onExit() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); }; #define BINARYFILECOUNT 6 -class TestLoadFromBinary : public ArmatureTestLayer +class TestLoadFromBinary : public ArmatureBaseTest { public: + CREATE_FUNC(TestLoadFromBinary); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void dataLoaded(float percent); @@ -413,9 +415,11 @@ private: int m_armatureIndex; // index of sync loaded armature, default -1 is none }; -class TestArmatureNode : public ArmatureTestLayer +class TestArmatureNode : public ArmatureBaseTest { public: + CREATE_FUNC(TestArmatureNode); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.cpp index 35b03ab72a..f900a68294 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.cpp @@ -8,61 +8,35 @@ using namespace cocos2d; using namespace cocos2d::extension; using namespace cocostudio; -ComponentsTestLayer::~ComponentsTestLayer() +CocoStudioComponentsTests::CocoStudioComponentsTests() { + ADD_TEST_CASE(CocoStudioComponentsTest); } -ComponentsTestLayer::ComponentsTestLayer() +bool CocoStudioComponentsTest::init() { -} + if (TestCase::init()) + { + auto bg = LayerColor::create(Color4B(255, 255, 255, 255)); + addChild(bg); -Scene* ComponentsTestLayer::scene() -{ - Scene * scene = nullptr; - do - { - // 'scene' is an autorelease object - scene = Scene::create(); - CC_BREAK_IF(! scene); - - // 'layer' is an autorelease object - auto layer = ComponentsTestLayer::create(); - CC_BREAK_IF(! layer); - - // add layer as a child to scene - scene->addChild(layer); - } while (0); - - // return the scene - return scene; -} - -// on "init" you need to initialize your instance -bool ComponentsTestLayer::init() -{ - bool bRet = false; - do - { - CC_BREAK_IF(! LayerColor::initWithColor( Color4B(255,255,255,255) ) ); - auto root = createGameScene(); - CC_BREAK_IF(!root); this->addChild(root, 0, 1); root->getChildByTag(1)->addComponent(ComAudio::create()); - root->getChildByTag(1)->addComponent(PlayerController::create()); - + root->getChildByTag(1)->addComponent(PlayerController::create()); + root->addComponent(ComAudio::create()); root->addComponent(ComAttribute::create()); root->addComponent(SceneController::create()); - bRet = true; - } while (0); + return true; + } - return bRet; + return false; } -cocos2d::Node* ComponentsTestLayer::createGameScene() +cocos2d::Node* CocoStudioComponentsTest::createGameScene() { Node *root = nullptr; do @@ -79,26 +53,8 @@ cocos2d::Node* ComponentsTestLayer::createGameScene() root = cocos2d::Node::create(); root->addChild(player, 1, 1); - - auto itemBack = MenuItemFont::create("Back", [](Ref* sender){ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); - }); - - itemBack->setColor(Color3B(0, 0, 0)); - itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); - }while (0); return root; } -void runComponentsTestLayerTest() -{ - auto scene = ComponentsTestLayer::scene(); - Director::getInstance()->replaceScene(scene); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.h index 23c17932d8..8a5562b8a4 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/ComponentsTestScene.h @@ -3,26 +3,17 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" +#include "BaseTest.h" -void runComponentsTestLayerTest(); +DEFINE_TEST_SUITE(CocoStudioComponentsTests); -class ComponentsTestLayer : public cocos2d::LayerColor +class CocoStudioComponentsTest : public TestCase { public: - ComponentsTestLayer(); - ~ComponentsTestLayer(); + CREATE_FUNC(CocoStudioComponentsTest); - // Here's a difference. Method 'init' in cocos2d-x returns bool, - // instead of returning 'id' in cocos2d-iphone - virtual bool init() override; - - // there's no 'id' in cpp, so we recommand to return the exactly class pointer - static cocos2d::Scene* scene(); + virtual bool init() override; - // implement the "static node()" method manually - CREATE_FUNC(ComponentsTestLayer); - - // init scene cocos2d::Node* createGameScene(); }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp index c9df2069c2..08ac48b6a3 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp @@ -31,7 +31,7 @@ using namespace cocos2d; bool GameOverScene::init() { - if( Scene::init() ) + if( TestCase::init() ) { this->_layer = GameOverLayer::create(); this->_layer->retain(); @@ -70,19 +70,6 @@ bool GameOverLayer::init() DelayTime::create(3), CallFunc::create(CC_CALLBACK_0(GameOverLayer::gameOverDone, this)), nullptr)); - - - auto itemBack = MenuItemFont::create("Back", [](Ref* sender){ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); - }); - - itemBack->setColor(Color3B(0, 0, 0)); - itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); return true; } @@ -94,7 +81,11 @@ bool GameOverLayer::init() void GameOverLayer::gameOverDone() { - Director::getInstance()->replaceScene( ComponentsTestLayer::scene() ); + auto director = Director::getInstance(); + auto newScene = CocoStudioComponentsTest::create(); + auto gameoverScene = (GameOverScene*)director->getRunningScene(); + newScene->setTestSuite(gameoverScene->getTestSuite()); + director->replaceScene(newScene); } GameOverLayer::~GameOverLayer() diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.h index 7576334a7d..b42406428a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.h @@ -2,6 +2,7 @@ #define _GAME_OVER_SCENE_H_ #include "cocos2d.h" +#include "BaseTest.h" class GameOverLayer : public cocos2d::LayerColor { @@ -16,13 +17,15 @@ public: CC_SYNTHESIZE_READONLY(cocos2d::Label*, _label, Label); }; -class GameOverScene : public cocos2d::Scene +class GameOverScene : public TestCase { public: - GameOverScene():_layer(nullptr) {}; - ~GameOverScene(); - bool init(); CREATE_FUNC(GameOverScene); + + GameOverScene():_layer(nullptr) {} + ~GameOverScene(); + + virtual bool init() override; CC_SYNTHESIZE_READONLY(GameOverLayer*, _layer, Layer); }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp index 04d5560473..744f986f73 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp @@ -79,8 +79,13 @@ void SceneController::spriteMoveFinished(Node* sender) if (sprite->getTag() == 2) // target { _targets.eraseObject(sprite); + + auto director = Director::getInstance(); auto gameOverScene = GameOverScene::create(); gameOverScene->getLayer()->getLabel()->setString("You Lose :["); + auto currScene = (CocoStudioComponentsTest*)director->getRunningScene(); + gameOverScene->setTestSuite(currScene->getTestSuite()); + Director::getInstance()->replaceScene(gameOverScene); } else if (sprite->getTag() == 3) @@ -99,8 +104,11 @@ void SceneController::increaseKillCount() if (nProjectilesDestroyed >= 5) { + auto director = Director::getInstance(); auto gameOverScene = GameOverScene::create(); gameOverScene->getLayer()->getLabel()->setString("You Win!"); + auto currScene = (CocoStudioComponentsTest*)director->getRunningScene(); + gameOverScene->setTestSuite(currScene->getTestSuite()); Director::getInstance()->replaceScene(gameOverScene); } } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.h index 28d168c7c0..a4eda36e4f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.h @@ -8,8 +8,8 @@ class SceneController : public cocostudio::ComController { protected: - SceneController(void); - virtual ~SceneController(void); + SceneController(); + virtual ~SceneController(); public: virtual bool init() override; @@ -17,7 +17,7 @@ public: virtual void onExit() override; virtual void update(float delta) override; - static SceneController* create(void); + static SceneController* create(); public: cocos2d::Vector& getTargets() {return _targets;}; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index 14c78a5c7a..e74c790740 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -1,4 +1,3 @@ - #include "extensions/cocos-ext.h" #include "../ExtensionsTest.h" #include "SceneEditorTest.h" @@ -11,202 +10,47 @@ using namespace cocos2d; using namespace cocostudio; using namespace ui; -Layer *Next(); -Layer *Back(); -Layer *Restart(); - -static int s_nIdx = -1; - -Layer *createTests(int index) +CocoStudioSceneEditTests::CocoStudioSceneEditTests() { - Layer *layer = nullptr; - switch(index) + ADD_TEST_CASE(LoadSceneEdtiorFileTest); + ADD_TEST_CASE(SpriteComponentTest); + ADD_TEST_CASE(ArmatureComponentTest); + ADD_TEST_CASE(UIComponentTest); + ADD_TEST_CASE(TmxMapComponentTest); + ADD_TEST_CASE(ParticleComponentTest); + ADD_TEST_CASE(EffectComponentTest); + ADD_TEST_CASE(BackgroundComponentTest); + ADD_TEST_CASE(AttributeComponentTest); + ADD_TEST_CASE(TriggerTest); +} + +const char* SceneEditorTestBase::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"}; +bool SceneEditorTestBase::init() +{ + if (TestCase::init()) { - case TEST_LOADSCENEEDITORFILE: - layer = new (std::nothrow) LoadSceneEdtiorFileTest(); - break; - case TEST_SPIRTECOMPONENT: - layer = new (std::nothrow) SpriteComponentTest(); - break; - case TEST_ARMATURECOMPONENT: - layer = new (std::nothrow) ArmatureComponentTest(); - break; - case TEST_UICOMPONENT: - layer = new (std::nothrow) UIComponentTest(); - break; - case TEST_TMXMAPCOMPONENT: - layer = new (std::nothrow) TmxMapComponentTest(); - break; - case TEST_PARTICLECOMPONENT: - layer = new (std::nothrow) ParticleComponentTest(); - break; - case TEST_EFEECTCOMPONENT: - layer = new (std::nothrow) EffectComponentTest(); - break; - case TEST_BACKGROUNDCOMPONENT: - layer = new (std::nothrow) BackgroundComponentTest(); - break; - case TEST_ATTRIBUTECOMPONENT: - layer = new (std::nothrow) AttributeComponentTest(); - break; - case TEST_TRIGGER: - layer = new (std::nothrow) TriggerTest(); - break; - default: - break; + _isCsbLoad = false; + _loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12); + // #endif + MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestBase::changeLoadTypeCallback, this)); + Menu* loadtypemenu = CCMenu::create(itemlb, nullptr); + loadtypemenu->setPosition(Point(VisibleRect::rightTop().x - 50, VisibleRect::rightTop().y - 20)); + addChild(loadtypemenu, 100); + + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + + return true; } - return layer; + + return false; } -Layer *Next() -{ - ++s_nIdx; - s_nIdx = s_nIdx % TEST_SCENEEDITOR_COUNT; - - Layer *layer = createTests(s_nIdx); - layer->autorelease(); - - return layer; -} - -Layer *Back() -{ - --s_nIdx; - if( s_nIdx < 0 ) - s_nIdx += TEST_SCENEEDITOR_COUNT; - - Layer *layer = createTests(s_nIdx); - layer->autorelease(); - - return layer; -} - -Layer *Restart() -{ - Layer *layer = createTests(s_nIdx); - layer->autorelease(); - - return layer; -} - -SceneEditorTestScene::SceneEditorTestScene(bool bPortrait) -{ - TestScene::init(); -} - -void SceneEditorTestScene::runThisTest() -{ - s_nIdx = -1; - addChild(Next()); - CCDirector::getInstance()->replaceScene(this); -} - -void SceneEditorTestScene::MainMenuCallback(Ref *pSender) -{ - removeAllChildren(); -} - -const char* SceneEditorTestLayer::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"}; -void SceneEditorTestLayer::onEnter() -{ - CCLayer::onEnter(); - - // add title and subtitle - std::string str = title(); - const char *pTitle = str.c_str(); - auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18); - label->setTextColor(Color4B::WHITE); - addChild(label, 1, 10000); - label->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 30) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18); - l->setTextColor(Color4B::BLACK); - addChild(l, 1, 10001); - l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) ); - } - _isCsbLoad = false; - _loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12); - // #endif - MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this)); - Menu* loadtypemenu = CCMenu::create(itemlb, nullptr); - loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20)); - addChild(loadtypemenu,100); - - // add menu - backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) ); - restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(SceneEditorTestLayer::restartCallback, this) ); - nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(SceneEditorTestLayer::nextCallback, this) ); - - - Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr); - - float fScale = 0.5f; - - menu->setPosition(Vec2(0, 0)); - backItem->setPosition(Vec2(VisibleRect::center().x - restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); - backItem->setScale(fScale); - - restartItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); - restartItem->setScale(fScale); - - nextItem->setPosition(Vec2(VisibleRect::center().x + restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2)); - nextItem->setScale(fScale); - - addChild(menu, 100); - - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); -} - -void SceneEditorTestLayer::onExit() -{ - removeAllChildren(); - backItem = restartItem = nextItem = nullptr; - Layer::onExit(); -} - -std::string SceneEditorTestLayer::title() +std::string SceneEditorTestBase::title() const { return "SceneReader Test LoadSceneEditorFile"; } -std::string SceneEditorTestLayer::subtitle() -{ - return ""; -} - -void SceneEditorTestLayer::restartCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) SceneEditorTestScene(); - s->addChild(Restart()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SceneEditorTestLayer::nextCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) SceneEditorTestScene(); - s->addChild(Next()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SceneEditorTestLayer::backCallback(Ref *pSender) -{ - Scene *s = new (std::nothrow) SceneEditorTestScene(); - s->addChild(Back()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) -{ - Layer::draw(renderer, transform, flags); -} - -void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender) +void SceneEditorTestBase::changeLoadTypeCallback(cocos2d::Ref *pSender) { _isCsbLoad = !_isCsbLoad; _loadtypelb->setString(_loadtypeStr[(int)_isCsbLoad]); @@ -226,7 +70,7 @@ void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender) } } -void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName) +void SceneEditorTestBase::loadFileChangeHelper(std::string& filePathName) { std::string::size_type n = filePathName.find_last_of("."); if(n == std::string::npos) @@ -248,14 +92,14 @@ LoadSceneEdtiorFileTest::~LoadSceneEdtiorFileTest() } -std::string LoadSceneEdtiorFileTest::title() +std::string LoadSceneEdtiorFileTest::title() const { return "loadSceneEdtiorFile Test"; } void LoadSceneEdtiorFileTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -270,7 +114,7 @@ void LoadSceneEdtiorFileTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } @@ -302,14 +146,14 @@ SpriteComponentTest::~SpriteComponentTest() } -std::string SpriteComponentTest::title() +std::string SpriteComponentTest::title() const { return "Sprite Component Test"; } void SpriteComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -324,7 +168,7 @@ void SpriteComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* SpriteComponentTest::createGameScene() @@ -364,14 +208,14 @@ ArmatureComponentTest::~ArmatureComponentTest() } -std::string ArmatureComponentTest::title() +std::string ArmatureComponentTest::title() const { return "Armature Component Test"; } void ArmatureComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -386,7 +230,7 @@ void ArmatureComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* ArmatureComponentTest::createGameScene() @@ -420,14 +264,14 @@ UIComponentTest::~UIComponentTest() { } -std::string UIComponentTest::title() +std::string UIComponentTest::title() const { return "UI Component Test"; } void UIComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -442,7 +286,7 @@ void UIComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* UIComponentTest::createGameScene() @@ -495,14 +339,14 @@ TmxMapComponentTest::~TmxMapComponentTest() } -std::string TmxMapComponentTest::title() +std::string TmxMapComponentTest::title() const { return "TmxMap Component Test"; } void TmxMapComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -517,7 +361,7 @@ void TmxMapComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* TmxMapComponentTest::createGameScene() @@ -557,14 +401,14 @@ ParticleComponentTest::~ParticleComponentTest() { } -std::string ParticleComponentTest::title() +std::string ParticleComponentTest::title() const { return "Particle Component Test"; } void ParticleComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -579,7 +423,7 @@ void ParticleComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* ParticleComponentTest::createGameScene() @@ -612,14 +456,14 @@ EffectComponentTest::~EffectComponentTest() { } -std::string EffectComponentTest::title() +std::string EffectComponentTest::title() const { return "Effect Component Test"; } void EffectComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -634,7 +478,7 @@ void EffectComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* EffectComponentTest::createGameScene() @@ -679,14 +523,14 @@ BackgroundComponentTest::~BackgroundComponentTest() { } -std::string BackgroundComponentTest::title() +std::string BackgroundComponentTest::title() const { return "Background Component Test"; } void BackgroundComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -701,7 +545,7 @@ void BackgroundComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } cocos2d::Node* BackgroundComponentTest::createGameScene() @@ -732,14 +576,14 @@ AttributeComponentTest::~AttributeComponentTest() { } -std::string AttributeComponentTest::title() +std::string AttributeComponentTest::title() const { return "Attribute Component Test"; } void AttributeComponentTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); do { Node *root = createGameScene(); @@ -755,7 +599,7 @@ void AttributeComponentTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } bool AttributeComponentTest::initData() @@ -799,7 +643,7 @@ TriggerTest::~TriggerTest() { } -std::string TriggerTest::title() +std::string TriggerTest::title() const { return "Trigger Test"; } @@ -808,17 +652,17 @@ std::string TriggerTest::title() // on "init" you need to initialize your instance void TriggerTest::onEnter() { - SceneEditorTestLayer::onEnter(); + SceneEditorTestBase::onEnter(); Node *root = createGameScene(); this->addChild(root, 0, 1); this->schedule(CC_SCHEDULE_SELECTOR(TriggerTest::gameLogic)); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); - listener->onTouchBegan = CC_CALLBACK_2(SceneEditorTestLayer::onTouchBegan, this); - listener->onTouchMoved = CC_CALLBACK_2(SceneEditorTestLayer::onTouchMoved, this); - listener->onTouchEnded = CC_CALLBACK_2(SceneEditorTestLayer::onTouchEnded, this); - listener->onTouchCancelled = CC_CALLBACK_2(SceneEditorTestLayer::onTouchCancelled, this); + listener->onTouchBegan = CC_CALLBACK_2(TriggerTest::onTouchBegan, this); + listener->onTouchMoved = CC_CALLBACK_2(TriggerTest::onTouchMoved, this); + listener->onTouchEnded = CC_CALLBACK_2(TriggerTest::onTouchEnded, this); + listener->onTouchCancelled = CC_CALLBACK_2(TriggerTest::onTouchCancelled, this); dispatcher->addEventListenerWithFixedPriority(listener, 1); _touchListener = listener; } @@ -835,7 +679,7 @@ void TriggerTest::onExit() SceneReader::destroyInstance(); ActionManagerEx::destroyInstance(); GUIReader::destroyInstance(); - SceneEditorTestLayer::onExit(); + SceneEditorTestBase::onExit(); } bool TriggerTest::onTouchBegan(Touch *touch, Event *unused_event) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h index f9f25d24b8..768e13aea5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h @@ -4,46 +4,16 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "cocostudio/CocoStudio.h" +#include "BaseTest.h" -class SceneEditorTestScene : public TestScene -{ -public: - SceneEditorTestScene(bool bPortrait = false); +DEFINE_TEST_SUITE(CocoStudioSceneEditTests); - virtual void runThisTest(); - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(cocos2d::Ref* pSender); -}; - -enum { - TEST_LOADSCENEEDITORFILE = 0, - TEST_SPIRTECOMPONENT, - TEST_ARMATURECOMPONENT, - TEST_UICOMPONENT, - TEST_TMXMAPCOMPONENT, - TEST_PARTICLECOMPONENT, - TEST_EFEECTCOMPONENT, - TEST_BACKGROUNDCOMPONENT, - TEST_ATTRIBUTECOMPONENT, - TEST_TRIGGER, - TEST_SCENEEDITOR_COUNT -}; - -class SceneEditorTestLayer : public cocos2d::Layer +class SceneEditorTestBase : public TestCase { public: - virtual void onEnter() override; - virtual void onExit() override; + virtual bool init() override; - virtual std::string title(); - virtual std::string subtitle(); - - virtual void restartCallback(cocos2d::Ref* pSender); - virtual void nextCallback(cocos2d::Ref* pSender); - virtual void backCallback(cocos2d::Ref* pSender); - - virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + virtual std::string title() const override; protected: MenuItemImage *restartItem; @@ -65,13 +35,15 @@ protected: std::string _filePath; }; -class LoadSceneEdtiorFileTest : public SceneEditorTestLayer +class LoadSceneEdtiorFileTest : public SceneEditorTestBase { public: + CREATE_FUNC(LoadSceneEdtiorFileTest); + LoadSceneEdtiorFileTest(); ~LoadSceneEdtiorFileTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -80,13 +52,15 @@ private: }; -class SpriteComponentTest : public SceneEditorTestLayer +class SpriteComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(SpriteComponentTest); + SpriteComponentTest(); ~SpriteComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -95,13 +69,15 @@ private: void defaultPlay(); }; -class ArmatureComponentTest : public SceneEditorTestLayer +class ArmatureComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(ArmatureComponentTest); + ArmatureComponentTest(); ~ArmatureComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -110,13 +86,15 @@ private: void defaultPlay(); }; -class UIComponentTest : public SceneEditorTestLayer +class UIComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(UIComponentTest); + UIComponentTest(); ~UIComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -125,13 +103,15 @@ private: void defaultPlay(); }; -class TmxMapComponentTest : public SceneEditorTestLayer +class TmxMapComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(TmxMapComponentTest); + TmxMapComponentTest(); ~TmxMapComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -140,13 +120,15 @@ private: }; -class ParticleComponentTest : public SceneEditorTestLayer +class ParticleComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(ParticleComponentTest); + ParticleComponentTest(); ~ParticleComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -154,13 +136,15 @@ protected: void defaultPlay(); }; -class EffectComponentTest : public SceneEditorTestLayer +class EffectComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(EffectComponentTest); + EffectComponentTest(); ~EffectComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -170,13 +154,15 @@ private: }; -class BackgroundComponentTest : public SceneEditorTestLayer +class BackgroundComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(BackgroundComponentTest); + BackgroundComponentTest(); ~BackgroundComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; cocos2d::Node* createGameScene(); @@ -184,13 +170,15 @@ private: void defaultPlay(); }; -class AttributeComponentTest : public SceneEditorTestLayer +class AttributeComponentTest : public SceneEditorTestBase { public: + CREATE_FUNC(AttributeComponentTest); + AttributeComponentTest(); ~AttributeComponentTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; bool initData(); @@ -200,13 +188,15 @@ private: void defaultPlay(); }; -class TriggerTest : public SceneEditorTestLayer +class TriggerTest : public SceneEditorTestBase { public: + CREATE_FUNC(TriggerTest); + TriggerTest(); ~TriggerTest(); - virtual std::string title(); + virtual std::string title() const override; virtual void onEnter() override; virtual void onExit() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp index 13251e908e..e715421fa5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp @@ -30,46 +30,33 @@ USING_NS_CC; USING_NS_CC_EXT; using namespace cocosbuilder; -void CocosBuilderTestScene::runThisTest() { - /* Create an autorelease NodeLoaderLibrary. */ - NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); - - ccNodeLoaderLibrary->registerNodeLoader("HelloCocosBuilderLayer", HelloCocosBuilderLayerLoader::loader()); - - /* Create an autorelease CCBReader. */ - cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(ccNodeLoaderLibrary); - - /* Read a ccbi file. */ - auto node = ccbReader->readNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this); - - ccbReader->release(); - - if(node != nullptr) { - this->addChild(node); - } - - Director::getInstance()->replaceScene(this); +CocosBuilderTests::CocosBuilderTests() +{ + ADD_TEST_CASE(CocosBuilderTestScene); } +bool CocosBuilderTestScene::init() { + if (TestCase::init()) + { + /* Create an autorelease NodeLoaderLibrary. */ + auto nodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); -//void CocosBuilderTestScene::runThisTest() { -// auto ccbiReaderLayer = CCBIReaderLayer::node(); -// -// /* Create an autorelease NodeLoaderLibrary. */ -// NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); -// -// /* Create an autorelease CCBReader. */ -// CCBReader * ccbReader = new (std::nothrow) CCBReader(ccNodeLoaderLibrary, ccbiReaderLayer, ccbiReaderLayer); -// ccbReader->autorelease(); -// -// /* Read a ccbi file. */ -// auto node = ccbReader->readNodeGraphFromFile("ccb/simple/pub/", "ccb/test.ccbi", ccbiReaderLayer); -// -// if(node != nullptr) { -// ccbiReaderLayer->addChild(node); -// } -// -// this->addChild(ccbiReaderLayer); -// -// Director::getInstance()->replaceScene(this); -//} + nodeLoaderLibrary->registerNodeLoader("HelloCocosBuilderLayer", HelloCocosBuilderLayerLoader::loader()); + + /* Create an autorelease CCBReader. */ + cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(nodeLoaderLibrary); + + /* Read a ccbi file. */ + auto node = ccbReader->readNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this); + + ccbReader->release(); + + if (node != nullptr) { + this->addChild(node); + } + + return true; + } + + return false; +} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.h b/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.h index cdd7ee00a4..7f3203efdb 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.h @@ -1,11 +1,15 @@ #ifndef _CCBIREADER_TEST_H_ #define _CCBIREADER_TEST_H_ -#include "../../testBasic.h" +#include "../../BaseTest.h" -class CocosBuilderTestScene : public TestScene { - public: - virtual void runThisTest(); +DEFINE_TEST_SUITE(CocosBuilderTests); + +class CocosBuilderTestScene : public TestCase { +public: + CREATE_FUNC(CocosBuilderTestScene); + + virtual bool init() override; }; #endif diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h index 930d98f658..8bd0b030ac 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h @@ -33,19 +33,23 @@ USING_NS_CC_EXT; class ControlButtonTest_HelloVariableSize : public ControlScene { public: - bool init(); + CREATE_FUNC(ControlButtonTest_HelloVariableSize); + + virtual bool init() override; /** Creates and return a button with a default background and title color. */ ControlButton *standardButtonWithTitle(const char * title); - - CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_HelloVariableSize) }; class ControlButtonTest_Event : public ControlScene { public: + CREATE_FUNC(ControlButtonTest_Event); + ControlButtonTest_Event(); ~ControlButtonTest_Event(); - bool init(); + + virtual bool init() override; + void touchDownAction(Ref *sender, Control::EventType controlEvent); void touchDragInsideAction(Ref *sender, Control::EventType controlEvent); void touchDragOutsideAction(Ref *sender, Control::EventType controlEvent); @@ -58,16 +62,15 @@ public: protected: CC_SYNTHESIZE_RETAIN(Label *, _displayValueLabel, DisplayValueLabel) CC_SYNTHESIZE_RETAIN(Label *, _displayBitmaskLabel, DisplayBitmaskLabel) - CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_Event) + }; - class ControlButtonTest_Styling : public ControlScene { public: - bool init(); + virtual bool init() override; ControlButton *standardButtonWithTitle(const char *title); - CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_Styling) + CREATE_FUNC(ControlButtonTest_Styling); }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.cpp index b7c06c5c88..bd675c0959 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.cpp @@ -1,28 +1,3 @@ -/* - * ControlColourPickerTest.m - * - * Copyright (c) 2012 Yannick Loriot - * - * 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: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * 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. - * - */ - #include "CCControlColourPickerTest.h" USING_NS_CC_EXT; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.h index 8ae2e40912..f0d03d3d74 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.h @@ -1,28 +1,3 @@ -/* - * ControlColourPickerTest.h - * - * Copyright (c) 2012 Yannick Loriot - * - * 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: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * 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. - * - */ - #include "../CCControlScene.h" #include "extensions/cocos-ext.h" @@ -33,12 +8,12 @@ class ControlColourPickerTest : public ControlScene public: ControlColourPickerTest(); virtual ~ControlColourPickerTest(); - bool init(); + virtual bool init() override; /** Callback for the change value. */ void colourValueChanged(Ref *sender, Control::EventType controlEvent); CC_SYNTHESIZE_RETAIN(Label*, _colorLabel, ColorLabel) - CONTROL_SCENE_CREATE_FUNC(ControlColourPickerTest) + CREATE_FUNC(ControlColourPickerTest) }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlPotentiometerTest/CCControlPotentiometerTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlPotentiometerTest/CCControlPotentiometerTest.h index 88c77ed785..11eb1fb495 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlPotentiometerTest/CCControlPotentiometerTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlPotentiometerTest/CCControlPotentiometerTest.h @@ -32,12 +32,12 @@ class ControlPotentiometerTest : public ControlScene public: ControlPotentiometerTest(); virtual ~ControlPotentiometerTest(); - bool init(); + virtual bool init() override; CC_SYNTHESIZE_RETAIN(Label*, _displayValueLabel, DisplayValueLabel) void valueChanged(Ref *sender, Control::EventType controlEvent); - CONTROL_SCENE_CREATE_FUNC(ControlPotentiometerTest) + CREATE_FUNC(ControlPotentiometerTest) }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp index 7bb6e5e7b2..541ad62d05 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp @@ -27,27 +27,10 @@ #include "CCControlSceneManager.h" #include "../ExtensionsTest.h" -ControlScene::ControlScene() -: _sceneTitleLabel(nullptr) -{ - -} - -ControlScene::~ControlScene() -{ - CC_SAFE_RELEASE_NULL(_sceneTitleLabel); -} - bool ControlScene::init() { - if (Layer::init()) + if (TestCase::init()) { - auto pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(ControlScene::toExtensionsMainLayer, this)); - pBackItem->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25); - auto pBackMenu = Menu::create(pBackItem, nullptr); - pBackMenu->setPosition( Vec2::ZERO ); - addChild(pBackMenu, 10); - // Add the generated background auto background = Sprite::create("extensions/background.png"); background->setPosition(VisibleRect::center()); @@ -58,49 +41,8 @@ bool ControlScene::init() ribbon->setContentSize(Size(VisibleRect::getVisibleRect().size.width, 57)); ribbon->setPosition(VisibleRect::center().x, VisibleRect::top().y - ribbon->getContentSize().height / 2.0f); addChild(ribbon); - - // Add the title - setSceneTitleLabel(Label::createWithTTF("Title", "fonts/arial.ttf", 12)); - _sceneTitleLabel->setPosition(VisibleRect::center().x, VisibleRect::top().y - _sceneTitleLabel->getContentSize().height / 2 - 5); - addChild(_sceneTitleLabel, 1); - - // Add the menu - auto item1 = MenuItemImage::create("Images/b1.png", "Images/b2.png", CC_CALLBACK_1(ControlScene::previousCallback, this)); - auto item2 = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ControlScene::restartCallback, this)); - auto item3 = MenuItemImage::create("Images/f1.png", "Images/f2.png", CC_CALLBACK_1(ControlScene::nextCallback, this)); - - auto menu = Menu::create(item1, item3, item2, nullptr); - menu->setPosition(Vec2::ZERO); - item1->setPosition(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2); - item2->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2); - item3->setPosition(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2); - - addChild(menu ,1); return true; } return false; } - -void ControlScene::toExtensionsMainLayer(Ref* sender) -{ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); -} - -void ControlScene::previousCallback(Ref* sender) -{ - Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->previousControlScene()); -} - -void ControlScene::restartCallback(Ref* sender) -{ - Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->currentControlScene()); -} - -void ControlScene::nextCallback(Ref* sender) -{ - Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->nextControlScene()); -} - diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.h index 8a2f405e19..3c4e53d365 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.h @@ -28,47 +28,17 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" - +#include "BaseTest.h" USING_NS_CC; USING_NS_CC_EXT; -#define CONTROL_SCENE_CREATE_FUNC(controlScene) \ -public: \ -static Scene* sceneWithTitle(const char * title) \ -{ \ - Scene* scene = Scene::create(); \ - controlScene* controlLayer = new controlScene(); \ - if (controlLayer && controlLayer->init()) \ - { \ - controlLayer->autorelease(); \ - controlLayer->getSceneTitleLabel()->setString(title); \ - scene->addChild(controlLayer); \ - } \ - else \ - { \ - CC_SAFE_DELETE(controlLayer); \ - } \ - return scene; \ -} - - -class ControlScene : public Layer +class ControlScene : public TestCase { public: - ControlScene(); - ~ControlScene(); - bool init(); - // Menu Callbacks - void toExtensionsMainLayer(Ref* sender); - void previousCallback(Ref* sender); - void restartCallback(Ref* sender); - void nextCallback(Ref* sender); + virtual bool init() override; - /** Title label of the scene. */ - CC_SYNTHESIZE_RETAIN(Label*, _sceneTitleLabel, SceneTitleLabel) - - CONTROL_SCENE_CREATE_FUNC(ControlScene); + virtual std::string title() const override { return getTestCaseName(); } }; #endif /* __CCCONTROLSCENE_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp index 06af6a76c1..9aecdb5da5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp @@ -1,28 +1,3 @@ -/* - * ControlSceneManager.m - * - * Copyright (c) 2011 Yannick Loriot - * - * 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: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * 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. - * - */ - #include "CCControlSceneManager.h" #include "CCControlScene.h" #include "CCControlButtonTest/CCControlButtonTest.h" @@ -34,82 +9,14 @@ USING_NS_CC; -enum +ControlTests::ControlTests() { - kControlSliderTest = 0, - kControlColourPickerTest, - kControlSwitchTest, - kControlButtonTest_HelloVariableSize, - kControlButtonTest_Event, - kControlButtonTest_Styling, - kControlPotentiometerTest, - kControlStepperTest, - kControlTestMax -}; - -static const char* s_testArray[] = { - "CCControlSliderTest", - "ControlColourPickerTest", - "ControlSwitchTest", - "ControlButtonTest_HelloVariableSize", - "ControlButtonTest_Event", - "ControlButtonTest_Styling", - "ControlPotentiometerTest", - "CCControlStepperTest" -}; - -static ControlSceneManager *sharedInstance = nullptr; - - -ControlSceneManager::ControlSceneManager() -{ - _currentControlSceneId = kControlSliderTest; -} - -ControlSceneManager::~ControlSceneManager() -{ - CC_SAFE_RELEASE(sharedInstance); -} - -ControlSceneManager * ControlSceneManager::sharedControlSceneManager() -{ - if (sharedInstance == nullptr) - { - sharedInstance = new (std::nothrow) ControlSceneManager(); - } - return sharedInstance; -} - -Scene *ControlSceneManager::nextControlScene() -{ - _currentControlSceneId = (_currentControlSceneId + 1) % kControlTestMax; - - return currentControlScene(); -} - -Scene *ControlSceneManager::previousControlScene() -{ - _currentControlSceneId = _currentControlSceneId - 1; - if (_currentControlSceneId < 0) - { - _currentControlSceneId = kControlTestMax - 1; - } - - return currentControlScene(); -} - -Scene *ControlSceneManager::currentControlScene() -{ - switch (_currentControlSceneId) - { - case kControlSliderTest: return ControlSliderTest::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlColourPickerTest:return ControlColourPickerTest::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlSwitchTest:return ControlSwitchTest::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlButtonTest_HelloVariableSize:return ControlButtonTest_HelloVariableSize::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlButtonTest_Event:return ControlButtonTest_Event::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlButtonTest_Styling:return ControlButtonTest_Styling::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlPotentiometerTest:return ControlPotentiometerTest::sceneWithTitle(s_testArray[_currentControlSceneId]); - case kControlStepperTest:return ControlStepperTest::sceneWithTitle(s_testArray[_currentControlSceneId]); - } - return nullptr; + addTestCase("CCControlSliderTest", [](){ return ControlSliderTest::create(); }); + addTestCase("ControlColourPickerTest", [](){ return ControlColourPickerTest::create(); }); + addTestCase("ControlSwitchTest", [](){ return ControlSwitchTest::create(); }); + addTestCase("ControlButtonTest_HelloVariableSize", [](){ return ControlButtonTest_HelloVariableSize::create(); }); + addTestCase("ControlButtonTest_Event", [](){ return ControlButtonTest_Event::create(); }); + addTestCase("ControlButtonTest_Styling", [](){ return ControlButtonTest_Styling::create(); }); + addTestCase("ControlPotentiometerTest", [](){ return ControlPotentiometerTest::create(); }); + addTestCase("CCControlStepperTest", [](){ return ControlStepperTest::create(); }); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h index 0f84376faa..7ed9b6e0cf 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h @@ -27,28 +27,10 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" +#include "BaseTest.h" USING_NS_CC; -class ControlSceneManager : public cocos2d::Ref -{ -public: - ControlSceneManager(); - ~ControlSceneManager(); - /** Returns the singleton of the control scene manager. */ - static ControlSceneManager * sharedControlSceneManager(); - - /** Returns the next control scene. */ - cocos2d::Scene *nextControlScene(); - - /** Returns the previous control scene. */ - cocos2d::Scene *previousControlScene(); - - /** Returns the current control scene. */ - cocos2d::Scene *currentControlScene(); - - /** Control scene id. */ - CC_SYNTHESIZE(int, _currentControlSceneId, CurrentControlSceneId) -}; +DEFINE_TEST_SUITE(ControlTests); #endif /* __CCCONTROLSCENEMANAGER_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp index 2cc6549d48..0ce565f3de 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp @@ -33,7 +33,6 @@ ControlSliderTest::ControlSliderTest() ControlSliderTest::~ControlSliderTest() { - CC_SAFE_RELEASE_NULL(_displayValueLabel); } bool ControlSliderTest::init() @@ -43,10 +42,8 @@ bool ControlSliderTest::init() auto screenSize = Director::getInstance()->getWinSize(); // Add a label in which the slider value will be displayed - _displayValueLabel = Label::createWithTTF("Move the slider thumb!\nThe lower slider is restricted." ,"fonts/Marker Felt.ttf", 32); - _displayValueLabel->retain(); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(screenSize.width / 1.7f, screenSize.height / 2.0f); + _displayValueLabel = Label::createWithTTF("Move the slider thumb!\nThe lower slider is restricted." ,"fonts/Marker Felt.ttf", 20); + _displayValueLabel->setPosition(screenSize.width / 2.0f, screenSize.height * 0.7f); addChild(_displayValueLabel); // Add the slider diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.h index ef60ea8885..dc1f5f6450 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.h @@ -28,12 +28,14 @@ class ControlSliderTest : public ControlScene { public: + CREATE_FUNC(ControlSliderTest); + ControlSliderTest(); virtual ~ControlSliderTest(); - bool init(); + virtual bool init() override; void valueChanged(Ref *sender, Control::EventType controlEvent); protected: Label* _displayValueLabel; - CONTROL_SCENE_CREATE_FUNC(ControlSliderTest) + }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlStepperTest/CCControlStepperTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlStepperTest/CCControlStepperTest.h index bd03df7d6e..32fa601237 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlStepperTest/CCControlStepperTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlStepperTest/CCControlStepperTest.h @@ -31,9 +31,10 @@ class ControlStepperTest : public ControlScene { public: + CREATE_FUNC(ControlStepperTest); ControlStepperTest(); virtual ~ControlStepperTest(); - bool init(); + virtual bool init() override; /** Creates and returns a new ControlStepper. */ ControlStepper* makeControlStepper(); @@ -41,7 +42,7 @@ public: void valueChanged(Ref *sender, Control::EventType controlEvent); protected: CC_SYNTHESIZE_RETAIN(Label*, _displayValueLabel, DisplayValueLabel) - CONTROL_SCENE_CREATE_FUNC(ControlStepperTest) + }; #endif /* __CCCONTROLSTEPPERTEST_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.h index 79fa02cd98..3598ef6b02 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.h @@ -30,10 +30,10 @@ class ControlSwitchTest : public ControlScene { public: virtual ~ControlSwitchTest(); - bool init(); + virtual bool init() override; /** Callback for the change value. */ void valueChanged(Ref* sender, Control::EventType controlEvent); Label *_displayValueLabel; - CONTROL_SCENE_CREATE_FUNC(ControlSwitchTest) + CREATE_FUNC(ControlSwitchTest); }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp index 8f060c4a96..f7f2ffdced 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp @@ -19,180 +19,22 @@ #include "NetworkTest/SocketIOTest.h" #endif - -enum +ExtensionsTests::ExtensionsTests() { - LINE_SPACE = 40, - kItemTagBasic = 1000, -}; - -static struct { - const char *name; - std::function callback; -} g_extensionsTests[] = { - { "AssetsManagerExTest", [](Ref* sender) { - AssetsManagerExLoaderScene *scene = new AssetsManagerExLoaderScene(); - scene->runThisTest(); - } }, - { "NotificationCenterTest", [](Ref* sender) { runNotificationCenterTest(); } - }, - { "CCControlButtonTest", [](Ref *sender){ - ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager(); - auto scene = pManager->currentControlScene(); - Director::getInstance()->replaceScene(scene); - }}, - { "CocosBuilderTest", [](Ref *sender) { - auto scene = new (std::nothrow) CocosBuilderTestScene(); - if (scene) - { - scene->runThisTest(); - scene->release(); - } - }}, + addTest("AssetsManagerExTest", [](){ return new (std::nothrow) AssetsManagerExTests; }); + addTest("NotificationCenterTest", [](){ return new (std::nothrow) NotificationCenterTests; }); + addTest("CCControlButtonTest", [](){ return new (std::nothrow) ControlTests; }); + addTest("CocosBuilderTest", [](){ return new (std::nothrow) CocosBuilderTests; }); #if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN) && (CC_TARGET_PLATFORM != CC_PLATFORM_NACL) - { "HttpClientTest", [](Ref *sender){ runHttpClientTest();} - }, + addTest("HttpClientTest", [](){ return new (std::nothrow) HttpClientTests; }); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - { "WebSocketTest", [](Ref *sender){ runWebSocketTest();} - }, - { "SocketIOTest", [](Ref *sender){ runSocketIOTest();} - }, + addTest("WebSocketTest", [](){ return new (std::nothrow) WebSocketTests; }); + addTest("SocketIOTest", [](){ return new (std::nothrow) SocketIOTests; }); #endif - - { "TableViewTest", [](Ref *sender){ runTableViewTest();} - }, - { "CocoStudioArmatureTest", [](Ref *sender) { ArmatureTestScene *scene = new (std::nothrow) ArmatureTestScene(); - scene->runThisTest(); - scene->release(); - } - }, - { "CocoStudioActionTimelineTest", [](Ref *sender) { ActionTimelineTestScene *scene = new (std::nothrow) ActionTimelineTestScene(); - scene->runThisTest(); - scene->release(); - } - }, - { "CocoStudioComponentsTest", [](Ref *sender) { runComponentsTestLayerTest(); } - }, - { "CocoStudioSceneTest", [](Ref *sender) { SceneEditorTestScene *scene = new (std::nothrow) SceneEditorTestScene(); - scene->runThisTest(); - scene->release(); - } - }, -}; - -static const int g_maxTests = sizeof(g_extensionsTests) / sizeof(g_extensionsTests[0]); - -static Vec2 s_tCurPos = Vec2::ZERO; - -//////////////////////////////////////////////////////// -// -// ExtensionsMainLayer -// -//////////////////////////////////////////////////////// -void ExtensionsMainLayer::onEnter() -{ - Layer::onEnter(); - - auto s = Director::getInstance()->getWinSize(); - - _itemMenu = Menu::create(); - _itemMenu->setPosition( Vec2::ZERO ); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_extensionsTests[i].name, g_extensionsTests[i].callback); - pItem->setPosition(Vec2(s.width / 2, s.height - (i + 1) * LINE_SPACE)); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - - auto mouseListener = EventListenerMouse::create(); - mouseListener->onMouseScroll = CC_CALLBACK_1(ExtensionsMainLayer::onMouseScroll, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this); - - addChild(_itemMenu); + addTest("TableViewTest", [](){ return new (std::nothrow) TableViewTests; }); + addTest("CocoStudioArmatureTest", [](){ return new (std::nothrow) CocoStudioArmatureTests; }); + addTest("CocoStudioActionTimelineTest", [](){ return new (std::nothrow) CocoStudioActionTimelineTests; }); + addTest("CocoStudioComponentsTest", [](){ return new (std::nothrow) CocoStudioComponentsTests; }); + addTest("CocoStudioSceneTest", [](){ return new (std::nothrow) CocoStudioSceneEditTests; }); } - - -void ExtensionsMainLayer::onTouchesBegan(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - -void ExtensionsMainLayer::onTouchesMoved(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - auto touchLocation = touch->getLocation(); - float nMoveY = touchLocation.y - _beginPos.y; - - auto curPos = _itemMenu->getPosition(); - auto nextPos = Vec2(curPos.x, curPos.y + nMoveY); - - if (nextPos.y < 0.0f) - { - _itemMenu->setPosition(Vec2::ZERO); - return; - } - - if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) - { - _itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)); - return; - } - - _itemMenu->setPosition(nextPos); - _beginPos = touchLocation; - s_tCurPos = nextPos; -} - -void ExtensionsMainLayer::onMouseScroll(Event* event) -{ - auto mouseEvent = static_cast(event); - float nMoveY = mouseEvent->getScrollY() * 6; - - auto curPos = _itemMenu->getPosition(); - auto nextPos = Vec2(curPos.x, curPos.y + nMoveY); - - if (nextPos.y < 0.0f) - { - _itemMenu->setPosition(Vec2::ZERO); - return; - } - - if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) - { - _itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)); - return; - } - - _itemMenu->setPosition(nextPos); - s_tCurPos = nextPos; -} - -//////////////////////////////////////////////////////// -// -// ExtensionsTestScene -// -//////////////////////////////////////////////////////// - -void ExtensionsTestScene::runThisTest() -{ - auto layer = new (std::nothrow) ExtensionsMainLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); -} - - diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.h b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.h index f11bbf2071..b5b6d2e31c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.h @@ -1,29 +1,8 @@ #ifndef __EXTENSIONS_TEST_H__ #define __EXTENSIONS_TEST_H__ -#include "../testBasic.h" +#include "BaseTest.h" -class ExtensionsMainLayer : public Layer -{ -public: - virtual void onEnter() override; - - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - - Vec2 _beginPos; - Menu* _itemMenu; - - int _testcount; - -protected: - void onMouseScroll(Event* event); -}; - -class ExtensionsTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_LIST(ExtensionsTests); #endif /* __EXTENSIONS_TEST_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp index 8c53ff3190..4a246db1d8 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp @@ -6,6 +6,11 @@ USING_NS_CC; USING_NS_CC_EXT; using namespace cocos2d::network; +HttpClientTests::HttpClientTests() +{ + ADD_TEST_CASE(HttpClientTest); +} + HttpClientTest::HttpClientTest() : _labelStatusCode(nullptr) { @@ -17,10 +22,6 @@ HttpClientTest::HttpClientTest() const int LEFT = winSize.width / 4; const int RIGHT = winSize.width / 4 * 3; - auto label = Label::createWithTTF("Http Request Test", "fonts/arial.ttf", 28); - label->setPosition(winSize.width / 2, winSize.height - MARGIN); - addChild(label, 0); - auto menuRequest = Menu::create(); menuRequest->setPosition(Vec2::ZERO); addChild(menuRequest); @@ -89,13 +90,6 @@ HttpClientTest::HttpClientTest() _labelStatusCode = Label::createWithTTF("HTTP Status Code", "fonts/arial.ttf", 18); _labelStatusCode->setPosition(winSize.width / 2, winSize.height - MARGIN - 6 * SPACE); addChild(_labelStatusCode); - - // Back Menu - auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(HttpClientTest::toExtensionsMainLayer, this)); - itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); } HttpClientTest::~HttpClientTest() @@ -380,20 +374,3 @@ void HttpClientTest::onHttpRequestCompleted(HttpClient *sender, HttpResponse *re log("request ref count not 2, is %d", response->getHttpRequest()->getReferenceCount()); } } - -void HttpClientTest::toExtensionsMainLayer(cocos2d::Ref *sender) -{ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); -} - -void runHttpClientTest() -{ - auto scene = Scene::create(); - HttpClientTest *layer = new (std::nothrow) HttpClientTest(); - scene->addChild(layer); - - Director::getInstance()->replaceScene(scene); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.h b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.h index 01cf360918..37b4cf1714 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/HttpClientTest.h @@ -4,13 +4,17 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "network/HttpClient.h" +#include "BaseTest.h" -class HttpClientTest : public cocos2d::Layer +DEFINE_TEST_SUITE(HttpClientTests); + +class HttpClientTest : public TestCase { public: + CREATE_FUNC(HttpClientTest); + HttpClientTest(); virtual ~HttpClientTest(); - void toExtensionsMainLayer(cocos2d::Ref *sender); //Menu Callbacks void onMenuGetTestClicked(cocos2d::Ref *sender, bool isImmediate); @@ -22,10 +26,10 @@ public: //Http Response Callback void onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response); + virtual std::string title() const override { return "Http Request Test"; } + private: cocos2d::Label* _labelStatusCode; }; -void runHttpClientTest(); - #endif //__HTTPREQUESTHTTP_H diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp index 6ca58d5895..26a0b2280d 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp @@ -14,7 +14,12 @@ USING_NS_CC; USING_NS_CC_EXT; using namespace cocos2d::network; -SocketIOTestLayer::SocketIOTestLayer(void) +SocketIOTests::SocketIOTests() +{ + ADD_TEST_CASE(SocketIOTest); +} + +SocketIOTest::SocketIOTest() : _sioClient(nullptr) , _sioEndpoint(nullptr) { @@ -24,10 +29,6 @@ SocketIOTestLayer::SocketIOTestLayer(void) const int MARGIN = 40; const int SPACE = 35; - - auto label = Label::createWithTTF("SocketIO Extension Test", "fonts/arial.ttf", 28); - label->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN)); - addChild(label, 0); auto menuRequest = Menu::create(); menuRequest->setPosition(Vec2::ZERO); @@ -35,49 +36,49 @@ SocketIOTestLayer::SocketIOTestLayer(void) // Test to create basic client in the default namespace auto labelSIOClient = Label::createWithTTF("Open SocketIO Client", "fonts/arial.ttf", 22); - auto itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOClientClicked, this)); + auto itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTest::onMenuSIOClientClicked, this)); itemSIOClient->setPosition(Vec2(VisibleRect::left().x + labelSIOClient->getContentSize().width / 2 + 5, winSize.height - MARGIN - SPACE)); menuRequest->addChild(itemSIOClient); // Test to create a client at the endpoint '/testpoint' auto labelSIOEndpoint = Label::createWithTTF("Open SocketIO Endpoint", "fonts/arial.ttf", 22); - auto itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOEndpointClicked, this)); + auto itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuSIOEndpointClicked, this)); itemSIOEndpoint->setPosition(Vec2(VisibleRect::right().x - labelSIOEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - SPACE)); menuRequest->addChild(itemSIOEndpoint); // Test sending message to default namespace auto labelTestMessage = Label::createWithTTF("Send Test Message", "fonts/arial.ttf", 22); - auto itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageClicked, this)); + auto itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTest::onMenuTestMessageClicked, this)); itemTestMessage->setPosition(Vec2(VisibleRect::left().x + labelTestMessage->getContentSize().width / 2 + 5, winSize.height - MARGIN - 2 * SPACE)); menuRequest->addChild(itemTestMessage); // Test sending message to the endpoint '/testpoint' auto labelTestMessageEndpoint = Label::createWithTTF("Test Endpoint Message", "fonts/arial.ttf", 22); - auto itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageEndpointClicked, this)); + auto itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuTestMessageEndpointClicked, this)); itemTestMessageEndpoint->setPosition(Vec2(VisibleRect::right().x - labelTestMessageEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 2 * SPACE)); menuRequest->addChild(itemTestMessageEndpoint); // Test sending event 'echotest' to default namespace auto labelTestEvent = Label::createWithTTF("Send Test Event", "fonts/arial.ttf", 22); - auto itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventClicked, this)); + auto itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTest::onMenuTestEventClicked, this)); itemTestEvent->setPosition(Vec2(VisibleRect::left().x + labelTestEvent->getContentSize().width / 2 + 5, winSize.height - MARGIN - 3 * SPACE)); menuRequest->addChild(itemTestEvent); // Test sending event 'echotest' to the endpoint '/testpoint' auto labelTestEventEndpoint = Label::createWithTTF("Test Endpoint Event", "fonts/arial.ttf", 22); - auto itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventEndpointClicked, this)); + auto itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuTestEventEndpointClicked, this)); itemTestEventEndpoint->setPosition(Vec2(VisibleRect::right().x - labelTestEventEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 3 * SPACE)); menuRequest->addChild(itemTestEventEndpoint); // Test disconnecting basic client auto labelTestClientDisconnect = Label::createWithTTF("Disconnect Socket", "fonts/arial.ttf", 22); - auto itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestClientDisconnectClicked, this)); + auto itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTest::onMenuTestClientDisconnectClicked, this)); itemClientDisconnect->setPosition(Vec2(VisibleRect::left().x + labelTestClientDisconnect->getContentSize().width / 2 + 5, winSize.height - MARGIN - 4 * SPACE)); menuRequest->addChild(itemClientDisconnect); // Test disconnecting the endpoint '/testpoint' auto labelTestEndpointDisconnect = Label::createWithTTF("Disconnect Endpoint", "fonts/arial.ttf", 22); - auto itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEndpointDisconnectClicked, this)); + auto itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTest::onMenuTestEndpointDisconnectClicked, this)); itemTestEndpointDisconnect->setPosition(Vec2(VisibleRect::right().x - labelTestEndpointDisconnect->getContentSize().width / 2 - 5, winSize.height - MARGIN - 4 * SPACE)); menuRequest->addChild(itemTestEndpointDisconnect); @@ -86,25 +87,16 @@ SocketIOTestLayer::SocketIOTestLayer(void) _sioClientStatus->setAnchorPoint(Vec2(0, 0)); _sioClientStatus->setPosition(Vec2(VisibleRect::left().x, VisibleRect::rightBottom().y)); this->addChild(_sioClientStatus); - - // Back Menu - auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SocketIOTestLayer::toExtensionsMainLayer, this)); - itemBack->setPosition(Vec2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); - } - -SocketIOTestLayer::~SocketIOTestLayer(void) +SocketIOTest::~SocketIOTest() { } //test event callback handlers, these will be registered with socket.io -void SocketIOTestLayer::testevent(SIOClient *client, const std::string& data) { +void SocketIOTest::testevent(SIOClient *client, const std::string& data) { - log("SocketIOTestLayer::testevent called with data: %s", data.c_str()); + log("SocketIOTest::testevent called with data: %s", data.c_str()); std::stringstream s; s << client->getTag() << " received event testevent with data: " << data.c_str(); @@ -113,9 +105,9 @@ void SocketIOTestLayer::testevent(SIOClient *client, const std::string& data) { } -void SocketIOTestLayer::echotest(SIOClient *client, const std::string& data) { +void SocketIOTest::echotest(SIOClient *client, const std::string& data) { - log("SocketIOTestLayer::echotest called with data: %s", data.c_str()); + log("SocketIOTest::echotest called with data: %s", data.c_str()); std::stringstream s; s << client->getTag() << " received event echotest with data: " << data.c_str(); @@ -124,18 +116,7 @@ void SocketIOTestLayer::echotest(SIOClient *client, const std::string& data) { } -void SocketIOTestLayer::toExtensionsMainLayer(cocos2d::Ref *sender) -{ - ExtensionsTestScene *scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); - - if(_sioEndpoint) _sioEndpoint->disconnect(); - if(_sioClient) _sioClient->disconnect(); - -} - -void SocketIOTestLayer::onMenuSIOClientClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuSIOClientClicked(cocos2d::Ref *sender) { //create a client by using this static method, url does not need to contain the protocol _sioClient = SocketIO::connect("ws://channon.us:3000", *this); @@ -143,12 +124,12 @@ void SocketIOTestLayer::onMenuSIOClientClicked(cocos2d::Ref *sender) _sioClient->setTag("Test Client"); //register event callbacks using the CC_CALLBACK_2() macro and passing the instance of the target class - _sioClient->on("testevent", CC_CALLBACK_2(SocketIOTestLayer::testevent, this)); - _sioClient->on("echotest", CC_CALLBACK_2(SocketIOTestLayer::echotest, this)); + _sioClient->on("testevent", CC_CALLBACK_2(SocketIOTest::testevent, this)); + _sioClient->on("echotest", CC_CALLBACK_2(SocketIOTest::echotest, this)); } -void SocketIOTestLayer::onMenuSIOEndpointClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuSIOEndpointClicked(cocos2d::Ref *sender) { //repeat the same connection steps for the namespace "testpoint" _sioEndpoint = SocketIO::connect("ws://channon.us:3000/testpoint", *this); @@ -156,12 +137,12 @@ void SocketIOTestLayer::onMenuSIOEndpointClicked(cocos2d::Ref *sender) _sioEndpoint->setTag("Test Endpoint"); //demonstrating how callbacks can be shared within a delegate - _sioEndpoint->on("testevent", CC_CALLBACK_2(SocketIOTestLayer::testevent, this)); - _sioEndpoint->on("echotest", CC_CALLBACK_2(SocketIOTestLayer::echotest, this)); + _sioEndpoint->on("testevent", CC_CALLBACK_2(SocketIOTest::testevent, this)); + _sioEndpoint->on("echotest", CC_CALLBACK_2(SocketIOTest::echotest, this)); } -void SocketIOTestLayer::onMenuTestMessageClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestMessageClicked(cocos2d::Ref *sender) { //check that the socket is != nullptr before sending or emitting events //the client should be nullptr either before initialization and connection or after disconnect @@ -169,14 +150,14 @@ void SocketIOTestLayer::onMenuTestMessageClicked(cocos2d::Ref *sender) } -void SocketIOTestLayer::onMenuTestMessageEndpointClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestMessageEndpointClicked(cocos2d::Ref *sender) { if(_sioEndpoint != nullptr) _sioEndpoint->send("Hello Socket.IO!"); } -void SocketIOTestLayer::onMenuTestEventClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestEventClicked(cocos2d::Ref *sender) { //check that the socket is != nullptr before sending or emitting events //the client should be nullptr either before initialization and connection or after disconnect @@ -184,21 +165,21 @@ void SocketIOTestLayer::onMenuTestEventClicked(cocos2d::Ref *sender) } -void SocketIOTestLayer::onMenuTestEventEndpointClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestEventEndpointClicked(cocos2d::Ref *sender) { if(_sioEndpoint != nullptr) _sioEndpoint->emit("echotest","[{\"name\":\"myname\",\"type\":\"mytype\"}]"); } -void SocketIOTestLayer::onMenuTestClientDisconnectClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestClientDisconnectClicked(cocos2d::Ref *sender) { if(_sioClient != nullptr) _sioClient->disconnect(); } -void SocketIOTestLayer::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender) +void SocketIOTest::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender) { if(_sioEndpoint != nullptr) _sioEndpoint->disconnect(); @@ -207,9 +188,9 @@ void SocketIOTestLayer::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender // Delegate methods -void SocketIOTestLayer::onConnect(network::SIOClient* client) +void SocketIOTest::onConnect(network::SIOClient* client) { - log("SocketIOTestLayer::onConnect called"); + log("SocketIOTest::onConnect called"); std::stringstream s; s << client->getTag() << " connected!"; @@ -217,9 +198,9 @@ void SocketIOTestLayer::onConnect(network::SIOClient* client) } -void SocketIOTestLayer::onMessage(network::SIOClient* client, const std::string& data) +void SocketIOTest::onMessage(network::SIOClient* client, const std::string& data) { - log("SocketIOTestLayer::onMessage received: %s", data.c_str()); + log("SocketIOTest::onMessage received: %s", data.c_str()); std::stringstream s; s << client->getTag() << " received message with content: " << data.c_str(); @@ -227,9 +208,9 @@ void SocketIOTestLayer::onMessage(network::SIOClient* client, const std::string& } -void SocketIOTestLayer::onClose(network::SIOClient* client) +void SocketIOTest::onClose(network::SIOClient* client) { - log("SocketIOTestLayer::onClose called"); + log("SocketIOTest::onClose called"); std::stringstream s; s << client->getTag() << " closed!"; @@ -247,23 +228,11 @@ void SocketIOTestLayer::onClose(network::SIOClient* client) } -void SocketIOTestLayer::onError(network::SIOClient* client, const std::string& data) +void SocketIOTest::onError(network::SIOClient* client, const std::string& data) { - log("SocketIOTestLayer::onError received: %s", data.c_str()); + log("SocketIOTest::onError received: %s", data.c_str()); std::stringstream s; s << client->getTag() << " received error with content: " << data.c_str(); _sioClientStatus->setString(s.str().c_str()); } - - - -void runSocketIOTest() -{ - auto scene = Scene::create(); - auto layer = new (std::nothrow) SocketIOTestLayer(); - scene->addChild(layer); - - Director::getInstance()->replaceScene(scene); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.h b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.h index 5d94477680..c7d0048d8e 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/SocketIOTest.h @@ -11,21 +11,23 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "network/SocketIO.h" +#include "BaseTest.h" -class SocketIOTestLayer - : public cocos2d::Layer +DEFINE_TEST_SUITE(SocketIOTests); + +class SocketIOTest: public TestCase , public cocos2d::network::SocketIO::SIODelegate { public: - SocketIOTestLayer(void); - virtual ~SocketIOTestLayer(void); + CREATE_FUNC(SocketIOTest); + + SocketIOTest(); + virtual ~SocketIOTest(); virtual void onConnect(cocos2d::network::SIOClient* client); virtual void onMessage(cocos2d::network::SIOClient* client, const std::string& data); virtual void onClose(cocos2d::network::SIOClient* client); virtual void onError(cocos2d::network::SIOClient* client, const std::string& data); - - void toExtensionsMainLayer(cocos2d::Ref *sender); void onMenuSIOClientClicked(cocos2d::Ref *sender); void onMenuTestMessageClicked(cocos2d::Ref *sender); @@ -41,11 +43,11 @@ public: void testevent(cocos2d::network::SIOClient *client, const std::string& data); void echotest(cocos2d::network::SIOClient *client, const std::string& data); + virtual std::string title() const override{ return "SocketIO Extension Test"; } + cocos2d::network::SIOClient *_sioClient, *_sioEndpoint; cocos2d::Label *_sioClientStatus; }; -void runSocketIOTest(); - #endif /* defined(__TestCpp__SocketIOTest__) */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp index f0409e4247..be8cc6a01f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -1,18 +1,15 @@ -// -// WebSocketTest.cpp -// TestCpp -// -// Created by James Chen on 5/31/13. -// -// - #include "WebSocketTest.h" #include "../ExtensionsTest.h" USING_NS_CC; USING_NS_CC_EXT; -WebSocketTestLayer::WebSocketTestLayer() +WebSocketTests::WebSocketTests() +{ + ADD_TEST_CASE(WebSocketTest); +} + +WebSocketTest::WebSocketTest() : _wsiSendText(nullptr) , _wsiSendBinary(nullptr) , _wsiError(nullptr) @@ -27,74 +24,50 @@ WebSocketTestLayer::WebSocketTestLayer() const int MARGIN = 40; const int SPACE = 35; - auto label = Label::createWithTTF("WebSocket Test", "fonts/arial.ttf", 28); - label->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN)); - addChild(label, 0); - auto menuRequest = Menu::create(); menuRequest->setPosition(Vec2::ZERO); addChild(menuRequest); // Send Text - auto labelSendText = Label::createWithTTF("Send Text", "fonts/arial.ttf", 22); - auto itemSendText = MenuItemLabel::create(labelSendText, CC_CALLBACK_1(WebSocketTestLayer::onMenuSendTextClicked, this)); + auto labelSendText = Label::createWithTTF("Send Text", "fonts/arial.ttf", 20); + auto itemSendText = MenuItemLabel::create(labelSendText, CC_CALLBACK_1(WebSocketTest::onMenuSendTextClicked, this)); itemSendText->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - SPACE)); menuRequest->addChild(itemSendText); // Send Binary - auto labelSendBinary = Label::createWithTTF("Send Binary", "fonts/arial.ttf", 22); - auto itemSendBinary = MenuItemLabel::create(labelSendBinary, CC_CALLBACK_1(WebSocketTestLayer::onMenuSendBinaryClicked, this)); + auto labelSendBinary = Label::createWithTTF("Send Binary", "fonts/arial.ttf", 20); + auto itemSendBinary = MenuItemLabel::create(labelSendBinary, CC_CALLBACK_1(WebSocketTest::onMenuSendBinaryClicked, this)); itemSendBinary->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - 2 * SPACE)); menuRequest->addChild(itemSendBinary); // Send Text Status Label - _sendTextStatus = Label::createWithTTF("Send Text WS is waiting...", "fonts/arial.ttf", 14, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); + _sendTextStatus = Label::createWithTTF("Send Text WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); _sendTextStatus->setAnchorPoint(Vec2(0, 0)); _sendTextStatus->setPosition(Vec2(VisibleRect::left().x, VisibleRect::rightBottom().y + 25)); this->addChild(_sendTextStatus); // Send Binary Status Label - _sendBinaryStatus = Label::createWithTTF("Send Binary WS is waiting...", "fonts/arial.ttf", 14, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); + _sendBinaryStatus = Label::createWithTTF("Send Binary WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); _sendBinaryStatus->setAnchorPoint(Vec2(0, 0)); _sendBinaryStatus->setPosition(Vec2(VisibleRect::left().x + 160, VisibleRect::rightBottom().y + 25)); this->addChild(_sendBinaryStatus); // Error Label - _errorStatus = Label::createWithTTF("Error WS is waiting...", "fonts/arial.ttf", 14, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); + _errorStatus = Label::createWithTTF("Error WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP); _errorStatus->setAnchorPoint(Vec2(0, 0)); _errorStatus->setPosition(Vec2(VisibleRect::left().x + 320, VisibleRect::rightBottom().y + 25)); this->addChild(_errorStatus); - // Back Menu - auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(WebSocketTestLayer::toExtensionsMainLayer, this)); - itemBack->setPosition(Vec2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); - - _wsiSendText = new network::WebSocket(); - _wsiSendBinary = new network::WebSocket(); - _wsiError = new network::WebSocket(); - - if (!_wsiSendText->init(*this, "ws://echo.websocket.org")) - { - CC_SAFE_DELETE(_wsiSendText); - } - - if (!_wsiSendBinary->init(*this, "ws://echo.websocket.org")) - { - CC_SAFE_DELETE(_wsiSendBinary); - } - - if (!_wsiError->init(*this, "ws://invalid.url.com")) - { - CC_SAFE_DELETE(_wsiError); - } + auto startTestLabel = Label::createWithTTF("Start Test WebSocket", "fonts/arial.ttf", 16); + auto startTestItem = MenuItemLabel::create(startTestLabel, CC_CALLBACK_1(WebSocketTest::startTestCallback, this)); + startTestItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 150)); + _startTestMenu = Menu::create(startTestItem, nullptr); + _startTestMenu->setPosition(Vec2::ZERO); + this->addChild(_startTestMenu, 1); } - -WebSocketTestLayer::~WebSocketTestLayer() +WebSocketTest::~WebSocketTest() { if (_wsiSendText) _wsiSendText->close(); @@ -106,8 +79,33 @@ WebSocketTestLayer::~WebSocketTestLayer() _wsiError->close(); } +void WebSocketTest::startTestCallback(Ref* sender) +{ + removeChild(_startTestMenu); + _startTestMenu = nullptr; + + _wsiSendText = new network::WebSocket(); + _wsiSendBinary = new network::WebSocket(); + _wsiError = new network::WebSocket(); + + if (!_wsiSendText->init(*this, "ws://echo.websocket.org")) + { + CC_SAFE_DELETE(_wsiSendText); + } + + if (!_wsiSendBinary->init(*this, "ws://echo.websocket.org")) + { + CC_SAFE_DELETE(_wsiSendBinary); + } + + if (!_wsiError->init(*this, "ws://invalid.url.com")) + { + CC_SAFE_DELETE(_wsiError); + } +} + // Delegate methods -void WebSocketTestLayer::onOpen(network::WebSocket* ws) +void WebSocketTest::onOpen(network::WebSocket* ws) { log("Websocket (%p) opened", ws); if (ws == _wsiSendText) @@ -124,7 +122,7 @@ void WebSocketTestLayer::onOpen(network::WebSocket* ws) } } -void WebSocketTestLayer::onMessage(network::WebSocket* ws, const network::WebSocket::Data& data) +void WebSocketTest::onMessage(network::WebSocket* ws, const network::WebSocket::Data& data) { if (!data.isBinary) { @@ -161,7 +159,7 @@ void WebSocketTestLayer::onMessage(network::WebSocket* ws, const network::WebSoc } } -void WebSocketTestLayer::onClose(network::WebSocket* ws) +void WebSocketTest::onClose(network::WebSocket* ws) { log("websocket instance (%p) closed.", ws); if (ws == _wsiSendText) @@ -180,7 +178,7 @@ void WebSocketTestLayer::onClose(network::WebSocket* ws) CC_SAFE_DELETE(ws); } -void WebSocketTestLayer::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error) +void WebSocketTest::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error) { log("Error was fired, error code: %d", error); if (ws == _wsiError) @@ -191,15 +189,8 @@ void WebSocketTestLayer::onError(network::WebSocket* ws, const network::WebSocke } } -void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::Ref *sender) -{ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); -} - // Menu Callbacks -void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::Ref *sender) +void WebSocketTest::onMenuSendTextClicked(cocos2d::Ref *sender) { if (! _wsiSendText) { @@ -219,7 +210,7 @@ void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::Ref *sender) } } -void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::Ref *sender) +void WebSocketTest::onMenuSendBinaryClicked(cocos2d::Ref *sender) { if (! _wsiSendBinary) { return; @@ -238,13 +229,3 @@ void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::Ref *sender) _sendBinaryStatus->setString(warningStr.c_str()); } } - -void runWebSocketTest() -{ - auto scene = Scene::create(); - auto layer = new (std::nothrow) WebSocketTestLayer(); - scene->addChild(layer); - - Director::getInstance()->replaceScene(scene); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h index c11beb2a45..6676cc3d6b 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h @@ -12,26 +12,31 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "network/WebSocket.h" +#include "BaseTest.h" -class WebSocketTestLayer -: public cocos2d::Layer +DEFINE_TEST_SUITE(WebSocketTests); + +class WebSocketTest : public TestCase , public cocos2d::network::WebSocket::Delegate { public: - WebSocketTestLayer(); - virtual ~WebSocketTestLayer(); + CREATE_FUNC(WebSocketTest); + + WebSocketTest(); + virtual ~WebSocketTest(); virtual void onOpen(cocos2d::network::WebSocket* ws); virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data); virtual void onClose(cocos2d::network::WebSocket* ws); virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error); - void toExtensionsMainLayer(cocos2d::Ref *sender); - // Menu Callbacks void onMenuSendTextClicked(cocos2d::Ref *sender); void onMenuSendBinaryClicked(cocos2d::Ref *sender); + virtual std::string title() const override { return "WebSocket Test"; } + void startTestCallback(Ref* sender); + private: cocos2d::network::WebSocket* _wsiSendText; cocos2d::network::WebSocket* _wsiSendBinary; @@ -40,11 +45,10 @@ private: cocos2d::Label* _sendTextStatus; cocos2d::Label* _sendBinaryStatus; cocos2d::Label* _errorStatus; + cocos2d::Menu* _startTestMenu; int _sendTextTimes; int _sendBinaryTimes; }; -void runWebSocketTest(); - #endif /* defined(__TestCpp__WebSocketTest__) */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp index d56c7d28a8..22e9ab4bc5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp @@ -8,6 +8,11 @@ USING_NS_CC; +NotificationCenterTests::NotificationCenterTests() +{ + ADD_TEST_CASE(NotificationCenterTest); +} + class Light : public Sprite { public: @@ -80,12 +85,6 @@ NotificationCenterTest::NotificationCenterTest() { auto s = Director::getInstance()->getWinSize(); - auto pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(NotificationCenterTest::toExtensionsMainLayer, this)); - pBackItem->setPosition(Vec2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); - auto pBackMenu = Menu::create(pBackItem, nullptr); - pBackMenu->setPosition( Vec2::ZERO ); - addChild(pBackMenu); - auto label1 = Label::createWithTTF("switch off", "fonts/Marker Felt.ttf", 26); auto label2 = Label::createWithTTF("switch on", "fonts/Marker Felt.ttf", 26); auto item1 = MenuItemLabel::create(label1); @@ -132,15 +131,11 @@ NotificationCenterTest::NotificationCenterTest() NotificationCenter::getInstance()->addObserver(this, CC_CALLFUNCO_SELECTOR(NotificationCenterTest::doNothing), "random-observer3", nullptr); } -void NotificationCenterTest::toExtensionsMainLayer(cocos2d::Ref* sender) +NotificationCenterTest::~NotificationCenterTest() { /* 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(); } void NotificationCenterTest::toggleSwitch(Ref *sender) @@ -162,12 +157,3 @@ void NotificationCenterTest::doNothing(cocos2d::Ref *sender) { } - -void runNotificationCenterTest() -{ - auto scene = Scene::create(); - NotificationCenterTest* layer = new (std::nothrow) NotificationCenterTest(); - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.h b/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.h index 1bfa9ca7cc..8ffea0b56f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.h @@ -1,18 +1,21 @@ #ifndef __NOTIFICATIONCENTERTEST_H__ #define __NOTIFICATIONCENTERTEST_H__ -#include "cocos2d.h" +#include "BaseTest.h" -class NotificationCenterTest : public cocos2d::Layer +DEFINE_TEST_SUITE(NotificationCenterTests); + +class NotificationCenterTest : public TestCase { public: + CREATE_FUNC(NotificationCenterTest); + NotificationCenterTest(); - void toExtensionsMainLayer(cocos2d::Ref* sender); + ~NotificationCenterTest(); + void toggleSwitch(cocos2d::Ref *sender); void connectToSwitch(cocos2d::Ref *sender); void doNothing(cocos2d::Ref *sender); }; -void runNotificationCenterTest(); - #endif /* __NOTIFICATIONCENTERTEST_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp index 4df52f2789..77c1d6e34e 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp @@ -5,18 +5,15 @@ USING_NS_CC; USING_NS_CC_EXT; -void runTableViewTest() +TableViewTests::TableViewTests() { - Scene *scene = Scene::create(); - TableViewTestLayer *layer = TableViewTestLayer::create(); - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); + ADD_TEST_CASE(TableViewTest); } // on "init" you need to initialize your instance -bool TableViewTestLayer::init() +bool TableViewTest::init() { - if ( !Layer::init() ) + if ( !TestCase::init() ) { return false; } @@ -38,29 +35,15 @@ bool TableViewTestLayer::init() this->addChild(tableView); tableView->reloadData(); - // Back Menu - MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(TableViewTestLayer::toExtensionsMainLayer, this)); - itemBack->setPosition(Vec2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); - Menu *menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); - return true; } -void TableViewTestLayer::toExtensionsMainLayer(cocos2d::Ref *sender) -{ - ExtensionsTestScene *scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); -} - -void TableViewTestLayer::tableCellTouched(TableView* table, TableViewCell* cell) +void TableViewTest::tableCellTouched(TableView* table, TableViewCell* cell) { CCLOG("cell touched at index: %ld", cell->getIdx()); } -Size TableViewTestLayer::tableCellSizeForIndex(TableView *table, ssize_t idx) +Size TableViewTest::tableCellSizeForIndex(TableView *table, ssize_t idx) { if (idx == 2) { return Size(100, 100); @@ -68,7 +51,7 @@ Size TableViewTestLayer::tableCellSizeForIndex(TableView *table, ssize_t idx) return Size(60, 60); } -TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, ssize_t idx) +TableViewCell* TableViewTest::tableCellAtIndex(TableView *table, ssize_t idx) { auto string = String::createWithFormat("%ld", idx); TableViewCell *cell = table->dequeueCell(); @@ -96,7 +79,7 @@ TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, ssize_t id return cell; } -ssize_t TableViewTestLayer::numberOfCellsInTableView(TableView *table) +ssize_t TableViewTest::numberOfCellsInTableView(TableView *table) { return 20; } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h index 5915b34b3a..286c185a51 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h @@ -3,17 +3,16 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" +#include "BaseTest.h" -void runTableViewTest(); +DEFINE_TEST_SUITE(TableViewTests); -class TableViewTestLayer : public cocos2d::Layer, public cocos2d::extension::TableViewDataSource, public cocos2d::extension::TableViewDelegate +class TableViewTest : public TestCase, public cocos2d::extension::TableViewDataSource, public cocos2d::extension::TableViewDelegate { public: - virtual bool init() override; - - void toExtensionsMainLayer(cocos2d::Ref *sender); + CREATE_FUNC(TableViewTest); - CREATE_FUNC(TableViewTestLayer); + virtual bool init() override; virtual void scrollViewDidScroll(cocos2d::extension::ScrollView* view) {}; virtual void scrollViewDidZoom(cocos2d::extension::ScrollView* view) {} diff --git a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp index cc36d8aa0c..092beda456 100644 --- a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -1,97 +1,14 @@ #include "FileUtilsTest.h" -static std::function createFunctions[] = { - CL(TestResolutionDirectories), - CL(TestSearchPath), - CL(TestFilenameLookup), - CL(TestIsFileExist), - CL(TestFileFuncs), - CL(TestDirectoryFuncs), - CL(TextWritePlist), -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() +FileUtilsTests::FileUtilsTests() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void FileUtilsTestScene::runThisTest() -{ - auto layer = nextAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -// FileUtilsDemo - -void FileUtilsDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void FileUtilsDemo::backCallback(Ref* sender) -{ - auto scene = new (std::nothrow) FileUtilsTestScene(); - auto layer = backAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void FileUtilsDemo::nextCallback(Ref* sender) -{ - auto scene = new (std::nothrow) FileUtilsTestScene(); - auto layer = nextAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void FileUtilsDemo::restartCallback(Ref* sender) -{ - auto scene = new (std::nothrow) FileUtilsTestScene(); - auto layer = restartAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -std::string FileUtilsDemo::title() const -{ - return "No title"; -} - -std::string FileUtilsDemo::subtitle() const -{ - return ""; + ADD_TEST_CASE(TestResolutionDirectories); + ADD_TEST_CASE(TestSearchPath); + ADD_TEST_CASE(TestFilenameLookup); + ADD_TEST_CASE(TestIsFileExist); + ADD_TEST_CASE(TestFileFuncs); + ADD_TEST_CASE(TestDirectoryFuncs); + ADD_TEST_CASE(TextWritePlist); } // TestResolutionDirectories diff --git a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.h b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.h index ee0969cfb6..5eee31c272 100644 --- a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.h +++ b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.h @@ -1,26 +1,15 @@ #ifndef __FILEUTILSTEST_H__ #define __FILEUTILSTEST_H__ -#include "../testBasic.h" #include "../BaseTest.h" USING_NS_CC; -class FileUtilsTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(FileUtilsTests); -class FileUtilsDemo : public BaseTest +class FileUtilsDemo : public TestCase { public: - virtual void onEnter() override; - virtual std::string title() const override; - virtual std::string subtitle() const override; - void backCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void restartCallback(Ref* sender) override; }; class TestResolutionDirectories : public FileUtilsDemo diff --git a/tests/cpp-tests/Classes/FontTest/FontTest.cpp b/tests/cpp-tests/Classes/FontTest/FontTest.cpp index 69e3dff26e..e79bcbc3ed 100644 --- a/tests/cpp-tests/Classes/FontTest/FontTest.cpp +++ b/tests/cpp-tests/Classes/FontTest/FontTest.cpp @@ -12,8 +12,6 @@ enum { kTagColor3, }; -static int fontIdx = 0; - //you don't need any ifdef anymore static std::string fontList[] = { @@ -25,7 +23,13 @@ static std::string fontList[] = "fonts/Scissor Cuts.ttf", }; -static int fontCount = sizeof(fontList) / sizeof(*fontList); +FontTests::FontTests() +{ + for (auto& fontFile : fontList) + { + addTestCase("FontTests", [&](){return FontTest::create(fontFile); }); + } +} static int vAlignIdx = 0; static TextVAlignment verticalAlignment[] = @@ -34,44 +38,8 @@ static TextVAlignment verticalAlignment[] = TextVAlignment::CENTER, TextVAlignment::BOTTOM, }; -static int vAlignCount = sizeof(verticalAlignment) / sizeof(*verticalAlignment); -static const char* nextAction(void) -{ - fontIdx++; - if(fontIdx >= fontCount) { - fontIdx = 0; - vAlignIdx = (vAlignIdx + 1) % vAlignCount; - } - return fontList[fontIdx].c_str(); -} - -static const char* backAction(void) -{ - fontIdx--; - if( fontIdx < 0 ) { - fontIdx = fontCount - 1; - vAlignIdx--; - if(vAlignIdx < 0) - vAlignIdx = vAlignCount - 1; - } - - return fontList[fontIdx].c_str(); -} - -static const char* restartAction(void) -{ - return fontList[fontIdx].c_str(); -} - - -FontTest::FontTest() -: BaseTest() -{ - showFont(restartAction()); -} - -void FontTest::showFont(const char *pFont) +void FontTest::showFont(const std::string& fontFile) { auto s = Director::getInstance()->getWinSize(); @@ -86,12 +54,12 @@ void FontTest::showFont(const char *pFont) removeChildByTag(kTagColor2, true); removeChildByTag(kTagColor3, true); - auto top = Label::createWithSystemFont(pFont, pFont, 24); - auto left = Label::createWithSystemFont("alignment left", pFont, fontSize, + auto top = Label::createWithSystemFont(fontFile, fontFile, 24); + auto left = Label::createWithSystemFont("alignment left", fontFile, fontSize, blockSize, TextHAlignment::LEFT, verticalAlignment[vAlignIdx]); - auto center = Label::createWithSystemFont("alignment center", pFont, fontSize, + auto center = Label::createWithSystemFont("alignment center", fontFile, fontSize, blockSize, TextHAlignment::CENTER, verticalAlignment[vAlignIdx]); - auto right = Label::createWithSystemFont("alignment right", pFont, fontSize, + auto right = Label::createWithSystemFont("alignment right", fontFile, fontSize, blockSize, TextHAlignment::RIGHT, verticalAlignment[vAlignIdx]); auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height); @@ -128,35 +96,7 @@ void FontTest::showFont(const char *pFont) this->addChild(top, 0, kTagLabel4); } -void FontTest::backCallback(Ref* sender) -{ - showFont(backAction()); -} - -void FontTest::nextCallback(Ref* sender) -{ - showFont(nextAction()); -} - std::string FontTest::title() const { return "Font test"; } - -void FontTest::restartCallback(Ref* sender) -{ - showFont(restartAction()); -} - -///--------------------------------------- -// -// DirectorTestScene -// -///--------------------------------------- -void FontTestScene::runThisTest() -{ - auto layer = FontTest::create(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/FontTest/FontTest.h b/tests/cpp-tests/Classes/FontTest/FontTest.h index bd60142caf..18d2c15bb9 100644 --- a/tests/cpp-tests/Classes/FontTest/FontTest.h +++ b/tests/cpp-tests/Classes/FontTest/FontTest.h @@ -2,27 +2,33 @@ #define _FONT_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class FontTestScene : public TestScene +DEFINE_TEST_SUITE(FontTests); + +class FontTest : public TestCase { public: - virtual void runThisTest(); -}; + static FontTest* create(const std::string& fontFile) + { + auto ret = new (std::nothrow) FontTest; + if (ret && ret->init()) + { + ret->showFont(fontFile); + ret->autorelease(); + } + else + { + delete ret; + ret = nullptr; + } -class FontTest : public BaseTest -{ -public: - FontTest(); - void showFont(const char *pFont); + return ret; + } + + void showFont(const std::string& fontFile); - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; virtual std::string title() const override; - - CREATE_FUNC(FontTest); }; #endif // _FONT_TEST_H_ diff --git a/tests/cpp-tests/Classes/InputTest/MouseTest.cpp b/tests/cpp-tests/Classes/InputTest/MouseTest.cpp index 3e2fb291d1..cbbc4ec07e 100644 --- a/tests/cpp-tests/Classes/InputTest/MouseTest.cpp +++ b/tests/cpp-tests/Classes/InputTest/MouseTest.cpp @@ -2,105 +2,10 @@ template std::string tostr(const T& t) { std::ostringstream os; os< createFunctions[] = +MouseTests::MouseTests() { - CL(MouseEventTest), - CL(HideMouseTest) -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextSpriteTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backSpriteTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartSpriteTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - - -//------------------------------------------------------------------ -// -// BaseMouseTest -// -//------------------------------------------------------------------ - -BaseMouseTest::BaseMouseTest(void) -: BaseTest() -{ -} - -BaseMouseTest::~BaseMouseTest(void) -{ -} - -std::string BaseMouseTest::title() const -{ - return "No title"; -} - -std::string BaseMouseTest::subtitle() const -{ - return ""; -} - -void BaseMouseTest::onEnter() -{ - BaseTest::onEnter(); -} - -void BaseMouseTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) MouseTestScene(); - s->addChild(restartSpriteTestAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseMouseTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) MouseTestScene(); - s->addChild( nextSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void BaseMouseTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) MouseTestScene(); - s->addChild( backSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MouseTestScene::runThisTest() -{ - auto layer = nextSpriteTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); + ADD_TEST_CASE(MouseEventTest); + ADD_TEST_CASE(HideMouseTest); } //------------------------------------------------------------------ diff --git a/tests/cpp-tests/Classes/InputTest/MouseTest.h b/tests/cpp-tests/Classes/InputTest/MouseTest.h index 9a597dd428..b0ad1602ce 100644 --- a/tests/cpp-tests/Classes/InputTest/MouseTest.h +++ b/tests/cpp-tests/Classes/InputTest/MouseTest.h @@ -2,29 +2,14 @@ #define __MOUSE_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class BaseMouseTest : public BaseTest -{ -public: - BaseMouseTest(void); - virtual ~BaseMouseTest(void); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - // overrides - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; -}; +DEFINE_TEST_SUITE(MouseTests); -class MouseTestScene : public TestScene +class BaseMouseTest : public TestCase { public: - virtual void runThisTest(); + }; class MouseEventTest : public BaseMouseTest diff --git a/tests/cpp-tests/Classes/IntervalTest/IntervalTest.cpp b/tests/cpp-tests/Classes/IntervalTest/IntervalTest.cpp index 4fade5cffc..7acdd12ea8 100644 --- a/tests/cpp-tests/Classes/IntervalTest/IntervalTest.cpp +++ b/tests/cpp-tests/Classes/IntervalTest/IntervalTest.cpp @@ -7,7 +7,12 @@ #define IDC_PAUSE 200 -IntervalLayer::IntervalLayer() +IntervalTests::IntervalTests() +{ + ADD_TEST_CASE(IntervalTest); +} + +IntervalTest::IntervalTest() { _time0 = _time1 = _time2 = _time3 = _time4 = 0.0f; @@ -94,7 +99,7 @@ IntervalLayer::IntervalLayer() addChild( menu ); } -IntervalLayer::~IntervalLayer() +IntervalTest::~IntervalTest() { if(Director::getInstance()->isPaused()) { @@ -102,19 +107,10 @@ IntervalLayer::~IntervalLayer() } } -void IntervalLayer::update(float dt) +void IntervalTest::update(float dt) { _time0 +=dt; char time[10] = {0}; sprintf(time, "%2.1f", _time0); _label0->setString(time); } - -void IntervalTestScene::runThisTest() -{ - auto layer = new (std::nothrow) IntervalLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/IntervalTest/IntervalTest.h b/tests/cpp-tests/Classes/IntervalTest/IntervalTest.h index 1ef8ca483b..daa28dba1f 100644 --- a/tests/cpp-tests/Classes/IntervalTest/IntervalTest.h +++ b/tests/cpp-tests/Classes/IntervalTest/IntervalTest.h @@ -1,13 +1,16 @@ #ifndef _INTERVAL_TEST_H_ #define _INTERVAL_TEST_H_ -#include "../testBasic.h" +#include "../BaseTest.h" -class IntervalLayer : public Layer +DEFINE_TEST_SUITE(IntervalTests); + +class IntervalTest : public TestCase { public: - IntervalLayer(void); - virtual ~IntervalLayer(); + CREATE_FUNC(IntervalTest); + IntervalTest(); + virtual ~IntervalTest(); virtual void update(float dt) override; @@ -23,10 +26,4 @@ protected: float _time0, _time1, _time2, _time3, _time4; }; -class IntervalTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp index 5fd0dd878e..c09d00f812 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTest.cpp @@ -29,138 +29,41 @@ enum { kTagSprite8, }; -//------------------------------------------------------------------ -// -// AtlasDemo -// -//------------------------------------------------------------------ - -enum +LabelTests::LabelTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -Layer* nextAtlasAction(); -Layer* backAtlasAction(); -Layer* restartAtlasAction(); - -static int sceneIdx = -1; - -static std::function createFunctions[] = -{ - CL(LabelAtlasTest), - CL(LabelAtlasColorTest), - CL(Atlas3), - CL(Atlas4), - CL(Atlas5), - CL(Atlas6), - CL(AtlasBitmapColor), - CL(AtlasFastBitmap), - CL(BitmapFontMultiLine), - CL(LabelsEmpty), - CL(LabelBMFontHD), - CL(LabelAtlasHD), - CL(LabelGlyphDesigner), - CL(LabelTTFTest), - CL(LabelTTFMultiline), - CL(LabelTTFChinese), - CL(LabelBMFontChinese), - CL(BitmapFontMultiLineAlignment), - CL(LabelTTFOpacityTest), - CL(BMFontOneAtlas), - CL(BMFontUnicode), - CL(BMFontInit), - CL(TTFFontInit), - CL(Issue1343), - CL(LabelTTFAlignment), - CL(LabelBMFontBounds), - CL(TTFFontShadowAndStroke), + ADD_TEST_CASE(LabelAtlasTest); + ADD_TEST_CASE(LabelAtlasColorTest); + ADD_TEST_CASE(Atlas3); + ADD_TEST_CASE(Atlas4); + ADD_TEST_CASE(Atlas5); + ADD_TEST_CASE(Atlas6); + ADD_TEST_CASE(AtlasBitmapColor); + ADD_TEST_CASE(AtlasFastBitmap); + ADD_TEST_CASE(BitmapFontMultiLine); + ADD_TEST_CASE(LabelsEmpty); + ADD_TEST_CASE(LabelBMFontHD); + ADD_TEST_CASE(LabelAtlasHD); + ADD_TEST_CASE(LabelGlyphDesigner); + ADD_TEST_CASE(LabelTTFTest); + ADD_TEST_CASE(LabelTTFMultiline); + ADD_TEST_CASE(LabelTTFChinese); + ADD_TEST_CASE(LabelBMFontChinese); + ADD_TEST_CASE(BitmapFontMultiLineAlignment); + ADD_TEST_CASE(LabelTTFOpacityTest); + ADD_TEST_CASE(BMFontOneAtlas); + ADD_TEST_CASE(BMFontUnicode); + ADD_TEST_CASE(BMFontInit); + ADD_TEST_CASE(TTFFontInit); + ADD_TEST_CASE(Issue1343); + ADD_TEST_CASE(LabelTTFAlignment); + ADD_TEST_CASE(LabelBMFontBounds); + ADD_TEST_CASE(TTFFontShadowAndStroke); // should be moved to another test - CL(Atlas1), - CL(LabelBMFontCrashTest), - CL(LabelBMFontBinaryFormat), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextAtlasAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(Atlas1); + ADD_TEST_CASE(LabelBMFontCrashTest); + ADD_TEST_CASE(LabelBMFontBinaryFormat); } -Layer* backAtlasAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartAtlasAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - - -AtlasDemo::AtlasDemo(void) -{ -} - -AtlasDemo::~AtlasDemo(void) -{ -} - -std::string AtlasDemo::title() const -{ - return "No title"; -} - -std::string AtlasDemo::subtitle() const -{ - return ""; -} - -void AtlasDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void AtlasDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestScene(); - s->addChild(restartAtlasAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void AtlasDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestScene(); - s->addChild( nextAtlasAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void AtlasDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestScene(); - s->addChild( backAtlasAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - - //------------------------------------------------------------------ // // Atlas1 @@ -916,15 +819,6 @@ std::string LabelGlyphDesigner::subtitle() const return "You should see a font with shawdows and outline"; } -void AtlasTestScene::runThisTest() -{ - sceneIdx = -1; - auto layer = nextAtlasAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - //------------------------------------------------------------------ // // LabelTTFTest diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTest.h b/tests/cpp-tests/Classes/LabelTest/LabelTest.h index 660e07768b..8a6699fc78 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTest.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTest.h @@ -1,7 +1,6 @@ #ifndef _ATLAS_TEST_H_ #define _ATLAS_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) @@ -11,23 +10,11 @@ #pragma warning (disable: 4996) #endif -class AtlasDemo : public BaseTest +DEFINE_TEST_SUITE(LabelTests); + +class AtlasDemo : public TestCase { -protected: - public: - CREATE_FUNC(AtlasDemo); - - AtlasDemo(void); - ~AtlasDemo(void); - - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; @@ -209,14 +196,6 @@ public: virtual std::string subtitle() const override; }; -class AtlasTestScene : public TestScene -{ -public: - CREATE_FUNC(AtlasTestScene); - - virtual void runThisTest(); -}; - class LabelTTFTest : public AtlasDemo { public: @@ -281,9 +260,9 @@ public: virtual std::string subtitle() const override; void stringChanged(Ref *sender); void alignmentChanged(Ref *sender); - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); public: LabelBMFont *_labelShouldRetain; diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 953436c221..931d016ff0 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -30,150 +30,52 @@ enum { // //------------------------------------------------------------------ -enum +NewLabelTests::NewLabelTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART + ADD_TEST_CASE(LabelFNTColorAndOpacity); + ADD_TEST_CASE(LabelFNTSpriteActions); + ADD_TEST_CASE(LabelFNTPadding); + ADD_TEST_CASE(LabelFNTOffset); + ADD_TEST_CASE(LabelFNTColor); + ADD_TEST_CASE(LabelFNTHundredLabels); + ADD_TEST_CASE(LabelFNTMultiLine); + ADD_TEST_CASE(LabelFNTandTTFEmpty); + ADD_TEST_CASE(LabelFNTRetina); + ADD_TEST_CASE(LabelFNTGlyphDesigner); + ADD_TEST_CASE(LabelTTFUnicodeChinese); + ADD_TEST_CASE(LabelFNTUnicodeChinese); + ADD_TEST_CASE(LabelFNTMultiLineAlignment); + ADD_TEST_CASE(LabelFNTUNICODELanguages); + ADD_TEST_CASE(LabelTTFAlignmentNew); + ADD_TEST_CASE(LabelFNTBounds); + ADD_TEST_CASE(LabelTTFLongLineWrapping); + ADD_TEST_CASE(LabelTTFColor); + ADD_TEST_CASE(LabelTTFFontsTestNew); + ADD_TEST_CASE(LabelTTFDynamicAlignment); + ADD_TEST_CASE(LabelTTFCJKWrappingTest); + ADD_TEST_CASE(LabelTTFUnicodeNew); + ADD_TEST_CASE(LabelBMFontTestNew); + ADD_TEST_CASE(LabelTTFDistanceField); + ADD_TEST_CASE(LabelOutlineAndGlowTest); + ADD_TEST_CASE(LabelShadowTest); + ADD_TEST_CASE(LabelCharMapTest); + ADD_TEST_CASE(LabelCharMapColorTest); + ADD_TEST_CASE(LabelCrashTest); + ADD_TEST_CASE(LabelTTFOldNew); + ADD_TEST_CASE(LabelFontNameTest); + ADD_TEST_CASE(LabelAlignmentTest); + ADD_TEST_CASE(LabelIssue4428Test); + ADD_TEST_CASE(LabelIssue4999Test); + ADD_TEST_CASE(LabelLineHeightTest); + ADD_TEST_CASE(LabelAdditionalKerningTest); + ADD_TEST_CASE(LabelIssue8492Test); + ADD_TEST_CASE(LabelMultilineWithOutline); + ADD_TEST_CASE(LabelIssue9255Test); + ADD_TEST_CASE(LabelSmallDimensionsTest); + ADD_TEST_CASE(LabelIssue10089Test); + ADD_TEST_CASE(LabelSystemFontColor); }; -Layer* nextAtlasActionNew(); -Layer* backAtlasActionNew(); -Layer* restartAtlasActionNew(); - -static int sceneIdx = -1; - -static std::function createFunctions[] = -{ - CL(LabelFNTColorAndOpacity), - CL(LabelFNTSpriteActions), - CL(LabelFNTPadding), - CL(LabelFNTOffset), - CL(LabelFNTColor), - CL(LabelFNTHundredLabels), - CL(LabelFNTMultiLine), - CL(LabelFNTandTTFEmpty), - CL(LabelFNTRetina), - CL(LabelFNTGlyphDesigner), - CL(LabelTTFUnicodeChinese), - CL(LabelFNTUnicodeChinese), - CL(LabelFNTMultiLineAlignment), - CL(LabelFNTUNICODELanguages), - CL(LabelTTFAlignmentNew), - CL(LabelFNTBounds), - CL(LabelTTFLongLineWrapping), - CL(LabelTTFColor), - CL(LabelTTFFontsTestNew), - CL(LabelTTFDynamicAlignment), - CL(LabelTTFCJKWrappingTest), - CL(LabelTTFUnicodeNew), - CL(LabelBMFontTestNew), - CL(LabelTTFDistanceField), - CL(LabelOutlineAndGlowTest), - CL(LabelShadowTest), - CL(LabelCharMapTest), - CL(LabelCharMapColorTest), - CL(LabelCrashTest), - CL(LabelTTFOldNew), - CL(LabelFontNameTest), - CL(LabelAlignmentTest), - CL(LabelIssue4428Test), - CL(LabelIssue4999Test), - CL(LabelLineHeightTest), - CL(LabelAdditionalKerningTest), - CL(LabelIssue8492Test), - CL(LabelMultilineWithOutline), - CL(LabelIssue9255Test), - CL(LabelSmallDimensionsTest), - CL(LabelIssue10089Test), - CL(LabelSystemFontColor) -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextAtlasActionNew() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* backAtlasActionNew() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartAtlasActionNew() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void AtlasTestSceneNew::runThisTest() -{ - sceneIdx = -1; - auto layer = nextAtlasActionNew(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -AtlasDemoNew::AtlasDemoNew(void) -{ -} - -AtlasDemoNew::~AtlasDemoNew(void) -{ -} - -std::string AtlasDemoNew::title() const -{ - return "No title"; -} - -std::string AtlasDemoNew::subtitle() const -{ - return ""; -} - -void AtlasDemoNew::onEnter() -{ - BaseTest::onEnter(); -} - -void AtlasDemoNew::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestSceneNew(); - s->addChild(restartAtlasActionNew()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void AtlasDemoNew::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestSceneNew(); - s->addChild( nextAtlasActionNew() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void AtlasDemoNew::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) AtlasTestSceneNew(); - s->addChild( backAtlasActionNew() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - LabelTTFAlignmentNew::LabelTTFAlignmentNew() { auto s = Director::getInstance()->getWinSize(); diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 61d56b9253..375c862160 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -1,29 +1,14 @@ #ifndef _ATLAS_TEST_NEW_H_ #define _ATLAS_TEST_NEW_H_ -#include "../testBasic.h" #include "../BaseTest.h" #include "renderer/CCCustomCommand.h" #include "ui/CocosGUI.h" +DEFINE_TEST_SUITE(NewLabelTests); -class AtlasDemoNew : public BaseTest +class AtlasDemoNew : public TestCase { -protected: - -public: - CREATE_FUNC(AtlasDemoNew); - - AtlasDemoNew(void); - ~AtlasDemoNew(void); - - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class LabelTTFAlignmentNew : public AtlasDemoNew @@ -149,14 +134,6 @@ public: virtual std::string subtitle() const override; }; -class AtlasTestSceneNew : public TestScene -{ -public: - CREATE_FUNC(AtlasTestSceneNew); - - virtual void runThisTest(); -}; - class LabelTTFUnicodeChinese : public AtlasDemoNew { public: @@ -189,9 +166,9 @@ public: virtual std::string subtitle() const override; void stringChanged(Ref *sender); void alignmentChanged(Ref *sender); - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); public: Label *_labelShouldRetain; diff --git a/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp b/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp index 808efe7dc5..14fedb470e 100644 --- a/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp +++ b/tests/cpp-tests/Classes/LayerTest/LayerTest.cpp @@ -6,111 +6,29 @@ enum kTagLayer = 1, }; -static std::function createFunctions[] = { - CL(LayerTestCascadingOpacityA), - CL(LayerTestCascadingOpacityB), - CL(LayerTestCascadingOpacityC), - CL(LayerTestCascadingColorA), - CL(LayerTestCascadingColorB), - CL(LayerTestCascadingColorC), - CL(LayerTest1), - CL(LayerTest2), - CL(LayerTestBlend), - CL(LayerGradientTest), - CL(LayerGradientTest2), - CL(LayerGradientTest3), - CL(LayerIgnoreAnchorPointPos), - CL(LayerIgnoreAnchorPointRot), - CL(LayerIgnoreAnchorPointScale), - CL(LayerExtendedBlendOpacityTest), - CL(LayerBug3162A), - CL(LayerBug3162B), - CL(LayerColorOccludeBug), -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() +LayerTests::LayerTests() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(LayerTestCascadingOpacityA); + ADD_TEST_CASE(LayerTestCascadingOpacityB); + ADD_TEST_CASE(LayerTestCascadingOpacityC); + ADD_TEST_CASE(LayerTestCascadingColorA); + ADD_TEST_CASE(LayerTestCascadingColorB); + ADD_TEST_CASE(LayerTestCascadingColorC); + ADD_TEST_CASE(LayerTest1); + ADD_TEST_CASE(LayerTest2); + ADD_TEST_CASE(LayerTestBlend); + ADD_TEST_CASE(LayerGradientTest); + ADD_TEST_CASE(LayerGradientTest2); + ADD_TEST_CASE(LayerGradientTest3); + ADD_TEST_CASE(LayerIgnoreAnchorPointPos); + ADD_TEST_CASE(LayerIgnoreAnchorPointRot); + ADD_TEST_CASE(LayerIgnoreAnchorPointScale); + ADD_TEST_CASE(LayerExtendedBlendOpacityTest); + ADD_TEST_CASE(LayerBug3162A); + ADD_TEST_CASE(LayerBug3162B); + ADD_TEST_CASE(LayerColorOccludeBug); } -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -//------------------------------------------------------------------ -// -// LayerTest -// -//------------------------------------------------------------------ - -LayerTest::LayerTest(void) -{ -} - -LayerTest::~LayerTest(void) -{ -} - -std::string LayerTest::subtitle() const -{ - return ""; -} - -std::string LayerTest::title() const -{ - return "Layer Test"; -} - -void LayerTest::onEnter() -{ - BaseTest::onEnter(); -} - -void LayerTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) LayerTestScene(); - s->addChild(restartAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void LayerTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) LayerTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void LayerTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) LayerTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - // Cascading support extensions static void setEnableRecursiveCascading(Node* node, bool enable) @@ -823,15 +741,6 @@ std::string LayerIgnoreAnchorPointScale::subtitle() const return "Ignoring Anchor Vec2 for scale"; } -void LayerTestScene::runThisTest() -{ - sceneIdx = -1; - auto layer = nextAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - LayerExtendedBlendOpacityTest::LayerExtendedBlendOpacityTest() { auto layer1 = LayerGradient::create(Color4B(255, 0, 0, 255), Color4B(255, 0, 255, 255)); diff --git a/tests/cpp-tests/Classes/LayerTest/LayerTest.h b/tests/cpp-tests/Classes/LayerTest/LayerTest.h index ed2e8f5905..a788776ad1 100644 --- a/tests/cpp-tests/Classes/LayerTest/LayerTest.h +++ b/tests/cpp-tests/Classes/LayerTest/LayerTest.h @@ -1,26 +1,14 @@ #ifndef _LAYER_TEST_H_ #define _LAYER_TEST_H_ -////----#include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class LayerTest : public BaseTest +DEFINE_TEST_SUITE(LayerTests); + +class LayerTest : public TestCase { protected: std::string _title; - -public: - LayerTest(void); - ~LayerTest(void); - - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class LayerTestCascadingOpacityA : public LayerTest @@ -82,9 +70,9 @@ public: void updateSize(Vec2 &touchLocation); - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); }; class LayerTest2 : public LayerTest @@ -215,10 +203,4 @@ private: LayerColor* _layer; }; -class LayerTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/LightTest/LightTest.cpp b/tests/cpp-tests/Classes/LightTest/LightTest.cpp index 6d15d2f5ed..b3f446a579 100644 --- a/tests/cpp-tests/Classes/LightTest/LightTest.cpp +++ b/tests/cpp-tests/Classes/LightTest/LightTest.cpp @@ -1,39 +1,8 @@ #include "LightTest.h" -static int sceneIdx = -1; - - -static std::function createFunctions[] = +LightTests::LightTests() { - CL(LightTest) -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextSpriteTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backSpriteTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartSpriteTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(LightTest); } LightTest::LightTest() @@ -108,45 +77,6 @@ std::string LightTest::title() const return "Light Test"; } -std::string LightTest::subtitle() const -{ - return ""; -} - -void LightTest::restartCallback( Ref* sender ) -{ - auto s = new LightTestScene(); - s->addChild(restartSpriteTestAction()); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void LightTest::nextCallback( Ref* sender ) -{ - auto s = new LightTestScene(); - s->addChild( nextSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void LightTest::backCallback( Ref* sender ) -{ - auto s = new LightTestScene(); - s->addChild( backSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void LightTest::onEnter() -{ - BaseTest::onEnter(); -} - -void LightTest::onExit() -{ - BaseTest::onExit(); -} - void LightTest::addSprite() { auto s = Director::getInstance()->getWinSize(); @@ -297,7 +227,7 @@ void LightTest::update( float delta ) angleDelta += delta; - BaseTest::update(delta); + TestCase::update(delta); } void LightTest::SwitchLight( Ref* sender, LightType lightType ) @@ -348,15 +278,3 @@ void LightTest::SwitchLight( Ref* sender, LightType lightType ) break; } } - -void LightTestScene::runThisTest() -{ - auto layer = nextSpriteTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -LightTestScene::LightTestScene() -{ -} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/LightTest/LightTest.h b/tests/cpp-tests/Classes/LightTest/LightTest.h index e3c73ca718..05a184f4e5 100644 --- a/tests/cpp-tests/Classes/LightTest/LightTest.h +++ b/tests/cpp-tests/Classes/LightTest/LightTest.h @@ -25,10 +25,11 @@ #ifndef _LIGHT_TEST_H_ #define _LIGHT_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" -class LightTest : public BaseTest +DEFINE_TEST_SUITE(LightTests); + +class LightTest : public TestCase { public: CREATE_FUNC(LightTest); @@ -36,14 +37,6 @@ public: virtual ~LightTest(); virtual std::string title() const override; - virtual std::string subtitle() const override; - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; - - virtual void onEnter() override; - virtual void onExit() override; virtual void update(float delta) override; @@ -67,12 +60,5 @@ private: Label *_spotLightLabel; }; -class LightTestScene : public TestScene -{ -public: - LightTestScene(); - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/MenuTest/MenuTest.cpp b/tests/cpp-tests/Classes/MenuTest/MenuTest.cpp index 62c366d1e8..44c1c22934 100644 --- a/tests/cpp-tests/Classes/MenuTest/MenuTest.cpp +++ b/tests/cpp-tests/Classes/MenuTest/MenuTest.cpp @@ -43,6 +43,10 @@ enum { #define MID_CALLBACK3 1008 #define MID_BACKCALLBACK 1009 +MenuTests::MenuTests() +{ + ADD_TEST_CASE(MenuTest); +} //------------------------------------------------------------------ // // MenuLayerMainMenu @@ -561,26 +565,31 @@ void RemoveMenuItemWhenMove::onTouchMoved(Touch *touch, Event *event) } } -void MenuTestScene::runThisTest() +bool MenuTest::init() { - MenuItemFont::setFontSize(20); - - auto layer1 = new (std::nothrow) MenuLayerMainMenu(); - auto layer2 = new (std::nothrow) MenuLayer2(); - auto layer3 = new (std::nothrow) MenuLayer3(); - auto layer4 = new (std::nothrow) MenuLayer4(); - auto layer5 = new (std::nothrow) BugsTest(); - auto layer6 = new (std::nothrow) RemoveMenuItemWhenMove(); + if (TestCase::init()) + { + MenuItemFont::setFontSize(20); - auto layer = LayerMultiplex::create(layer1, layer2, layer3, layer4, layer5, layer6, nullptr); - addChild(layer, 0); + auto layer1 = new (std::nothrow) MenuLayerMainMenu(); + auto layer2 = new (std::nothrow) MenuLayer2(); + auto layer3 = new (std::nothrow) MenuLayer3(); + auto layer4 = new (std::nothrow) MenuLayer4(); + auto layer5 = new (std::nothrow) BugsTest(); + auto layer6 = new (std::nothrow) RemoveMenuItemWhenMove(); - layer1->release(); - layer2->release(); - layer3->release(); - layer4->release(); - layer5->release(); - layer6->release(); + auto layer = LayerMultiplex::create(layer1, layer2, layer3, layer4, layer5, layer6, nullptr); + addChild(layer, 0); - Director::getInstance()->replaceScene(this); + layer1->release(); + layer2->release(); + layer3->release(); + layer4->release(); + layer5->release(); + layer6->release(); + + return true; + } + + return false; } diff --git a/tests/cpp-tests/Classes/MenuTest/MenuTest.h b/tests/cpp-tests/Classes/MenuTest/MenuTest.h index e676b9fe98..eaf99c44d4 100644 --- a/tests/cpp-tests/Classes/MenuTest/MenuTest.h +++ b/tests/cpp-tests/Classes/MenuTest/MenuTest.h @@ -27,7 +27,17 @@ #define _MENU_TEST_H_ ////----#include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" + +DEFINE_TEST_SUITE(MenuTests); + +class MenuTest : public TestCase +{ +public: + CREATE_FUNC(MenuTest); + + virtual bool init() override; +}; class MenuLayerMainMenu : public Layer { @@ -36,7 +46,7 @@ protected: EventListenerTouchOneByOne* _touchListener; public: - MenuLayerMainMenu(void); + MenuLayerMainMenu(); ~MenuLayerMainMenu(); public: @@ -68,10 +78,9 @@ protected: void alignMenusV(); public: - MenuLayer2(void); + MenuLayer2(); ~MenuLayer2(); -public: void menuCallback(Ref* sender); void menuCallbackOpacity(Ref* sender); void menuCallbackAlign(Ref* sender); @@ -85,23 +94,18 @@ protected: MenuItem* _disabledItem; public: - MenuLayer3(void); + MenuLayer3(); ~MenuLayer3(); - - //CREATE_NODE(MenuLayer3); }; class MenuLayer4 : public Layer { public: - MenuLayer4(void); + MenuLayer4(); ~MenuLayer4(); -public: void menuCallback(Ref* sender); void backCallback(Ref* sender); - - //CREATE_NODE(MenuLayer4); }; class BugsTest : public Layer @@ -129,11 +133,4 @@ private: EventListenerTouchOneByOne* _touchListener; }; - -class MenuTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.cpp b/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.cpp index f7aecb34a5..3cc3bb3c67 100644 --- a/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.cpp +++ b/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.cpp @@ -7,46 +7,13 @@ enum { kTagSprite2 = 3, }; -Layer* nextMotionAction(); -Layer* backMotionAction(); -Layer* restartMotionAction(); - -static int sceneIdx = -1; - -static std::function createFunctions[] = +MotionStreakTests::MotionStreakTests() { - CL(MotionStreakTest1), - CL(MotionStreakTest2), - CL(Issue1358), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextMotionAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; + ADD_TEST_CASE(MotionStreakTest1); + ADD_TEST_CASE(MotionStreakTest2); + ADD_TEST_CASE(Issue1358); } -Layer* backMotionAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartMotionAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} //------------------------------------------------------------------ // // MotionStreakTest1 @@ -207,7 +174,7 @@ std::string MotionStreakTest::subtitle() const void MotionStreakTest::onEnter() { - BaseTest::onEnter(); + TestCase::onEnter(); auto s = Director::getInstance()->getWinSize(); @@ -227,36 +194,3 @@ void MotionStreakTest::modeCallback(Ref *pSender) bool fastMode = streak->isFastMode(); streak->setFastMode(! fastMode); } - -void MotionStreakTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) MotionStreakTestScene();//CCScene::create(); - s->addChild(restartMotionAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MotionStreakTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) MotionStreakTestScene();//CCScene::create(); - s->addChild( nextMotionAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MotionStreakTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) MotionStreakTestScene;//CCScene::create(); - s->addChild( backMotionAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MotionStreakTestScene::runThisTest() -{ - auto layer = nextMotionAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.h b/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.h index be78035f82..630c341def 100644 --- a/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.h +++ b/tests/cpp-tests/Classes/MotionStreakTest/MotionStreakTest.h @@ -1,13 +1,13 @@ #ifndef _MOTION_STREAK_TEST_H_ #define _MOTION_STREAK_TEST_H_ -////----#include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" //USING_NS_CC; -class MotionStreakTest : public BaseTest +DEFINE_TEST_SUITE(MotionStreakTests); + +class MotionStreakTest : public TestCase { public: MotionStreakTest(void); @@ -17,9 +17,6 @@ public: virtual std::string subtitle() const override; virtual void onEnter() override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; void modeCallback(Ref* sender); protected: MotionStreak *streak; @@ -47,7 +44,7 @@ protected: public: CREATE_FUNC(MotionStreakTest2); virtual void onEnter() override; - void onTouchesMoved(const std::vector& touches, Event* event) override; + void onTouchesMoved(const std::vector& touches, Event* event); virtual std::string title() const override; }; @@ -66,12 +63,4 @@ private: float _angle; }; -class MotionStreakTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -//CCLayer* nextAction(); - #endif diff --git a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp index 226007b30c..b90a2d731b 100644 --- a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp +++ b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp @@ -1,5 +1,9 @@ #include "MutiTouchTest.h" +MutiTouchTests::MutiTouchTests() +{ + ADD_TEST_CASE(MutiTouchTest); +} static const Color3B* s_TouchColors[5] = { &Color3B::YELLOW, @@ -33,14 +37,14 @@ public: } }; -bool MutiTouchTestLayer::init() +bool MutiTouchTest::init() { - if (Layer::init()) + if (TestCase::init()) { auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(MutiTouchTestLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(MutiTouchTestLayer::onTouchesMoved, this); - listener->onTouchesEnded = CC_CALLBACK_2(MutiTouchTestLayer::onTouchesEnded, this); + listener->onTouchesBegan = CC_CALLBACK_2(MutiTouchTest::onTouchesBegan, this); + listener->onTouchesMoved = CC_CALLBACK_2(MutiTouchTest::onTouchesMoved, this); + listener->onTouchesEnded = CC_CALLBACK_2(MutiTouchTest::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); auto title = Label::createWithSystemFont("Please touch the screen!", "", 24); @@ -54,7 +58,7 @@ bool MutiTouchTestLayer::init() static Map s_map; -void MutiTouchTestLayer::onTouchesBegan(const std::vector& touches, Event *event) +void MutiTouchTest::onTouchesBegan(const std::vector& touches, Event *event) { for ( auto &item: touches ) { @@ -67,7 +71,7 @@ void MutiTouchTestLayer::onTouchesBegan(const std::vector& touches, Even } } -void MutiTouchTestLayer::onTouchesMoved(const std::vector& touches, Event *event) +void MutiTouchTest::onTouchesMoved(const std::vector& touches, Event *event) { for( auto &item: touches) { @@ -84,7 +88,7 @@ void MutiTouchTestLayer::onTouchesMoved(const std::vector& touches, Even } } -void MutiTouchTestLayer::onTouchesEnded(const std::vector& touches, Event *event) +void MutiTouchTest::onTouchesEnded(const std::vector& touches, Event *event) { for ( auto &item: touches ) { @@ -95,16 +99,7 @@ void MutiTouchTestLayer::onTouchesEnded(const std::vector& touches, Even } } -void MutiTouchTestLayer::onTouchesCancelled(const std::vector& touches, Event *event) +void MutiTouchTest::onTouchesCancelled(const std::vector& touches, Event *event) { onTouchesEnded(touches, event); } - -void MutiTouchTestScene::runThisTest() -{ - auto layer = MutiTouchTestLayer::create(); - - addChild(layer, 0); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.h b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.h index 91333d6493..907684ed0c 100644 --- a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.h +++ b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.h @@ -1,25 +1,21 @@ #ifndef __MUTITOUCHTEST_H__ #define __MUTITOUCHTEST_H__ -#include "../testBasic.h" +#include "../BaseTest.h" -class MutiTouchTestLayer : public Layer +DEFINE_TEST_SUITE(MutiTouchTests); + +class MutiTouchTest : public TestCase { public: - bool init(); + CREATE_FUNC(MutiTouchTest); + + virtual bool init() override; void onTouchesBegan(const std::vector& touches, cocos2d::Event *event); void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); void onTouchesCancelled(const std::vector& touches, cocos2d::Event *event); - - CREATE_FUNC(MutiTouchTestLayer) -}; - -class MutiTouchTestScene : public TestScene -{ - public: - virtual void runThisTest(); }; #endif /* __MUTITOUCHTEST_H__ */ diff --git a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp index fb7ba66912..a5a3d34cf4 100644 --- a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp +++ b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp @@ -32,48 +32,17 @@ using namespace cocos2d; using namespace cocos2d::ui; using namespace cocos2d::experimental; +AudioEngineTests::AudioEngineTests() +{ + ADD_TEST_CASE(AudioControlTest); + ADD_TEST_CASE(PlaySimultaneouslyTest); + ADD_TEST_CASE(AudioProfileTest); + ADD_TEST_CASE(InvalidAudioFileTest); + ADD_TEST_CASE(LargeAudioFileTest); +} + namespace { -std::function createFunctions[] = -{ - CL(AudioControlTest), - CL(PlaySimultaneouslyTest), - CL(AudioProfileTest), - CL(InvalidAudioFileTest), - CL(LargeAudioFileTest) -}; - -unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]); - -int s_sceneIdx = -1; -Layer* createTest(int index) -{ - auto layer = (createFunctions[index])();; - return layer; -} - -Layer* nextAction() -{ - s_sceneIdx++; - s_sceneIdx = s_sceneIdx % TEST_CASE_COUNT; - - return createTest(s_sceneIdx); -} - -Layer* backAction() -{ - s_sceneIdx--; - if( s_sceneIdx < 0 ) - s_sceneIdx = TEST_CASE_COUNT -1; - - return createTest(s_sceneIdx); -} - -Layer* restartAction() -{ - return createTest(s_sceneIdx); -} - class TextButton : public cocos2d::Label { public: @@ -291,51 +260,10 @@ Layer* restartAction() }; } -void AudioEngineTestScene::runThisTest() -{ - CCASSERT(AudioEngine::lazyInit(),"Fail to initialize AudioEngine!"); - - s_sceneIdx = -1; - auto layer = nextAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - void AudioEngineTestDemo::onExit() { AudioEngine::stopAll(); - BaseTest::onExit(); -} - -void AudioEngineTestDemo::backCallback(Ref* sender) -{ - auto scene = new AudioEngineTestScene(); - auto layer = backAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void AudioEngineTestDemo::nextCallback(Ref* sender) -{ - auto scene = new AudioEngineTestScene(); - auto layer = nextAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void AudioEngineTestDemo::restartCallback(Ref* sender) -{ - auto scene = new AudioEngineTestScene(); - auto layer = restartAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); + TestCase::onExit(); } std::string AudioEngineTestDemo::title() const diff --git a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h index 55d84e9b34..0589c6ba19 100644 --- a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h +++ b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h @@ -29,28 +29,19 @@ #define __NEWAUDIOENGINE_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #include "audio/include/AudioEngine.h" +DEFINE_TEST_SUITE(AudioEngineTests); + using namespace cocos2d; -class AudioEngineTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -class AudioEngineTestDemo : public BaseTest +class AudioEngineTestDemo : public TestCase { public: virtual std::string title() const override; virtual void onExit() override; - - void backCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void restartCallback(Ref* sender) override; }; diff --git a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index a6b0532442..3c42999518 100644 --- a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -9,108 +9,25 @@ #include "NewEventDispatcherTest.h" #include "testResource.h" -namespace { - -std::function createFunctions[] = +EventDispatcherTests::EventDispatcherTests() { - CL(TouchableSpriteTest), - CL(FixedPriorityTest), - CL(RemoveListenerWhenDispatching), - CL(CustomEventTest), - CL(LabelKeyboardEventTest), - CL(SpriteAccelerationEventTest), - CL(RemoveAndRetainNodeTest), - CL(RemoveListenerAfterAddingTest), - CL(DirectorEventTest), - CL(GlobalZTouchTest), - CL(StopPropagationTest), - CL(PauseResumeTargetTest), - CL(Issue4129), - CL(Issue4160), - CL(DanglingNodePointersTest), - CL(RegisterAndUnregisterWhileEventHanldingTest), - CL(Issue9898) -}; - -unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]); - -int sceneIdx=-1; -Layer* createTest(int index) -{ - auto layer = (createFunctions[index])();; - return layer; -} - -Layer* nextAction(); -Layer* backAction(); -Layer* restartAction(); - -Layer* nextAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % TEST_CASE_COUNT; - - return createTest(sceneIdx); -} - -Layer* backAction() -{ - sceneIdx--; - if( sceneIdx < 0 ) - sceneIdx = TEST_CASE_COUNT -1; - - return createTest(sceneIdx); -} - -Layer* restartAction() -{ - return createTest(sceneIdx); -} - -} - -void EventDispatcherTestScene::runThisTest() -{ - auto layer = nextAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - - -void EventDispatcherTestDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void EventDispatcherTestDemo::backCallback(Ref* sender) -{ - auto scene = new (std::nothrow) EventDispatcherTestScene(); - auto layer = backAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void EventDispatcherTestDemo::nextCallback(Ref* sender) -{ - auto scene = new (std::nothrow) EventDispatcherTestScene(); - auto layer = nextAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void EventDispatcherTestDemo::restartCallback(Ref* sender) -{ - auto scene = new (std::nothrow) EventDispatcherTestScene(); - auto layer = restartAction(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); + ADD_TEST_CASE(TouchableSpriteTest); + ADD_TEST_CASE(FixedPriorityTest); + ADD_TEST_CASE(RemoveListenerWhenDispatching); + ADD_TEST_CASE(CustomEventTest); + ADD_TEST_CASE(LabelKeyboardEventTest); + ADD_TEST_CASE(SpriteAccelerationEventTest); + ADD_TEST_CASE(RemoveAndRetainNodeTest); + ADD_TEST_CASE(RemoveListenerAfterAddingTest); + ADD_TEST_CASE(DirectorEventTest); + ADD_TEST_CASE(GlobalZTouchTest); + ADD_TEST_CASE(StopPropagationTest); + ADD_TEST_CASE(PauseResumeTargetTest); + ADD_TEST_CASE(Issue4129); + ADD_TEST_CASE(Issue4160); + ADD_TEST_CASE(DanglingNodePointersTest); + ADD_TEST_CASE(RegisterAndUnregisterWhileEventHanldingTest); + ADD_TEST_CASE(Issue9898) } std::string EventDispatcherTestDemo::title() const @@ -118,11 +35,6 @@ std::string EventDispatcherTestDemo::title() const return "No title"; } -std::string EventDispatcherTestDemo::subtitle() const -{ - return ""; -} - // TouchableSpriteTest void TouchableSpriteTest::onEnter() { @@ -196,7 +108,7 @@ void TouchableSpriteTest::onEnter() _eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE); auto nextItem = MenuItemFont::create("Next", [=](Ref* sender){ - nextCallback(nullptr); + getTestSuite()->enterNextTest(); }); nextItem->setFontSizeObj(16); @@ -706,7 +618,7 @@ void RemoveListenerAfterAddingTest::onEnter() auto addNextButton = [this](){ auto next = MenuItemFont::create("Please Click Me To Reset!", [this](Ref* sender){ - this->restartCallback(nullptr); + getTestSuite()->restartCurrTest(); }); next->setPosition(VisibleRect::center() + Vec2(0, -40)); @@ -1211,7 +1123,7 @@ Issue4129::Issue4129() auto nextItem = MenuItemFont::create("Reset", [=](Ref* sender){ CCASSERT(_bugFixed, "This issue was not fixed!"); - this->restartCallback(nullptr); + getTestSuite()->restartCurrTest(); }); nextItem->setFontSizeObj(16); diff --git a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h index 34409190c7..4dac328b85 100644 --- a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h +++ b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h @@ -10,24 +10,14 @@ #define __samples__NewEventDispatcherTest__ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class EventDispatcherTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(EventDispatcherTests); -class EventDispatcherTestDemo : public BaseTest +class EventDispatcherTestDemo : public TestCase { public: - virtual void onEnter() override; virtual std::string title() const override; - virtual std::string subtitle() const override; - void backCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void restartCallback(Ref* sender) override; }; diff --git a/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.cpp b/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.cpp index 3071bc6111..dba9232e25 100644 --- a/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.cpp +++ b/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.cpp @@ -22,75 +22,20 @@ THE SOFTWARE. ****************************************************************************/ - #include "NewRendererTest.h" -static int sceneIdx = -1; - -Layer* nextSpriteTestAction(); -Layer* backSpriteTestAction(); -Layer* restartSpriteTestAction(); - -static std::function createFunctions[] = +NewRendererTests::NewRendererTests() { - CL(NewSpriteTest), - CL(NewSpriteBatchTest), - CL(GroupCommandTest), - CL(NewClippingNodeTest), - CL(NewDrawNodeTest), - CL(NewCullingTest), - CL(VBOFullTest), - CL(CaptureScreenTest) + ADD_TEST_CASE(NewSpriteTest); + ADD_TEST_CASE(NewSpriteBatchTest); + ADD_TEST_CASE(GroupCommandTest); + ADD_TEST_CASE(NewClippingNodeTest); + ADD_TEST_CASE(NewDrawNodeTest); + ADD_TEST_CASE(NewCullingTest); + ADD_TEST_CASE(VBOFullTest); + ADD_TEST_CASE(CaptureScreenTest); }; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* prevTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - - return layer; -} - -Layer* restartTest() -{ - auto layer = (createFunctions[sceneIdx])(); - - return layer; -} - -void NewRendererTestScene::runThisTest() -{ - auto layer = nextTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -MultiSceneTest::MultiSceneTest() -{ - -} - -MultiSceneTest::~MultiSceneTest() -{ - -} - std::string MultiSceneTest::title() const { return "New Renderer"; @@ -101,38 +46,6 @@ std::string MultiSceneTest::subtitle() const return "MultiSceneTest"; } -void MultiSceneTest::onEnter() -{ - BaseTest::onEnter(); -} - -void MultiSceneTest::restartCallback(Ref *sender) -{ - auto s = new (std::nothrow) NewRendererTestScene(); - s->addChild(restartTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MultiSceneTest::nextCallback(Ref *sender) -{ - auto s = new (std::nothrow) NewRendererTestScene(); - s->addChild(nextTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void MultiSceneTest::backCallback(Ref *sender) -{ - auto s = new (std::nothrow) NewRendererTestScene(); - s->addChild(prevTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - NewSpriteTest::NewSpriteTest() { auto touchListener = EventListenerTouchAllAtOnce::create(); diff --git a/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.h b/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.h index 3f9019b1e5..58131d3f57 100644 --- a/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.h +++ b/tests/cpp-tests/Classes/NewRendererTest/NewRendererTest.h @@ -1,41 +1,22 @@ -// -// Created by NiTe Luo on 11/1/13. -// - - - #ifndef __NewRendererTest_H_ #define __NewRendererTest_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #define kTagSpriteBatchNode 100 #define kTagClipperNode 101 #define kTagContentNode 102 -class NewRendererTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(NewRendererTests); -class MultiSceneTest : public BaseTest +class MultiSceneTest : public TestCase { public: - CREATE_FUNC(MultiSceneTest); virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; protected: - MultiSceneTest(); - virtual ~MultiSceneTest(); }; @@ -49,7 +30,7 @@ public: void createSpriteTest(); void createNewSpriteTest(); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); protected: NewSpriteTest(); @@ -77,7 +58,7 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void addNewSpriteWithCoords(Vec2 p); protected: @@ -93,9 +74,9 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); protected: NewClippingNodeTest(); diff --git a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp index 24396818ed..e6bafe1bdd 100644 --- a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp +++ b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp @@ -36,74 +36,41 @@ enum }; -Layer* nextCocosNodeAction(); -Layer* backCocosNodeAction(); -Layer* restartCocosNodeAction(); - //------------------------------------------------------------------ // // TestCocosNodeDemo // //------------------------------------------------------------------ -static int sceneIdx = -1; - - -static std::function createFunctions[] = +CocosNodeTests::CocosNodeTests() { - CL(CameraTest1), - // TODO: Camera has been removed from CCNode, add new feature to support it - // CL(CameraTest2), - CL(CameraCenterTest), - CL(Test2), - CL(Test4), - CL(Test5), - CL(Test6), - CL(StressTest1), - CL(StressTest2), - CL(NodeToWorld), - CL(NodeToWorld3D), - CL(SchedulerTest1), - CL(SchedulerCallbackTest), - CL(CameraOrbitTest), - // TODO: Camera has been removed from CCNode, add new feature to support it - //CL(CameraZoomTest), - CL(ConvertToNode), - CL(NodeOpaqueTest), - CL(NodeNonOpaqueTest), - CL(NodeGlobalZValueTest), - CL(NodeNormalizedPositionTest1), - CL(NodeNormalizedPositionTest2), - CL(NodeNormalizedPositionBugTest), - CL(NodeNameTest), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextCocosNodeAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - return createFunctions[sceneIdx](); + //ADD_TEST_CASE(CameraTest1); + // TODO: Camera has been removed from CCNode; add new feature to support it + // ADD_TEST_CASE(CameraTest2); + //ADD_TEST_CASE(CameraCenterTest); + ADD_TEST_CASE(NodeTest2); + ADD_TEST_CASE(NodeTest4); + ADD_TEST_CASE(NodeTest5); + ADD_TEST_CASE(NodeTest6); + ADD_TEST_CASE(StressTest1); + ADD_TEST_CASE(StressTest2); + ADD_TEST_CASE(NodeToWorld); + ADD_TEST_CASE(NodeToWorld3D); + ADD_TEST_CASE(SchedulerTest1); + ADD_TEST_CASE(SchedulerCallbackTest); + ADD_TEST_CASE(CameraOrbitTest); + // TODO: Camera has been removed from CCNode; add new feature to support it + //ADD_TEST_CASE(CameraZoomTest); + ADD_TEST_CASE(ConvertToNode); + ADD_TEST_CASE(NodeOpaqueTest); + ADD_TEST_CASE(NodeNonOpaqueTest); + ADD_TEST_CASE(NodeGlobalZValueTest); + ADD_TEST_CASE(NodeNormalizedPositionTest1); + ADD_TEST_CASE(NodeNormalizedPositionTest2); + ADD_TEST_CASE(NodeNormalizedPositionBugTest); + ADD_TEST_CASE(NodeNameTest); } -Layer* backCocosNodeAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - return createFunctions[sceneIdx](); -} - -Layer* restartCocosNodeAction() -{ - return createFunctions[sceneIdx](); -} - - TestCocosNodeDemo::TestCocosNodeDemo(void) { } @@ -117,48 +84,13 @@ std::string TestCocosNodeDemo::title() const return "Node Test"; } -std::string TestCocosNodeDemo::subtitle() const -{ - return ""; -} - -void TestCocosNodeDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void TestCocosNodeDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) CocosNodeTestScene();//CCScene::create(); - s->addChild(restartCocosNodeAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TestCocosNodeDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) CocosNodeTestScene();//CCScene::create(); - s->addChild( nextCocosNodeAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TestCocosNodeDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) CocosNodeTestScene();//CCScene::create(); - s->addChild( backCocosNodeAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - - //------------------------------------------------------------------ // -// Test2 +// NodeTest2 // //------------------------------------------------------------------ -void Test2::onEnter() + +void NodeTest2::onEnter() { TestCocosNodeDemo::onEnter(); @@ -197,7 +129,7 @@ void Test2::onEnter() sp2->runAction(action2); } -std::string Test2::subtitle() const +std::string NodeTest2::subtitle() const { return "anchorPoint and children"; } @@ -205,13 +137,13 @@ std::string Test2::subtitle() const //------------------------------------------------------------------ // -// Test4 +// NodeTest4 // //------------------------------------------------------------------ #define SID_DELAY2 1 #define SID_DELAY4 2 -Test4::Test4() +NodeTest4::NodeTest4() { auto sp1 = Sprite::create(s_pathSister1); auto sp2 = Sprite::create(s_pathSister2); @@ -222,24 +154,24 @@ Test4::Test4() addChild(sp1, 0, 2); addChild(sp2, 0, 3); - schedule(CC_CALLBACK_1(Test4::delay2, this), 2.0f, "delay2_key"); - schedule(CC_CALLBACK_1(Test4::delay4, this), 4.0f, "delay4_key"); + schedule(CC_CALLBACK_1(NodeTest4::delay2, this), 2.0f, "delay2_key"); + schedule(CC_CALLBACK_1(NodeTest4::delay4, this), 4.0f, "delay4_key"); } -void Test4::delay2(float dt) +void NodeTest4::delay2(float dt) { auto node = static_cast(getChildByTag(2)); auto action1 = RotateBy::create(1, 360); node->runAction(action1); } -void Test4::delay4(float dt) +void NodeTest4::delay4(float dt) { unschedule("delay4_key"); removeChildByTag(3, false); } -std::string Test4::subtitle() const +std::string NodeTest4::subtitle() const { return "tags"; } @@ -247,10 +179,10 @@ std::string Test4::subtitle() const //------------------------------------------------------------------ // -// Test5 +// NodeTest5 // //------------------------------------------------------------------ -Test5::Test5() +NodeTest5::NodeTest5() { auto sp1 = Sprite::create(s_pathSister1); auto sp2 = Sprite::create(s_pathSister2); @@ -271,10 +203,10 @@ Test5::Test5() sp1->runAction(forever); sp2->runAction(forever2); - schedule(CC_CALLBACK_1(Test5::addAndRemove, this), 2.0f, "add_and_remove_key"); + schedule(CC_CALLBACK_1(NodeTest5::addAndRemove, this), 2.0f, "add_and_remove_key"); } -void Test5::addAndRemove(float dt) +void NodeTest5::addAndRemove(float dt) { auto sp1 = getChildByTag(kTagSprite1); auto sp2 = getChildByTag(kTagSprite2); @@ -292,17 +224,17 @@ void Test5::addAndRemove(float dt) sp2->release(); } -std::string Test5::subtitle() const +std::string NodeTest5::subtitle() const { return "remove and cleanup"; } //------------------------------------------------------------------ // -// Test6 +// NodeTest6 // //------------------------------------------------------------------ -Test6::Test6() +NodeTest6::NodeTest6() { auto sp1 = Sprite::create(s_pathSister1); auto sp11 = Sprite::create(s_pathSister1); @@ -331,10 +263,10 @@ Test6::Test6() sp2->runAction(forever2); sp21->runAction(forever21); - schedule(CC_CALLBACK_1(Test6::addAndRemove, this), 2.0f, "add_and_remove_key"); + schedule(CC_CALLBACK_1(NodeTest6::addAndRemove, this), 2.0f, "add_and_remove_key"); } -void Test6::addAndRemove(float dt) +void NodeTest6::addAndRemove(float dt) { auto sp1 = getChildByTag(kTagSprite1); auto sp2 = getChildByTag(kTagSprite2); @@ -353,7 +285,7 @@ void Test6::addAndRemove(float dt) } -std::string Test6::subtitle() const +std::string NodeTest6::subtitle() const { return "remove/cleanup with children"; } @@ -403,7 +335,7 @@ void StressTest1::shouldNotCrash(float dt) void StressTest1::removeMe(Node* node) { getParent()->removeChild(node, true); - nextCallback(this); + getTestSuite()->enterNextTest(); } @@ -414,7 +346,7 @@ std::string StressTest1::subtitle() const //------------------------------------------------------------------ // -// StressTest2 +// StressNodeTest2 // //------------------------------------------------------------------ StressTest2::StressTest2() @@ -1324,7 +1256,7 @@ std::string NodeNameTest::subtitle() const void NodeNameTest::onEnter() { - TestCocosNodeDemo::BaseTest::onEnter(); + TestCocosNodeDemo::onEnter(); this->scheduleOnce(CC_CALLBACK_1(NodeNameTest::test, this), 0.05f, "test_key"); } @@ -1509,14 +1441,3 @@ void NodeNameTest::test(float dt) CCAssert(findChildren.size() == 50, ""); } - -/// -/// main -/// -void CocosNodeTestScene::runThisTest() -{ - auto layer = nextCocosNodeAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/NodeTest/NodeTest.h b/tests/cpp-tests/Classes/NodeTest/NodeTest.h index 95a002d848..54f1711aaa 100644 --- a/tests/cpp-tests/Classes/NodeTest/NodeTest.h +++ b/tests/cpp-tests/Classes/NodeTest/NodeTest.h @@ -27,71 +27,65 @@ #define _NODE_TEST_H_ ////----#include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class TestCocosNodeDemo : public BaseTest +DEFINE_TEST_SUITE(CocosNodeTests); + +class TestCocosNodeDemo : public TestCase { public: - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; protected: TestCocosNodeDemo(); virtual ~TestCocosNodeDemo(); - -protected: + Director::Projection _preProjection; }; -class Test2 : public TestCocosNodeDemo +class NodeTest2 : public TestCocosNodeDemo { public: - CREATE_FUNC(Test2); + CREATE_FUNC(NodeTest2); + virtual void onEnter() override; virtual std::string subtitle() const override; }; -class Test4 : public TestCocosNodeDemo +class NodeTest4 : public TestCocosNodeDemo { public: - CREATE_FUNC(Test4); + CREATE_FUNC(NodeTest4); void delay2(float dt); void delay4(float dt); virtual std::string subtitle() const override; protected: - Test4(); + NodeTest4(); }; -class Test5 : public TestCocosNodeDemo +class NodeTest5 : public TestCocosNodeDemo { public: - CREATE_FUNC(Test5); + CREATE_FUNC(NodeTest5); void addAndRemove(float dt); virtual std::string subtitle() const override; protected: - Test5(); + NodeTest5(); }; -class Test6 : public TestCocosNodeDemo +class NodeTest6 : public TestCocosNodeDemo { public: - CREATE_FUNC(Test6); + CREATE_FUNC(NodeTest6); void addAndRemove(float dt); virtual std::string subtitle() const override; protected: - Test6(); + NodeTest6(); }; class StressTest1 : public TestCocosNodeDemo @@ -335,14 +329,4 @@ public: void test(float dt); }; - -// main -class CocosNodeTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -//CCLayer* nextAction(); - #endif diff --git a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp index 69aa50444f..25dfc3dde0 100644 --- a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp +++ b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp @@ -1,5 +1,10 @@ #include "OpenURLTest.h" +OpenURLTests::OpenURLTests() +{ + ADD_TEST_CASE(OpenURLTest); +} + OpenURLTest::OpenURLTest() { auto label = Label::createWithTTF("Open URL Test", "fonts/arial.ttf", 28); @@ -27,12 +32,3 @@ OpenURLTest::~OpenURLTest() { _label->release(); } - -void OpenURLTestScene::runThisTest() -{ - auto layer = new (std::nothrow) OpenURLTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h index 96e79c9a4b..b7a4fedf3b 100644 --- a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h +++ b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h @@ -2,11 +2,14 @@ #define _OPEN_URL_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class OpenURLTest : public Layer +DEFINE_TEST_SUITE(OpenURLTests); + +class OpenURLTest : public TestCase { public: + CREATE_FUNC(OpenURLTest); OpenURLTest(); ~OpenURLTest(); @@ -15,10 +18,4 @@ private: cocos2d::Label* _label; }; -class OpenURLTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _OPEN_URL_TEST_H_ diff --git a/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.cpp b/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.cpp index 59beab41f0..6781ac3ced 100644 --- a/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.cpp +++ b/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.cpp @@ -7,9 +7,12 @@ enum kTagGrossini, }; -Layer* nextParallaxAction(); -Layer* backParallaxAction(); -Layer* restartParallaxAction(); +ParallaxTests::ParallaxTests() +{ + ADD_TEST_CASE(Parallax1); + ADD_TEST_CASE(Parallax2); + ADD_TEST_CASE(Issue2572); +} //------------------------------------------------------------------ // @@ -227,109 +230,3 @@ std::string Issue2572::subtitle() const { return "Look at the output in console"; } - -//------------------------------------------------------------------ -// -// ParallaxDemo -// -//------------------------------------------------------------------ - -static int sceneIdx = -1; - -#define MAX_LAYER 3 - -Layer* createParallaxTestLayer(int nIndex) -{ - switch(nIndex) - { - case 0: return new Parallax1(); - case 1: return new Parallax2(); - case 2: return new Issue2572(); - } - - return nullptr; -} - -Layer* nextParallaxAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createParallaxTestLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backParallaxAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createParallaxTestLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartParallaxAction() -{ - auto layer = createParallaxTestLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - - -ParallaxDemo::ParallaxDemo(void) -{ -} - -ParallaxDemo::~ParallaxDemo(void) -{ -} - -std::string ParallaxDemo::title() const -{ - return "No title"; -} - -void ParallaxDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void ParallaxDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ParallaxTestScene(); - s->addChild(restartParallaxAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ParallaxDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ParallaxTestScene(); - s->addChild( nextParallaxAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ParallaxDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ParallaxTestScene(); - s->addChild( backParallaxAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ParallaxTestScene::runThisTest() -{ - auto layer = nextParallaxAction(); - - addChild(layer); - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.h b/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.h index 4e528c1372..bfb388858f 100644 --- a/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.h +++ b/tests/cpp-tests/Classes/ParallaxTest/ParallaxTest.h @@ -1,24 +1,14 @@ #ifndef _PARALLAX_TEST_H_ #define _PARALLAX_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" -class ParallaxDemo : public BaseTest +DEFINE_TEST_SUITE(ParallaxTests); + +class ParallaxDemo : public TestCase { protected: TextureAtlas* _atlas; - -public: - ParallaxDemo(void); - ~ParallaxDemo(void); - - virtual std::string title() const override; - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class Parallax1 : public ParallaxDemo @@ -29,6 +19,7 @@ protected: MotionStreak* _streak; public: + CREATE_FUNC(Parallax1); Parallax1(); virtual std::string title() const override; }; @@ -41,9 +32,10 @@ protected: MotionStreak* _streak; public: + CREATE_FUNC(Parallax2); Parallax2(); - void onTouchesMoved(const std::vector& touches, Event *event) override; + void onTouchesMoved(const std::vector& touches, Event *event); virtual std::string title() const override; }; @@ -65,16 +57,11 @@ protected: virtual void update(float dt) override; public: + CREATE_FUNC(Issue2572); Issue2572(); virtual std::string title() const override; virtual std::string subtitle() const override; }; -class ParallaxTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp index a46fe79d52..e74e1b2031 100644 --- a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp +++ b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp @@ -27,94 +27,25 @@ #include "Particle3D/CCParticleSystem3D.h" #include "Particle3D/PU/CCPUParticleSystem3D.h" -enum -{ - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; #define PARTICLE_SYSTEM_TAG 0x0001 -static std::function createFunctions[] = +Particle3DTests::Particle3DTests() { - CL(Particle3DExplosionSystemDemo), - CL(Particle3DLineStreakDemo), - CL(Particle3DBlackHoleDemo), - CL(Particle3DHypnoDemo), - CL(Particle3DAdvancedLodSystemDemo), - CL(Particle3DTimeShiftDemo), - CL(Particle3DUVAnimDemo), - CL(Particle3DFirePlaceDemo), - CL(Particle3DElectricBeamSystemDemo), - CL(Particle3DFlareShieldDemo), - CL(Particle3DLightningBoltDemo), - CL(Particle3DCanOfWormsDemo), - CL(Particle3DRibbonTrailDemo), - CL(Particle3DWeaponTrailDemo), - CL(Particle3DWithSprite3DDemo), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextSpriteTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backSpriteTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartSpriteTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void Particle3DTestScene::runThisTest() -{ - auto layer = nextSpriteTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -void Particle3DTestDemo::restartCallback( Ref* sender ) -{ - auto s = new (std::nothrow) Particle3DTestScene(); - s->addChild(restartSpriteTestAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void Particle3DTestDemo::nextCallback( Ref* sender ) -{ - auto s = new (std::nothrow) Particle3DTestScene(); - s->addChild( nextSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void Particle3DTestDemo::backCallback( Ref* sender ) -{ - auto s = new (std::nothrow) Particle3DTestScene(); - s->addChild( backSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); + ADD_TEST_CASE(Particle3DExplosionSystemDemo); + ADD_TEST_CASE(Particle3DLineStreakDemo); + ADD_TEST_CASE(Particle3DBlackHoleDemo); + ADD_TEST_CASE(Particle3DHypnoDemo); + ADD_TEST_CASE(Particle3DAdvancedLodSystemDemo); + ADD_TEST_CASE(Particle3DTimeShiftDemo); + ADD_TEST_CASE(Particle3DUVAnimDemo); + ADD_TEST_CASE(Particle3DFirePlaceDemo); + ADD_TEST_CASE(Particle3DElectricBeamSystemDemo); + ADD_TEST_CASE(Particle3DFlareShieldDemo); + ADD_TEST_CASE(Particle3DLightningBoltDemo); + ADD_TEST_CASE(Particle3DCanOfWormsDemo); + ADD_TEST_CASE(Particle3DRibbonTrailDemo); + ADD_TEST_CASE(Particle3DWeaponTrailDemo); + ADD_TEST_CASE(Particle3DWithSprite3DDemo); } std::string Particle3DTestDemo::title() const @@ -122,14 +53,9 @@ std::string Particle3DTestDemo::title() const return "Particle3D Test"; } -std::string Particle3DTestDemo::subtitle() const -{ - return ""; -} - bool Particle3DTestDemo::init() { - if (!BaseTest::init()) return false; + if (!TestCase::init()) return false; FileUtils::getInstance()->addSearchPath("Particle3D/materials"); FileUtils::getInstance()->addSearchPath("Particle3D/scripts"); diff --git a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h index 43fc5ae2a6..eb335372d0 100644 --- a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h +++ b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h @@ -25,30 +25,27 @@ #ifndef _PARTICLE3D_TEST_H_ #define _PARTICLE3D_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" #include "Particle3D/CCParticleSystem3D.h" #include -class Particle3DTestDemo : public BaseTest + +DEFINE_TEST_SUITE(Particle3DTests); + +class Particle3DTestDemo : public TestCase { public: CREATE_FUNC(Particle3DTestDemo); Particle3DTestDemo(void); virtual ~Particle3DTestDemo(void); - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - // overrides virtual bool init() override; virtual std::string title() const override; - virtual std::string subtitle() const override; virtual void update(float delta) override; - void onTouchesBegan(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesMoved(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesEnded(const std::vector& touches, cocos2d::Event *event) override; + void onTouchesBegan(const std::vector& touches, cocos2d::Event *event); + void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); + void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); protected: std::string _title; @@ -253,11 +250,4 @@ public: virtual bool init() override; }; -class Particle3DTestScene : public TestScene -{ -public: - Particle3DTestScene(){}; - virtual void runThisTest(); -}; - #endif \ No newline at end of file diff --git a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp index 54617f4e9e..24e920b796 100644 --- a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp +++ b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp @@ -5,10 +5,6 @@ enum { kTagParticleCount = 1, }; -Layer* nextParticleAction(); -Layer* backParticleAction(); -Layer* restartParticleAction(); - //------------------------------------------------------------------ // // DemoFirework @@ -956,102 +952,59 @@ enum IDC_TOGGLE }; -static int sceneIdx = -1; - -Layer* createParticleLayer(int nIndex) +ParticleTests::ParticleTests() { - switch(nIndex) - { - case 0: return new ParticleReorder(); - case 1: return new ParticleBatchHybrid(); - case 2: return new ParticleBatchMultipleEmitters(); - case 3: return new DemoFlower(); - case 4: return new DemoGalaxy(); - case 5: return new DemoFirework(); - case 6: return new DemoSpiral(); - case 7: return new DemoSun(); - case 8: return new DemoMeteor(); - case 9: return new DemoFire(); - case 10: return new DemoSmoke(); - case 11: return new DemoExplosion(); - case 12: return new DemoSnow(); - case 13: return new DemoRain(); - case 14: return new DemoBigFlower(); - case 15: return new DemoRotFlower(); - case 16: return new DemoModernArt(); - case 17: return new DemoRing(); - case 18: return new ParallaxParticle(); - case 19: return new DemoParticleFromFile("BoilingFoam"); - case 20: return new DemoParticleFromFile("BurstPipe"); - case 21: return new DemoParticleFromFile("Comet"); - case 22: return new DemoParticleFromFile("debian"); - case 23: return new DemoParticleFromFile("ExplodingRing"); - case 24: return new DemoParticleFromFile("LavaFlow"); - case 25: return new DemoParticleFromFile("SpinningPeas"); - case 26: return new DemoParticleFromFile("SpookyPeas"); - case 27: return new DemoParticleFromFile("Upsidedown"); - case 28: return new DemoParticleFromFile("Flower"); - case 29: return new DemoParticleFromFile("Spiral"); - case 30: return new DemoParticleFromFile("Galaxy"); - case 31: return new DemoParticleFromFile("Phoenix"); - case 32: return new DemoParticleFromFile("lines"); - case 33: return new DemoParticleFromFile("ButterFly"); - case 34: return new DemoParticleFromFile("ButterFlyYFlipped"); - case 35: return new RadiusMode1(); - case 36: return new RadiusMode2(); - case 37: return new Issue704(); - case 38: return new Issue870(); - case 39: return new Issue1201(); - // v1.1 tests - case 40: return new MultipleParticleSystems(); - case 41: return new MultipleParticleSystemsBatched(); - case 42: return new AddAndDeleteParticleSystems(); - case 43: return new ReorderParticleSystems(); - case 44: return new PremultipliedAlphaTest(); - case 45: return new PremultipliedAlphaTest2(); - case 46: return new Issue3990(); - case 47: return new ParticleAutoBatching(); - case 48: return new ParticleVisibleTest(); - case 49: return new ParticleResetTotalParticles(); - default: - break; - } + ADD_TEST_CASE(ParticleReorder); + ADD_TEST_CASE(ParticleBatchHybrid); + ADD_TEST_CASE(ParticleBatchMultipleEmitters); + ADD_TEST_CASE(DemoFlower); + ADD_TEST_CASE(DemoGalaxy); + ADD_TEST_CASE(DemoFirework); + ADD_TEST_CASE(DemoSpiral); + ADD_TEST_CASE(DemoSun); + ADD_TEST_CASE(DemoMeteor); + ADD_TEST_CASE(DemoFire); + ADD_TEST_CASE(DemoSmoke); + ADD_TEST_CASE(DemoExplosion); + ADD_TEST_CASE(DemoSnow); + ADD_TEST_CASE(DemoRain); + ADD_TEST_CASE(DemoBigFlower); + ADD_TEST_CASE(DemoRotFlower); + ADD_TEST_CASE(DemoModernArt); + ADD_TEST_CASE(DemoRing); + ADD_TEST_CASE(ParallaxParticle); + addTestCase("BoilingFoam", [](){return DemoParticleFromFile::create("BoilingFoam");}); + addTestCase("BurstPipe", [](){return DemoParticleFromFile::create("BurstPipe"); }); + addTestCase("Comet", [](){return DemoParticleFromFile::create("Comet"); }); + addTestCase("debian", [](){return DemoParticleFromFile::create("debian"); }); + addTestCase("ExplodingRing", [](){return DemoParticleFromFile::create("ExplodingRing"); }); + addTestCase("LavaFlow", [](){return DemoParticleFromFile::create("LavaFlow"); }); + addTestCase("SpinningPeas", [](){return DemoParticleFromFile::create("SpinningPeas"); }); + addTestCase("SpookyPeas", [](){return DemoParticleFromFile::create("SpookyPeas"); }); + addTestCase("Upsidedown", [](){return DemoParticleFromFile::create("Upsidedown"); }); + addTestCase("Flower", [](){return DemoParticleFromFile::create("Flower"); }); + addTestCase("Spiral", [](){return DemoParticleFromFile::create("Spiral"); }); + addTestCase("Galaxy", [](){return DemoParticleFromFile::create("Galaxy"); }); + addTestCase("Phoenix", [](){return DemoParticleFromFile::create("Phoenix"); }); + addTestCase("lines", [](){return DemoParticleFromFile::create("lines"); }); + addTestCase("ButterFly", [](){return DemoParticleFromFile::create("ButterFly"); }); + addTestCase("ButterFlyYFlipped", [](){return DemoParticleFromFile::create("ButterFlyYFlipped"); }); + ADD_TEST_CASE(RadiusMode1); + ADD_TEST_CASE(RadiusMode2); + ADD_TEST_CASE(Issue704); + ADD_TEST_CASE(Issue870); + ADD_TEST_CASE(Issue1201); - return nullptr; -} -#define MAX_LAYER 50 - - -Layer* nextParticleAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createParticleLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backParticleAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createParticleLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartParticleAction() -{ - auto layer = createParticleLayer(sceneIdx); - layer->autorelease(); - - return layer; + ADD_TEST_CASE(MultipleParticleSystems); + ADD_TEST_CASE(MultipleParticleSystemsBatched); + ADD_TEST_CASE(AddAndDeleteParticleSystems); + ADD_TEST_CASE(ReorderParticleSystems); + ADD_TEST_CASE(PremultipliedAlphaTest); + ADD_TEST_CASE(PremultipliedAlphaTest2); + ADD_TEST_CASE(Issue3990); + ADD_TEST_CASE(ParticleAutoBatching); + ADD_TEST_CASE(ParticleVisibleTest); + ADD_TEST_CASE(ParticleResetTotalParticles); } ParticleDemo::~ParticleDemo(void) @@ -1061,7 +1014,7 @@ ParticleDemo::~ParticleDemo(void) void ParticleDemo::onEnter(void) { - BaseTest::onEnter(); + TestCase::onEnter(); _color = LayerColor::create( Color4B(127,127,127,255) ); this->addChild(_color); @@ -1170,30 +1123,6 @@ void ParticleDemo::toggleCallback(Ref* sender) } } -void ParticleDemo::restartCallback(Ref* sender) -{ - if (_emitter != nullptr) - { - _emitter->resetSystem(); - } -} - -void ParticleDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ParticleTestScene(); - s->addChild( nextParticleAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ParticleDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ParticleTestScene(); - s->addChild( backParticleAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - void ParticleDemo::setEmitterPosition() { auto s = Director::getInstance()->getWinSize(); @@ -2052,13 +1981,4 @@ std::string ParticleResetTotalParticles::subtitle() const return "it should work as well"; } -// -// main -// -void ParticleTestScene::runThisTest() -{ - addChild(nextParticleAction()); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h index ddcaa01f0a..48cc1ae9cd 100644 --- a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h +++ b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h @@ -1,19 +1,11 @@ #ifndef _PARTICLE_TEST_H_ #define _PARTICLE_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" -////----#include "cocos2d.h" -// #include "event_dispatcher/CCTouch.h" -// #include "CCParticleExample.h" -class ParticleTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(ParticleTests); -class ParticleDemo : public BaseTest +class ParticleDemo : public TestCase { protected: ParticleSystemQuad* _emitter; @@ -28,14 +20,11 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; void toggleCallback(Ref* sender); - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - void onTouchesEnded(const std::vector& touches, Event *event) override; + void onTouchesBegan(const std::vector& touches, Event *event); + void onTouchesMoved(const std::vector& touches, Event *event); + void onTouchesEnded(const std::vector& touches, Event *event); virtual void update(float dt) override; void setEmitterPosition(); @@ -44,6 +33,7 @@ public: class DemoFirework : public ParticleDemo { public: + CREATE_FUNC(DemoFirework); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -51,6 +41,7 @@ public: class DemoFire : public ParticleDemo { public: + CREATE_FUNC(DemoFire); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -58,6 +49,7 @@ public: class DemoSun : public ParticleDemo { public: + CREATE_FUNC(DemoSun); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -65,6 +57,7 @@ public: class DemoGalaxy : public ParticleDemo { public: + CREATE_FUNC(DemoGalaxy); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -72,6 +65,7 @@ public: class DemoFlower : public ParticleDemo { public: + CREATE_FUNC(DemoFlower); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -79,6 +73,7 @@ public: class DemoBigFlower : public ParticleDemo { public: + CREATE_FUNC(DemoBigFlower); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -86,6 +81,7 @@ public: class DemoRotFlower : public ParticleDemo { public: + CREATE_FUNC(DemoRotFlower); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -93,6 +89,7 @@ public: class DemoMeteor : public ParticleDemo { public: + CREATE_FUNC(DemoMeteor); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -100,6 +97,7 @@ public: class DemoSpiral : public ParticleDemo { public: + CREATE_FUNC(DemoSpiral); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -107,6 +105,7 @@ public: class DemoExplosion : public ParticleDemo { public: + CREATE_FUNC(DemoExplosion); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -114,6 +113,7 @@ public: class DemoSmoke : public ParticleDemo { public: + CREATE_FUNC(DemoSmoke); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -121,6 +121,7 @@ public: class DemoSnow : public ParticleDemo { public: + CREATE_FUNC(DemoSnow); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -128,6 +129,7 @@ public: class DemoRain : public ParticleDemo { public: + CREATE_FUNC(DemoRain); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -135,6 +137,7 @@ public: class DemoModernArt : public ParticleDemo { public: + CREATE_FUNC(DemoModernArt); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -142,6 +145,7 @@ public: class DemoRing : public ParticleDemo { public: + CREATE_FUNC(DemoRing); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -149,6 +153,7 @@ public: class ParallaxParticle : public ParticleDemo { public: + CREATE_FUNC(ParallaxParticle); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -156,11 +161,25 @@ public: class DemoParticleFromFile : public ParticleDemo { public: - std::string _title; - DemoParticleFromFile(const char *file) - { - _title = file; + static DemoParticleFromFile* create(const std::string& file) + { + auto ret = new (std::nothrow) DemoParticleFromFile; + if (ret && ret->init()) + { + ret->_title = file; + ret->autorelease(); + } + else + { + delete ret; + ret = nullptr; + } + + return ret; } + + std::string _title; + virtual void onEnter() override; virtual std::string subtitle() const override { @@ -171,6 +190,7 @@ public: class RadiusMode1 : public ParticleDemo { public: + CREATE_FUNC(RadiusMode1); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -178,6 +198,7 @@ public: class RadiusMode2 : public ParticleDemo { public: + CREATE_FUNC(RadiusMode2); virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -185,6 +206,7 @@ public: class Issue704 : public ParticleDemo { public: + CREATE_FUNC(Issue704); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -193,6 +215,7 @@ public: class Issue870 : public ParticleDemo { public: + CREATE_FUNC(Issue870); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -205,6 +228,7 @@ private: class Issue1201 : public ParticleDemo { public: + CREATE_FUNC(Issue1201); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -213,6 +237,7 @@ public: class ParticleBatchHybrid : public ParticleDemo { public: + CREATE_FUNC(ParticleBatchHybrid); virtual void onEnter() override; void switchRender(float dt); virtual std::string title() const override; @@ -225,6 +250,8 @@ private: class ParticleBatchMultipleEmitters : public ParticleDemo { public: + CREATE_FUNC(ParticleBatchMultipleEmitters); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -233,6 +260,7 @@ public: class ParticleReorder : public ParticleDemo { public: + CREATE_FUNC(ParticleReorder); virtual void onEnter() override; void reorderParticles(float dt); virtual std::string title() const override; @@ -244,6 +272,7 @@ private: class MultipleParticleSystems : public ParticleDemo { public: + CREATE_FUNC(MultipleParticleSystems); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -253,6 +282,7 @@ public: class MultipleParticleSystemsBatched : public ParticleDemo { public: + CREATE_FUNC(MultipleParticleSystemsBatched); virtual void onEnter() override; virtual void update(float dt) override; virtual std::string title() const override; @@ -264,6 +294,7 @@ private: class AddAndDeleteParticleSystems : public ParticleDemo { public: + CREATE_FUNC(AddAndDeleteParticleSystems); virtual void onEnter() override; virtual void update(float dt) override; void removeSystem(float dt); @@ -276,6 +307,7 @@ private: class ReorderParticleSystems : public ParticleDemo { public: + CREATE_FUNC(ReorderParticleSystems); virtual void onEnter() override; void reorderSystem(float time); virtual void update(float dt) override; @@ -289,6 +321,7 @@ class PremultipliedAlphaTest : public ParticleDemo { bool _hasEmitter; public: + CREATE_FUNC(PremultipliedAlphaTest); virtual void onEnter() override; void readdPaticle(float delta); virtual std::string title() const override; @@ -298,6 +331,7 @@ public: class PremultipliedAlphaTest2 : public ParticleDemo { public: + CREATE_FUNC(PremultipliedAlphaTest2); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -306,6 +340,7 @@ public: class Issue3990 : public ParticleDemo { public: + CREATE_FUNC(Issue3990); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -314,6 +349,7 @@ public: class ParticleVisibleTest : public ParticleDemo { public: + CREATE_FUNC(ParticleVisibleTest); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -323,6 +359,7 @@ public: class ParticleAutoBatching : public ParticleDemo { public: + CREATE_FUNC(ParticleAutoBatching); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; @@ -331,6 +368,7 @@ public: class ParticleResetTotalParticles : public ParticleDemo { public: + CREATE_FUNC(ParticleResetTotalParticles); virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; diff --git a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp index b75e4ded76..7d4f9ae27e 100644 --- a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp +++ b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp @@ -4,83 +4,35 @@ #include "ui/CocosGUI.h" USING_NS_CC; -namespace +PhysicsTests::PhysicsTests() { - static std::function createFunctions[] = { #if CC_USE_PHYSICS - CL(PhysicsDemoLogoSmash), - CL(PhysicsDemoPyramidStack), - CL(PhysicsDemoClickAdd), - CL(PhysicsDemoRayCast), - CL(PhysicsDemoJoints), - CL(PhysicsDemoActions), - CL(PhysicsDemoPump), - CL(PhysicsDemoOneWayPlatform), - CL(PhysicsDemoSlice), - CL(PhysicsDemoBug3988), - CL(PhysicsContactTest), - CL(PhysicsPositionRotationTest), - CL(PhysicsSetGravityEnableTest), - CL(Bug5482), - CL(PhysicsFixedUpdate), - CL(PhysicsTransformTest), - CL(PhysicsIssue9959) + ADD_TEST_CASE(PhysicsDemoLogoSmash); + ADD_TEST_CASE(PhysicsDemoPyramidStack); + ADD_TEST_CASE(PhysicsDemoClickAdd); + ADD_TEST_CASE(PhysicsDemoRayCast); + ADD_TEST_CASE(PhysicsDemoJoints); + ADD_TEST_CASE(PhysicsDemoActions); + ADD_TEST_CASE(PhysicsDemoPump); + ADD_TEST_CASE(PhysicsDemoOneWayPlatform); + ADD_TEST_CASE(PhysicsDemoSlice); + ADD_TEST_CASE(PhysicsDemoBug3988); + ADD_TEST_CASE(PhysicsContactTest); + ADD_TEST_CASE(PhysicsPositionRotationTest); + ADD_TEST_CASE(PhysicsSetGravityEnableTest); + ADD_TEST_CASE(Bug5482); + ADD_TEST_CASE(PhysicsFixedUpdate); + ADD_TEST_CASE(PhysicsTransformTest); + ADD_TEST_CASE(PhysicsIssue9959); #else - CL(PhysicsDemoDisabled), + ADD_TEST_CASE(PhysicsDemoDisabled); #endif - }; - - static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - - static Layer* next() - { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - static Layer* back() - { - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - static Layer* restart() - { - auto layer = (createFunctions[sceneIdx])(); - return layer; - } - - static const Color4F STATIC_COLOR(1.0f, 0.0f, 0.0f, 1.0f); - static const int DRAG_BODYS_TAG = 0x80; } - -PhysicsTestScene::PhysicsTestScene() -#if CC_USE_PHYSICS -: TestScene(false, true) -#else -: TestScene() -#endif -, _debugDraw(false) -{} - -void PhysicsTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(next()); - Director::getInstance()->replaceScene(this); -} +static const Color4F STATIC_COLOR(1.0f, 0.0f, 0.0f, 1.0f); +static const int DRAG_BODYS_TAG = 0x80; -void PhysicsTestScene::toggleDebug() +void PhysicsDemo::toggleDebug() { #if CC_USE_PHYSICS _debugDraw = !_debugDraw; @@ -102,7 +54,7 @@ void PhysicsDemoDisabled::onEnter() #else PhysicsDemo::PhysicsDemo() -: _scene(nullptr) +: _debugDraw(false) , _spriteTexture(nullptr) , _ball(nullptr) { @@ -113,45 +65,22 @@ PhysicsDemo::~PhysicsDemo() } +bool PhysicsDemo::init() +{ + if (TestCase::init()) + { + return initWithPhysics(); + } + return false; +} std::string PhysicsDemo::title() const { return "PhysicsTest"; } -std::string PhysicsDemo::subtitle() const -{ - return ""; -} - -void PhysicsDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) PhysicsTestScene(); - s->addChild( restart() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void PhysicsDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) PhysicsTestScene(); - s->addChild( next() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void PhysicsDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) PhysicsTestScene(); - s->addChild( back() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - void PhysicsDemo::onEnter() { - BaseTest::onEnter(); - - _scene = dynamic_cast(this->getParent()); + TestCase::onEnter(); _spriteTexture = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100)->getTexture(); @@ -185,13 +114,9 @@ Sprite* PhysicsDemo::addGrossiniAtPosition(Vec2 p, float scale/* = 1.0*/) return sp; } - void PhysicsDemo::toggleDebugCallback(Ref* sender) { - if (_scene != nullptr) - { - _scene->toggleDebug(); - } + toggleDebug(); } PhysicsDemoClickAdd::~PhysicsDemoClickAdd() @@ -251,10 +176,7 @@ void PhysicsDemoClickAdd::onAcceleration(Acceleration* acc, Event* event) auto v = Vec2( accelX, accelY); v = v * 200; - if(_scene != nullptr) - { - _scene->getPhysicsWorld()->setGravity(v); - } + getPhysicsWorld()->setGravity(v); } namespace @@ -387,7 +309,7 @@ Sprite* PhysicsDemo::makeTriangle(Vec2 point, Size size, int color, PhysicsMater bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event) { auto location = touch->getLocation(); - auto arr = _scene->getPhysicsWorld()->getShapes(location); + auto arr = getPhysicsWorld()->getShapes(location); PhysicsBody* body = nullptr; for (auto& obj : arr) @@ -408,7 +330,7 @@ bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event) this->addChild(mouse); PhysicsJointPin* joint = PhysicsJointPin::construct(mouse->getPhysicsBody(), body, location); joint->setMaxForce(5000.0f * body->getMass()); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); _mouses.insert(std::make_pair(touch->getID(), mouse)); return true; @@ -442,8 +364,8 @@ void PhysicsDemoLogoSmash::onEnter() { PhysicsDemo::onEnter(); - _scene->getPhysicsWorld()->setGravity(Vec2(0, 0)); - _scene->getPhysicsWorld()->setUpdateRate(5.0f); + getPhysicsWorld()->setGravity(Vec2(0, 0)); + getPhysicsWorld()->setUpdateRate(5.0f); _ball = SpriteBatchNode::create("Images/ball.png", sizeof(logo_image)/sizeof(logo_image[0])); addChild(_ball); @@ -544,7 +466,7 @@ void PhysicsDemoRayCast::onEnter() listener->onTouchesEnded = CC_CALLBACK_2(PhysicsDemoRayCast::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - _scene->getPhysicsWorld()->setGravity(Point::ZERO); + getPhysicsWorld()->setGravity(Point::ZERO); auto node = DrawNode::create(); node->setPhysicsBody(PhysicsBody::createEdgeSegment(VisibleRect::leftBottom() + Vec2(0, 50), VisibleRect::rightBottom() + Vec2(0, 50))); @@ -604,7 +526,7 @@ void PhysicsDemoRayCast::update(float delta) Vec2 point3 = point2; auto func = CC_CALLBACK_3(PhysicsDemoRayCast::anyRay, this); - _scene->getPhysicsWorld()->rayCast(func, point1, point2, &point3); + getPhysicsWorld()->rayCast(func, point1, point2, &point3); _node->drawSegment(point1, point3, 1, STATIC_COLOR); if (point2 != point3) @@ -630,7 +552,7 @@ void PhysicsDemoRayCast::update(float delta) return true; }; - _scene->getPhysicsWorld()->rayCast(func, point1, point2, nullptr); + getPhysicsWorld()->rayCast(func, point1, point2, nullptr); _node->drawSegment(point1, point3, 1, STATIC_COLOR); if (point2 != point3) @@ -657,7 +579,7 @@ void PhysicsDemoRayCast::update(float delta) return true; }; - _scene->getPhysicsWorld()->rayCast(func, point1, point2, nullptr); + getPhysicsWorld()->rayCast(func, point1, point2, nullptr); _node->drawSegment(point1, point2, 1, STATIC_COLOR); @@ -709,7 +631,7 @@ std::string PhysicsDemoRayCast::title() const void PhysicsDemoJoints::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); + toggleDebug(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(PhysicsDemoJoints::onTouchBegan, this); @@ -744,7 +666,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointPin* joint = PhysicsJointPin::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), offset); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -759,7 +681,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointFixed* joint = PhysicsJointFixed::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), offset); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -773,7 +695,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointDistance* joint = PhysicsJointDistance::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Point::ZERO, Point::ZERO); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -787,7 +709,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointLimit* joint = PhysicsJointLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Point::ZERO, Point::ZERO, 30.0f, 60.0f); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -801,7 +723,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointSpring* joint = PhysicsJointSpring::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Point::ZERO, Point::ZERO, 500.0f, 0.3f); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -815,7 +737,7 @@ void PhysicsDemoJoints::onEnter() sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); PhysicsJointGroove* joint = PhysicsJointGroove::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), Vec2(30, 15), Vec2(30, -15), Vec2(-30, 0)); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -828,10 +750,10 @@ void PhysicsDemoJoints::onEnter() auto sp2 = makeBox(offset + Vec2(30, 0), Size(30, 10)); sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); PhysicsJointRotarySpring* joint = PhysicsJointRotarySpring::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 3000.0f, 60.0f); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -844,10 +766,10 @@ void PhysicsDemoJoints::onEnter() auto sp2 = makeBox(offset + Vec2(30, 0), Size(30, 10)); sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); PhysicsJointRotaryLimit* joint = PhysicsJointRotaryLimit::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f,(float) M_PI_2); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -860,10 +782,10 @@ void PhysicsDemoJoints::onEnter() auto sp2 = makeBox(offset + Vec2(30, 0), Size(30, 10)); sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); PhysicsJointRatchet* joint = PhysicsJointRatchet::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, (float)M_PI_2); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -876,10 +798,10 @@ void PhysicsDemoJoints::onEnter() auto sp2 = makeBox(offset + Vec2(30, 0), Size(30, 10)); sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); PhysicsJointGear* joint = PhysicsJointGear::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), 0.0f, 2.0f); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -892,10 +814,10 @@ void PhysicsDemoJoints::onEnter() auto sp2 = makeBox(offset + Vec2(30, 0), Size(30, 10)); sp2->getPhysicsBody()->setTag(DRAG_BODYS_TAG); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); - _scene->getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp1->getPhysicsBody(), box, sp1->getPosition())); + getPhysicsWorld()->addJoint(PhysicsJointPin::construct(sp2->getPhysicsBody(), box, sp2->getPosition())); PhysicsJointMotor* joint = PhysicsJointMotor::construct(sp1->getPhysicsBody(), sp2->getPhysicsBody(), (float)M_PI_2); - _scene->getPhysicsWorld()->addJoint(joint); + getPhysicsWorld()->addJoint(joint); this->addChild(sp1); this->addChild(sp2); @@ -916,7 +838,7 @@ std::string PhysicsDemoJoints::title() const void PhysicsDemoActions::onEnter() { PhysicsDemo::onEnter(); - _scene->getPhysicsWorld()->setGravity(Vect::ZERO); + getPhysicsWorld()->setGravity(Vect::ZERO); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(PhysicsDemoActions::onTouchBegan, this); @@ -961,7 +883,7 @@ std::string PhysicsDemoActions::title() const void PhysicsDemoPump::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); + toggleDebug(); _distance = 0.0f; _rotationV = 0.0f; @@ -998,7 +920,7 @@ void PhysicsDemoPump::onEnter() addChild(ball); } - auto _world = _scene->getPhysicsWorld(); + auto _world = getPhysicsWorld(); Vec2 vec[4] = { @@ -1063,7 +985,9 @@ void PhysicsDemoPump::onEnter() void PhysicsDemoPump::update(float delta) { - for (const auto& body : _scene->getPhysicsWorld()->getAllBodies()) + auto physicsWorld = getPhysicsWorld(); + + for (const auto& body : physicsWorld->getAllBodies()) { if (body->getTag() == DRAG_BODYS_TAG && body->getPosition().y < 0.0f) { @@ -1072,7 +996,7 @@ void PhysicsDemoPump::update(float delta) } } - PhysicsBody* gear = _scene->getPhysicsWorld()->getBody(1); + PhysicsBody* gear = physicsWorld->getBody(1); if (gear != nullptr) { @@ -1166,7 +1090,7 @@ std::string PhysicsDemoOneWayPlatform::title() const void PhysicsDemoSlice::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); + toggleDebug(); _sliceTag = 1; @@ -1254,7 +1178,7 @@ void PhysicsDemoSlice::clipPoly(PhysicsShapePolygon* shape, Vec2 normal, float d void PhysicsDemoSlice::onTouchEnded(Touch *touch, Event *event) { auto func = CC_CALLBACK_3(PhysicsDemoSlice::slice, this); - _scene->getPhysicsWorld()->rayCast(func, touch->getStartLocation(), touch->getLocation(), nullptr); + getPhysicsWorld()->rayCast(func, touch->getStartLocation(), touch->getLocation(), nullptr); } std::string PhysicsDemoSlice::title() const @@ -1271,8 +1195,8 @@ std::string PhysicsDemoSlice::subtitle() const void PhysicsDemoBug3988::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); - _scene->getPhysicsWorld()->setGravity(Vect::ZERO); + toggleDebug(); + getPhysicsWorld()->setGravity(Vect::ZERO); auto ball = Sprite::create("Images/YellowSquare.png"); ball->setPosition(VisibleRect::center() - Vec2(100, 0)); @@ -1297,7 +1221,7 @@ std::string PhysicsDemoBug3988::subtitle() const void PhysicsContactTest::onEnter() { PhysicsDemo::onEnter(); - _scene->getPhysicsWorld()->setGravity(Vect::ZERO); + getPhysicsWorld()->setGravity(Vect::ZERO); auto s = VisibleRect::getVisibleRect().size; _yellowBoxNum = 50; @@ -1559,8 +1483,8 @@ std::string PhysicsContactTest::subtitle() const void PhysicsPositionRotationTest::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); - _scene->getPhysicsWorld()->setGravity(Point::ZERO); + toggleDebug(); + getPhysicsWorld()->setGravity(Point::ZERO); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(PhysicsDemo::onTouchBegan, this); @@ -1656,7 +1580,7 @@ void PhysicsSetGravityEnableTest::onScheduleOnce(float delta) auto ball = getChildByTag(2); ball->getPhysicsBody()->setMass(200); - _scene->getPhysicsWorld()->setGravity(Vect(0, 98)); + getPhysicsWorld()->setGravity(Vect(0, 98)); } std::string PhysicsSetGravityEnableTest::title() const @@ -1673,7 +1597,7 @@ void Bug5482::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); + toggleDebug(); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(PhysicsDemo::onTouchBegan, this); @@ -1738,8 +1662,8 @@ void PhysicsFixedUpdate::onEnter() { PhysicsDemo::onEnter(); - _scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); - _scene->getPhysicsWorld()->setGravity(Point::ZERO); + getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); + getPhysicsWorld()->setGravity(Point::ZERO); // wall auto wall = Node::create(); @@ -1766,7 +1690,7 @@ void PhysicsFixedUpdate::updateStart(float delta) { addBall(); - _scene->getPhysicsWorld()->setAutoStep(false); + getPhysicsWorld()->setAutoStep(false); scheduleUpdate(); } @@ -1776,7 +1700,7 @@ void PhysicsFixedUpdate::update(float delta) // use fixed time and calculate 3 times per frame makes physics simulate more precisely. for (int i = 0; i < 3; ++i) { - _scene->getPhysicsWorld()->step(1/180.0f); + getPhysicsWorld()->step(1/180.0f); } } @@ -1800,8 +1724,8 @@ bool PhysicsTransformTest::onTouchBegan(Touch *touch, Event *event) void PhysicsTransformTest::onEnter() { PhysicsDemo::onEnter(); - _scene->toggleDebug(); - _scene->getPhysicsWorld()->setGravity(Point::ZERO); + toggleDebug(); + getPhysicsWorld()->setGravity(Point::ZERO); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(PhysicsTransformTest::onTouchBegan, this); diff --git a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.h b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.h index 969f8140c4..fb53082c03 100644 --- a/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.h +++ b/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.h @@ -2,28 +2,14 @@ #define _PHYSICS_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #include - -class PhysicsTestScene : public TestScene -{ -public: - PhysicsTestScene(); - -public: - virtual void runThisTest(); - - void toggleDebug(); - -private: - bool _debugDraw; -}; +DEFINE_TEST_SUITE(PhysicsTests); #if CC_USE_PHYSICS == 0 -class PhysicsDemoDisabled : public BaseTest +class PhysicsDemoDisabled : public TestCase { public: CREATE_FUNC(PhysicsDemoDisabled); @@ -32,21 +18,16 @@ public: }; #else -class PhysicsDemo : public BaseTest +class PhysicsDemo : public TestCase { public: - CREATE_FUNC(PhysicsDemo); - PhysicsDemo(); virtual ~PhysicsDemo(); + virtual bool init() override; virtual void onEnter() override; virtual std::string title() const override; - virtual std::string subtitle() const override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; void toggleDebugCallback(Ref* sender); Sprite* addGrossiniAtPosition(Vec2 p, float scale = 1.0); @@ -54,15 +35,16 @@ public: Sprite* makeBox(Vec2 point, Size size, int color = 0, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT); Sprite* makeTriangle(Vec2 point, Size size, int color = 0, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT); - bool onTouchBegan(Touch* touch, Event* event) override; - void onTouchMoved(Touch* touch, Event* event) override; - void onTouchEnded(Touch* touch, Event* event) override; - + bool onTouchBegan(Touch* touch, Event* event); + void onTouchMoved(Touch* touch, Event* event); + void onTouchEnded(Touch* touch, Event* event); + + void toggleDebug(); protected: - PhysicsTestScene* _scene; - Texture2D* _spriteTexture; // weak ref + Texture2D* _spriteTexture; SpriteBatchNode* _ball; std::unordered_map _mouses; + bool _debugDraw; }; class PhysicsDemoClickAdd : public PhysicsDemo @@ -74,8 +56,8 @@ public: void onEnter() override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; - void onAcceleration(Acceleration* acc, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); + void onAcceleration(Acceleration* acc, Event* event); }; class PhysicsDemoLogoSmash : public PhysicsDemo @@ -107,7 +89,7 @@ public: void onEnter() override; virtual std::string title() const override; void update(float delta) override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void changeModeCallback(Ref* sender); @@ -147,9 +129,9 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - bool onTouchBegan(Touch* touch, Event* event) override; - void onTouchMoved(Touch* touch, Event* event) override; - void onTouchEnded(Touch* touch, Event* event) override; + bool onTouchBegan(Touch* touch, Event* event); + void onTouchMoved(Touch* touch, Event* event); + void onTouchEnded(Touch* touch, Event* event); private: float _distance; @@ -179,7 +161,7 @@ public: bool slice(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data); void clipPoly(PhysicsShapePolygon* shape, Vec2 normal, float distance); - void onTouchEnded(Touch *touch, Event *event) override; + void onTouchEnded(Touch *touch, Event *event); private: int _sliceTag; @@ -275,7 +257,7 @@ public: void onEnter() override; virtual std::string title() const override; - bool onTouchBegan(Touch* touch, Event* event) override; + bool onTouchBegan(Touch* touch, Event* event); }; diff --git a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp index e488fe9974..ae723c08a6 100644 --- a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp +++ b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp @@ -2,6 +2,11 @@ using namespace cocos2d; +ReleasePoolTests::ReleasePoolTests() +{ + ADD_TEST_CASE(ReleasePoolTest); +} + class TestObject : public Ref { public: @@ -22,8 +27,12 @@ private: std::string _name; }; -void ReleasePoolTestScene::runThisTest() +bool ReleasePoolTest::init() { + if (!TestCase::init()) + { + return false; + } // title auto label = Label::createWithTTF("AutoreasePool Test", "fonts/arial.ttf", 32); addChild(label, 9999); @@ -81,5 +90,5 @@ void ReleasePoolTestScene::runThisTest() PoolManager::destroyInstance(); } - Director::getInstance()->replaceScene(this); + return true; } diff --git a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.h b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.h index abd518b571..e8ccec1aa8 100644 --- a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.h +++ b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.h @@ -4,13 +4,15 @@ #ifndef __RELEASE_POOL_TEST_H__ #define __RELEASE_POOL_TEST_H__ -#include "../testBasic.h" +#include "../BaseTest.h" -class ReleasePoolTestScene : public TestScene +DEFINE_TEST_SUITE(ReleasePoolTests); +class ReleasePoolTest : public TestCase { public: - virtual void runThisTest(); - + CREATE_FUNC(ReleasePoolTest); + + virtual bool init() override; private: }; diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index 4f3b51154c..8474dc4c49 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -1,89 +1,17 @@ #include "RenderTextureTest.h" #include "../testBasic.h" -// Test #1 by Jason Booth (slipster216) -// Test #3 by David Deaco (ddeaco) - - -static std::function createFunctions[] = { - CL(RenderTextureSave), - CL(RenderTextureIssue937), - CL(RenderTextureZbuffer), - CL(RenderTextureTestDepthStencil), - CL(RenderTextureTargetNode), - CL(SpriteRenderTextureBug), - CL(RenderTexturePartTest), +RenderTextureTests::RenderTextureTests() +{ + ADD_TEST_CASE(RenderTextureSave); + ADD_TEST_CASE(RenderTextureIssue937); + ADD_TEST_CASE(RenderTextureZbuffer); + ADD_TEST_CASE(RenderTextureTestDepthStencil); + ADD_TEST_CASE(RenderTextureTargetNode); + ADD_TEST_CASE(SpriteRenderTextureBug); + ADD_TEST_CASE(RenderTexturePartTest); }; -#define MAX_LAYER (sizeof(createFunctions)/sizeof(createFunctions[0])) -static int sceneIdx = -1; - -static Layer* nextTestCase() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backTestCase() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartTestCase() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void RenderTextureTest::onEnter() -{ - BaseTest::onEnter(); -} - -void RenderTextureTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) RenderTextureScene(); - s->addChild(restartTestCase()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void RenderTextureTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) RenderTextureScene(); - s->addChild( nextTestCase() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void RenderTextureTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) RenderTextureScene(); - s->addChild( backTestCase() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -std::string RenderTextureTest::title() const -{ - return "No title"; -} - -std::string RenderTextureTest::subtitle() const -{ - return ""; -} - /** * Impelmentation of RenderTextureSave */ @@ -268,14 +196,6 @@ std::string RenderTextureIssue937::subtitle() const return "All images should be equal..."; } -void RenderTextureScene::runThisTest() -{ - auto layer = nextTestCase(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - /** * Impelmentation of RenderTextureZbuffer */ diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h index 4289c543b8..29fbe5ca35 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h @@ -2,19 +2,12 @@ #define _RENDERTEXTURE_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" -class RenderTextureTest : public BaseTest -{ -public: - virtual void onEnter() override; - virtual std::string title() const override; - virtual std::string subtitle() const override; +DEFINE_TEST_SUITE(RenderTextureTests); - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; +class RenderTextureTest : public TestCase +{ }; class RenderTextureSave : public RenderTextureTest @@ -25,7 +18,7 @@ public: ~RenderTextureSave(); virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesMoved(const std::vector& touches, Event* event) override; + void onTouchesMoved(const std::vector& touches, Event* event); void clearImage(Ref *pSender); void saveImage(Ref *pSender); @@ -43,21 +36,15 @@ public: virtual std::string subtitle() const override; }; -class RenderTextureScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - class RenderTextureZbuffer : public RenderTextureTest { public: CREATE_FUNC(RenderTextureZbuffer); RenderTextureZbuffer(); - void onTouchesMoved(const std::vector& touches, Event* event) override; + void onTouchesMoved(const std::vector& touches, Event* event); void onTouchesBegan(const std::vector& touches, Event* event); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -148,7 +135,7 @@ public: CREATE_FUNC(SpriteRenderTextureBug); SpriteRenderTextureBug(); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual std::string title() const override; virtual std::string subtitle() const override; diff --git a/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.cpp b/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.cpp index 8351125918..54a9181d4e 100644 --- a/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.cpp +++ b/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.cpp @@ -1,6 +1,11 @@ #include "RotateWorldTest.h" #include "../testResource.h" +RotateWorldTests::RotateWorldTests() +{ + ADD_TEST_CASE(RotateWorldTest); +} + //------------------------------------------------------------------ // // TestLayer @@ -124,13 +129,17 @@ void RotateWorldMainLayer::onEnter() white->runAction(rot->clone()); } -void RotateWorldTestScene::runThisTest() +bool RotateWorldTest::init() { - auto layer = RotateWorldMainLayer::create(); + if (TestCase::init()) + { + auto layer = RotateWorldMainLayer::create(); - addChild(layer); - runAction( RotateBy::create(4, -360) ); + addChild(layer); + runAction(RotateBy::create(4, -360)); - Director::getInstance()->replaceScene(this); + return true; + } + return false; } diff --git a/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.h b/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.h index 2d0d9cce99..5caad0bb5d 100644 --- a/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.h +++ b/tests/cpp-tests/Classes/RotateWorldTest/RotateWorldTest.h @@ -1,12 +1,16 @@ #ifndef _ROTATE_WORLD_TEST_H_ #define _ROTATE_WORLD_TEST_H_ -#include "../testBasic.h" +#include "../BaseTest.h" -class RotateWorldTestScene : public TestScene +DEFINE_TEST_SUITE(RotateWorldTests); + +class RotateWorldTest : public TestCase { public: - virtual void runThisTest(); + CREATE_FUNC(RotateWorldTest); + + virtual bool init() override; }; class SpriteLayer : public Layer diff --git a/tests/cpp-tests/Classes/SceneTest/SceneTest.cpp b/tests/cpp-tests/Classes/SceneTest/SceneTest.cpp index 53967a7640..af141129e4 100644 --- a/tests/cpp-tests/Classes/SceneTest/SceneTest.cpp +++ b/tests/cpp-tests/Classes/SceneTest/SceneTest.cpp @@ -1,6 +1,11 @@ #include "SceneTest.h" #include "../testResource.h" +SceneTests::SceneTests() +{ + ADD_TEST_CASE(SceneTestScene); +} + //------------------------------------------------------------------ // // SceneTestLayer1 @@ -221,11 +226,13 @@ void SceneTestLayer3::item3Clicked(Ref* sender) Director::getInstance()->popToSceneStackLevel(2); } -void SceneTestScene::runThisTest() +bool SceneTestScene::init() { - auto layer = new (std::nothrow) SceneTestLayer1(); - addChild(layer); - layer->release(); + if (TestCase::init()) + { + addChild(SceneTestLayer1::create()); + return true; + } - Director::getInstance()->replaceScene(this); + return false; } diff --git a/tests/cpp-tests/Classes/SceneTest/SceneTest.h b/tests/cpp-tests/Classes/SceneTest/SceneTest.h index fd26de29f2..a41c27bb55 100644 --- a/tests/cpp-tests/Classes/SceneTest/SceneTest.h +++ b/tests/cpp-tests/Classes/SceneTest/SceneTest.h @@ -2,11 +2,14 @@ #define _SCENE_TEST_H_ ////----#include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" + +DEFINE_TEST_SUITE(SceneTests); class SceneTestLayer1 : public Layer { public: + CREATE_FUNC(SceneTestLayer1); SceneTestLayer1(); ~SceneTestLayer1(); @@ -17,27 +20,25 @@ public: void onPushScene(Ref* sender); void onPushSceneTran(Ref* sender); void onQuit(Ref* sender); - - //CREATE_NODE(SceneTestLayer1); } ; class SceneTestLayer2 : public Layer { float _timeCounter; public: + CREATE_FUNC(SceneTestLayer2); SceneTestLayer2(); void testDealloc(float dt); void onGoBack(Ref* sender); void onReplaceScene(Ref* sender); void onReplaceSceneTran(Ref* sender); - - //CREATE_NODE(SceneTestLayer2); } ; class SceneTestLayer3 : public LayerColor { public: + CREATE_FUNC(SceneTestLayer3); SceneTestLayer3(); bool init(); virtual void testDealloc(float dt); @@ -45,13 +46,14 @@ public: void item1Clicked(Ref* sender); void item2Clicked(Ref* sender); void item3Clicked(Ref* sender); - CREATE_FUNC(SceneTestLayer3) } ; -class SceneTestScene : public TestScene +class SceneTestScene : public TestCase { public: - virtual void runThisTest(); + CREATE_FUNC(SceneTestScene); + + virtual bool init() override; }; #endif diff --git a/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.cpp b/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.cpp index 9fa67e6372..c28efd2974 100644 --- a/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.cpp +++ b/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.cpp @@ -5,112 +5,29 @@ enum { kTagAnimationDance = 1, }; -static int sceneIdx = -1; - -Layer* nextSchedulerTest(); -Layer* backSchedulerTest(); -Layer* restartSchedulerTest(); - -static std::function createFunctions[] = { - CL(SchedulerTimeScale), - CL(TwoSchedulers), - CL(SchedulerAutoremove), - CL(SchedulerPauseResume), - CL(SchedulerPauseResumeAll), - CL(SchedulerPauseResumeAllUser), - CL(SchedulerUnscheduleAll), - CL(SchedulerUnscheduleAllHard), - CL(SchedulerUnscheduleAllUserLevel), - CL(SchedulerSchedulesAndRemove), - CL(SchedulerUpdate), - CL(SchedulerUpdateAndCustom), - CL(SchedulerUpdateFromCustom), - CL(RescheduleSelector), - CL(SchedulerDelayAndRepeat), - CL(SchedulerIssue2268), - CL(ScheduleCallbackTest), - CL(ScheduleUpdatePriority), - CL(SchedulerIssue10232) +SchedulerTests::SchedulerTests() +{ + ADD_TEST_CASE(SchedulerTimeScale); + ADD_TEST_CASE(TwoSchedulers); + ADD_TEST_CASE(SchedulerAutoremove); + ADD_TEST_CASE(SchedulerPauseResume); + ADD_TEST_CASE(SchedulerPauseResumeAll); + ADD_TEST_CASE(SchedulerPauseResumeAllUser); + ADD_TEST_CASE(SchedulerUnscheduleAll); + ADD_TEST_CASE(SchedulerUnscheduleAllHard); + ADD_TEST_CASE(SchedulerUnscheduleAllUserLevel); + ADD_TEST_CASE(SchedulerSchedulesAndRemove); + ADD_TEST_CASE(SchedulerUpdate); + ADD_TEST_CASE(SchedulerUpdateAndCustom); + ADD_TEST_CASE(SchedulerUpdateFromCustom); + ADD_TEST_CASE(RescheduleSelector); + ADD_TEST_CASE(SchedulerDelayAndRepeat); + ADD_TEST_CASE(SchedulerIssue2268); + ADD_TEST_CASE(ScheduleCallbackTest); + ADD_TEST_CASE(ScheduleUpdatePriority); + ADD_TEST_CASE(SchedulerIssue10232); }; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextSchedulerTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* backSchedulerTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartSchedulerTest() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -//------------------------------------------------------------------ -// -// SchedulerTestLayer -// -//------------------------------------------------------------------ -void SchedulerTestLayer::onEnter() -{ - BaseTest::onEnter(); -} - -void SchedulerTestLayer::backCallback(Ref* sender) -{ - auto scene = new (std::nothrow) SchedulerTestScene(); - auto layer = backSchedulerTest(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void SchedulerTestLayer::nextCallback(Ref* sender) -{ - auto scene = new (std::nothrow) SchedulerTestScene(); - auto layer = nextSchedulerTest(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -void SchedulerTestLayer::restartCallback(Ref* sender) -{ - auto scene = new (std::nothrow) SchedulerTestScene(); - auto layer = restartSchedulerTest(); - - scene->addChild(layer); - Director::getInstance()->replaceScene(scene); - scene->release(); -} - -std::string SchedulerTestLayer::title() const -{ - return "No title"; -} - -std::string SchedulerTestLayer::subtitle() const -{ - return ""; -} - //------------------------------------------------------------------ // // SchedulerAutoremove @@ -712,6 +629,7 @@ void SchedulerUpdateAndCustom::tick(float dt) void SchedulerUpdateAndCustom::stopSelectors(float dt) { + log("SchedulerUpdateAndCustom::stopSelectors"); unscheduleAllCallbacks(); } @@ -1201,19 +1119,6 @@ void ScheduleUpdatePriority::update(float dt) { } -//------------------------------------------------------------------ -// -// SchedulerTestScene -// -//------------------------------------------------------------------ -void SchedulerTestScene::runThisTest() -{ - auto layer = nextSchedulerTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - void SchedulerIssue10232::onEnter() { SchedulerTestLayer::onEnter(); diff --git a/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.h b/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.h index b2487a4f5c..ced27c8bb4 100644 --- a/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.h +++ b/tests/cpp-tests/Classes/SchedulerTest/SchedulerTest.h @@ -3,22 +3,15 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "../testBasic.h" #include "../BaseTest.h" USING_NS_CC_EXT; -class SchedulerTestLayer : public BaseTest +DEFINE_TEST_SUITE(SchedulerTests); + +class SchedulerTestLayer : public TestCase { public: - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; - - void backCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void restartCallback(Ref* sender) override; }; class SchedulerAutoremove : public SchedulerTestLayer @@ -319,15 +312,7 @@ public: virtual void update(float dt) override; - bool onTouchBegan(Touch* touch, Event* event) override; -}; - -class SchedulerTestScene : public TestScene -{ -public: - CREATE_FUNC(SchedulerTestScene); - - virtual void runThisTest(); + bool onTouchBegan(Touch* touch, Event* event); }; class SchedulerIssue10232 : public SchedulerTestLayer diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 1bff15d843..70b5cb826c 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -2,100 +2,19 @@ #include "../testResource.h" #include "cocos2d.h" -static int sceneIdx = -1; - -#define MAX_LAYER 11 - -static Layer* createShaderLayer(int nIndex) +ShaderTests::ShaderTests() { - switch (sceneIdx) - { - case 0: return new ShaderLensFlare(); - case 1: return new ShaderMandelbrot(); - case 2: return new ShaderJulia(); - case 3: return new ShaderHeart(); - case 4: return new ShaderFlower(); - case 5: return new ShaderPlasma(); - case 6: return new ShaderBlur(); - case 7: return new ShaderRetroEffect(); - case 8: return new ShaderMonjori(); - case 9: return new ShaderGlow(); - case 10: return new ShaderMultiTexture(); - } - return nullptr; -} - -static Layer* nextAction(void) -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createShaderLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -static Layer* backAction(void) -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createShaderLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -static Layer* restartAction(void) -{ - auto layer = createShaderLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - - -ShaderTestDemo::ShaderTestDemo() -{ - -} - -void ShaderTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) ShaderTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void ShaderTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) ShaderTestScene();//CCScene::create(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -std::string ShaderTestDemo::title() const -{ - return "No title"; -} - -std::string ShaderTestDemo::subtitle() const -{ - return ""; -} - -void ShaderTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) ShaderTestScene(); - s->addChild(restartAction()); - - Director::getInstance()->replaceScene(s); - s->release(); + ADD_TEST_CASE(ShaderLensFlare); + ADD_TEST_CASE(ShaderMandelbrot); + ADD_TEST_CASE(ShaderJulia); + ADD_TEST_CASE(ShaderHeart); + ADD_TEST_CASE(ShaderFlower); + ADD_TEST_CASE(ShaderPlasma); + ADD_TEST_CASE(ShaderBlur); + ADD_TEST_CASE(ShaderRetroEffect); + ADD_TEST_CASE(ShaderMonjori); + ADD_TEST_CASE(ShaderGlow); + ADD_TEST_CASE(ShaderMultiTexture); } ///--------------------------------------- @@ -825,17 +744,3 @@ void ShaderMultiTexture::changeTexture(Ref*) auto programState = _sprite->getGLProgramState(); programState->setUniformTexture("u_texture1", right->getTexture()); } - - -///--------------------------------------- -// -// ShaderTestScene -// -///--------------------------------------- -void ShaderTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(nextAction()); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h index 236fc426fd..6343c7e8af 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h @@ -9,24 +9,17 @@ USING_NS_CC_EXT; -class ShaderTestDemo : public BaseTest +DEFINE_TEST_SUITE(ShaderTests); + +class ShaderTestDemo : public TestCase { public: - ShaderTestDemo(void); - - virtual std::string title() const override; - virtual std::string subtitle() const override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - CREATE_FUNC(ShaderTestDemo); }; class ShaderMonjori : public ShaderTestDemo { public: + CREATE_FUNC(ShaderMonjori); ShaderMonjori(); virtual std::string title() const override; @@ -37,6 +30,7 @@ public: class ShaderMandelbrot : public ShaderTestDemo { public: + CREATE_FUNC(ShaderMandelbrot); ShaderMandelbrot(); virtual std::string title() const override; @@ -47,6 +41,7 @@ public: class ShaderJulia : public ShaderTestDemo { public: + CREATE_FUNC(ShaderJulia); ShaderJulia(); virtual std::string title() const override; @@ -57,6 +52,7 @@ public: class ShaderHeart : public ShaderTestDemo { public: + CREATE_FUNC(ShaderHeart); ShaderHeart(); virtual std::string title() const override; @@ -67,6 +63,7 @@ public: class ShaderFlower : public ShaderTestDemo { public: + CREATE_FUNC(ShaderFlower); ShaderFlower(); virtual std::string title() const override; @@ -77,6 +74,7 @@ public: class ShaderPlasma : public ShaderTestDemo { public: + CREATE_FUNC(ShaderPlasma); ShaderPlasma(); virtual std::string title() const override; @@ -88,6 +86,7 @@ class SpriteBlur; class ShaderBlur : public ShaderTestDemo { public: + CREATE_FUNC(ShaderBlur); ShaderBlur(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -105,6 +104,7 @@ protected: class ShaderRetroEffect : public ShaderTestDemo { public: + CREATE_FUNC(ShaderRetroEffect); ShaderRetroEffect(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -118,6 +118,7 @@ protected: class ShaderNode : public Node { public: + CREATE_FUNC(ShaderNode); static ShaderNode* shaderNodeWithVertex(const std::string &vert, const std::string &frag); virtual void update(float dt) override; @@ -141,15 +142,10 @@ protected: CustomCommand _customCommand; }; -class ShaderTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - class ShaderLensFlare : public ShaderTestDemo { public: + CREATE_FUNC(ShaderLensFlare); ShaderLensFlare(); virtual std::string title() const override; @@ -160,6 +156,7 @@ public: class ShaderGlow : public ShaderTestDemo { public: + CREATE_FUNC(ShaderGlow); ShaderGlow(); virtual std::string title() const override; @@ -171,6 +168,7 @@ class ShaderMultiTexture : public ShaderTestDemo { static const int rightSpriteTag = 2014; public: + CREATE_FUNC(ShaderMultiTexture); ShaderMultiTexture(); ui::Slider* createSliderCtl(); void changeTexture(Ref*); diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp index 05838f6270..908335c5e1 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp @@ -22,89 +22,16 @@ THE SOFTWARE. ****************************************************************************/ - #include "ShaderTest2.h" #include "ShaderTest.h" #include "../testResource.h" #include "cocos2d.h" #include -namespace ShaderTest2 +Shader2Tests::Shader2Tests() { - static std::function createFunctions[] = - { - CL(EffectSpriteTest), - CL(EffectSpriteLamp), - }; - - static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]); - - static int sceneIdx=-1; - Layer* createTest(int index) - { - auto layer = (createFunctions[index])();; - return layer; - } - - Layer* nextAction(); - Layer* backAction(); - Layer* restartAction(); - - Layer* nextAction() - { - sceneIdx++; - sceneIdx = sceneIdx % TEST_CASE_COUNT; - - return createTest(sceneIdx); - } - - Layer* backAction() - { - sceneIdx--; - if( sceneIdx < 0 ) - sceneIdx = TEST_CASE_COUNT -1; - - return createTest(sceneIdx); - } - - Layer* restartAction() - { - return createTest(sceneIdx); - } - -} - -ShaderTestDemo2::ShaderTestDemo2() -{ - -} - -void ShaderTestDemo2::backCallback(Ref* sender) -{ - auto s = ShaderTestScene2::create(); - s->addChild( ShaderTest2::backAction() ); - Director::getInstance()->replaceScene(s); -} - -void ShaderTestDemo2::nextCallback(Ref* sender) -{ - auto s = ShaderTestScene2::create(); - s->addChild( ShaderTest2::nextAction() ); - Director::getInstance()->replaceScene(s); -} - -void ShaderTestDemo2::restartCallback(Ref* sender) -{ - auto s = ShaderTestScene2::create(); - s->addChild(ShaderTest2::restartAction()); - Director::getInstance()->replaceScene(s); -} - -void ShaderTestScene2::runThisTest() -{ - auto layer = ShaderTest2::nextAction(); - addChild(layer); - Director::getInstance()->replaceScene(this); + ADD_TEST_CASE(EffectSpriteTest); + ADD_TEST_CASE(EffectSpriteLamp); } // diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.h b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.h index 5208eb4fda..7d9cd53c24 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.h +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.h @@ -6,24 +6,14 @@ USING_NS_CC_EXT; -class ShaderTestDemo2 : public BaseTest +DEFINE_TEST_SUITE(Shader2Tests); + +class ShaderTestDemo2 : public TestCase { public: - ShaderTestDemo2(void); virtual std::string title() const override { return "Effects on Sprites";} - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; -class ShaderTestScene2 : public TestScene -{ -public: - CREATE_FUNC(ShaderTestScene2); - virtual void runThisTest(); -}; - - // // Effect // @@ -67,9 +57,9 @@ public: virtual std::string subtitle() const {return "Sprite Lamp effects";} //callback public: - virtual void onTouchesBegan(const std::vector& touches, Event *unused_event) override; - virtual void onTouchesMoved(const std::vector& touches, Event *unused_event) override; - virtual void onTouchesEnded(const std::vector& touches, Event *unused_event) override; + virtual void onTouchesBegan(const std::vector& touches, Event *unused_event); + virtual void onTouchesMoved(const std::vector& touches, Event *unused_event); + virtual void onTouchesEnded(const std::vector& touches, Event *unused_event); protected: EffectSprite *_sprite; Effect* _effect; diff --git a/tests/cpp-tests/Classes/SpineTest/SpineTest.cpp b/tests/cpp-tests/Classes/SpineTest/SpineTest.cpp index 04d1111a2c..17f90ce7a4 100644 --- a/tests/cpp-tests/Classes/SpineTest/SpineTest.cpp +++ b/tests/cpp-tests/Classes/SpineTest/SpineTest.cpp @@ -39,110 +39,15 @@ using namespace spine; // //------------------------------------------------------------------ -static std::function createFunctions[] = +SpineTests::SpineTests() { - CL(SpineTestLayerNormal), - CL(SpineTestLayerFFD), - CL(SpineTestPerformanceLayer), -}; - -static int sceneIdx = -1; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextSpineTestLayer() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* backSpineTestLayer() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartSpineTestLayer() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void SpineTestScene::runThisTest() -{ - auto layer = nextSpineTestLayer(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -void SpineTestSceneFFD::runThisTest() -{ - auto layer = SpineTestLayer::create(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -SpineTestLayer::SpineTestLayer(void) -: BaseTest() -{ -} - -SpineTestLayer::~SpineTestLayer(void) -{ -} - -std::string SpineTestLayer::title() const -{ - return "No title"; -} - -std::string SpineTestLayer::subtitle() const -{ - return ""; -} - -void SpineTestLayer::onEnter() -{ - BaseTest::onEnter(); -} - -void SpineTestLayer::restartCallback(Ref* sender) -{ - auto s = new SpineTestScene(); - s->addChild(restartSpineTestLayer()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpineTestLayer::nextCallback(Ref* sender) -{ - auto s = new SpineTestScene(); - s->addChild( nextSpineTestLayer() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpineTestLayer::backCallback(Ref* sender) -{ - auto s = new SpineTestScene(); - s->addChild( backSpineTestLayer() ); - Director::getInstance()->replaceScene(s); - s->release(); + ADD_TEST_CASE(SpineTestLayerNormal); + ADD_TEST_CASE(SpineTestLayerFFD); + ADD_TEST_CASE(SpineTestPerformanceLayer); } bool SpineTestLayerNormal::init () { - if (!Layer::init()) return false; + if (!SpineTestLayer::init()) return false; skeletonNode = SkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas", 0.6f); skeletonNode->setScale(0.5); @@ -202,7 +107,7 @@ void SpineTestLayerNormal::update (float deltaTime) { } bool SpineTestLayerFFD::init () { - if (!Layer::init()) return false; + if (!SpineTestLayer::init()) return false; skeletonNode = SkeletonAnimation::createWithFile("spine/goblins-ffd.json", "spine/goblins-ffd.atlas", 1.5f); skeletonNode->setAnimation(0, "walk", true); @@ -238,7 +143,7 @@ void SpineTestLayerFFD::update (float deltaTime) { } bool SpineTestPerformanceLayer::init () { - if (!Layer::init()) return false; + if (!SpineTestLayer::init()) return false; scheduleUpdate(); diff --git a/tests/cpp-tests/Classes/SpineTest/SpineTest.h b/tests/cpp-tests/Classes/SpineTest/SpineTest.h index 442553820f..76a0cde152 100644 --- a/tests/cpp-tests/Classes/SpineTest/SpineTest.h +++ b/tests/cpp-tests/Classes/SpineTest/SpineTest.h @@ -27,39 +27,15 @@ #define _SPINETEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #include -class SpineTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; +DEFINE_TEST_SUITE(SpineTests); -class SpineTestSceneFFD : public TestScene -{ -public: - virtual void runThisTest(); -}; - -class SpineTestLayer : public BaseTest +class SpineTestLayer : public TestCase { protected: std::string _title; - -public: - SpineTestLayer(void); - virtual ~SpineTestLayer(void); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - // overrides - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; }; class SpineTestLayerNormal: public SpineTestLayer { diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 7e1206c41c..70faf9f517 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -38,129 +38,48 @@ #include #include "../testResource.h" -enum + +Sprite3DTests::Sprite3DTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; - - -static std::function createFunctions[] = -{ - CL(Sprite3DBasicTest), - CL(Sprite3DHitTest), - CL(AsyncLoadSprite3DTest), + ADD_TEST_CASE(Sprite3DBasicTest); + ADD_TEST_CASE(Sprite3DHitTest); + ADD_TEST_CASE(AsyncLoadSprite3DTest); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) // 3DEffect use custom shader which is not supported on WP8/WinRT yet. - CL(Sprite3DEffectTest), - CL(Sprite3DUVAnimationTest), - CL(Sprite3DFakeShadowTest), - CL(Sprite3DBasicToonShaderTest), - CL(Sprite3DLightMapTest), + ADD_TEST_CASE(Sprite3DEffectTest); + ADD_TEST_CASE(Sprite3DUVAnimationTest); + ADD_TEST_CASE(Sprite3DFakeShadowTest); + ADD_TEST_CASE(Sprite3DBasicToonShaderTest); + ADD_TEST_CASE(Sprite3DLightMapTest); #endif - CL(Sprite3DWithSkinTest), + ADD_TEST_CASE(Sprite3DWithSkinTest); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) - CL(Sprite3DWithSkinOutlineTest), + ADD_TEST_CASE(Sprite3DWithSkinOutlineTest); #endif - CL(Animate3DTest), - CL(AttachmentTest), - CL(Sprite3DReskinTest), - CL(Sprite3DWithOBBPerformanceTest), - CL(Sprite3DMirrorTest), - CL(QuaternionTest), - CL(Sprite3DEmptyTest), - CL(UseCaseSprite3D), - CL(Sprite3DForceDepthTest), - CL(Sprite3DCubeMapTest), - CL(NodeAnimationTest) + ADD_TEST_CASE(Animate3DTest); + ADD_TEST_CASE(AttachmentTest); + ADD_TEST_CASE(Sprite3DReskinTest); + ADD_TEST_CASE(Sprite3DWithOBBPerformanceTest); + ADD_TEST_CASE(Sprite3DMirrorTest); + ADD_TEST_CASE(QuaternionTest); + ADD_TEST_CASE(Sprite3DEmptyTest); + ADD_TEST_CASE(UseCaseSprite3D); + ADD_TEST_CASE(Sprite3DForceDepthTest); + ADD_TEST_CASE(Sprite3DCubeMapTest); + ADD_TEST_CASE(NodeAnimationTest); }; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextSpriteTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backSpriteTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartSpriteTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - //------------------------------------------------------------------ // // SpriteTestDemo // //------------------------------------------------------------------ -Sprite3DTestDemo::Sprite3DTestDemo(void) -: BaseTest() -{ -} - -Sprite3DTestDemo::~Sprite3DTestDemo(void) -{ -} - std::string Sprite3DTestDemo::title() const { return "No title"; } -std::string Sprite3DTestDemo::subtitle() const -{ - return ""; -} - -void Sprite3DTestDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void Sprite3DTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) Sprite3DTestScene(); - s->addChild(restartSpriteTestAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void Sprite3DTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) Sprite3DTestScene(); - s->addChild( nextSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void Sprite3DTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) Sprite3DTestScene(); - s->addChild( backSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - //------------------------------------------------------------------ // // Sprite3DForceDepthTest @@ -170,7 +89,7 @@ Sprite3DForceDepthTest::Sprite3DForceDepthTest() { auto orc = Sprite3D::create("Sprite3DTest/orc.c3b"); orc->setScale(5); - orc->setNormalizedPosition(Vec2(.5,.3)); + orc->setNormalizedPosition(Vec2(.5f,.3f)); orc->setPositionZ(40); orc->setRotation3D(Vec3(0,180,0)); orc->setGlobalZOrder(-1); @@ -905,19 +824,6 @@ std::string Sprite3DHitTest::subtitle() const return "Tap Sprite3D and Drag"; } -void Sprite3DTestScene::runThisTest() -{ - auto layer = nextSpriteTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - -Sprite3DTestScene::Sprite3DTestScene() -{ - -} - static int tuple_sort( const std::tuple &tuple1, const std::tuple &tuple2 ) { return std::get<0>(tuple1) < std::get<0>(tuple2); @@ -2506,7 +2412,7 @@ std::string Sprite3DCubeMapTest::subtitle() const void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p) { Size visibleSize = Director::getInstance()->getVisibleSize(); - auto _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1, 200); + auto _camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 0.1f, 200); _camera->setCameraFlag(CameraFlag::USER1); // create a teapot diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index c9b1d32b0a..ae02eddaeb 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -25,8 +25,7 @@ #ifndef _SPRITE3D_TEST_H_ #define _SPRITE3D_TEST_H_ -#include "../testBasic.h" -#include "../BaseTest.h" +#include "BaseTest.h" #include namespace cocos2d { @@ -38,20 +37,13 @@ namespace cocos2d { class GLProgramState; } -class Sprite3DTestDemo : public BaseTest +DEFINE_TEST_SUITE(Sprite3DTests); + +class Sprite3DTestDemo : public TestCase { public: - Sprite3DTestDemo(void); - virtual ~Sprite3DTestDemo(void); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - // overrides virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; }; class Sprite3DForceDepthTest : public Sprite3DTestDemo @@ -81,7 +73,7 @@ public: virtual std::string subtitle() const override; void addNewSpriteWithCoords(Vec2 p); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); }; class Sprite3DUVAnimationTest : public Sprite3DTestDemo @@ -125,9 +117,9 @@ public: void move3D(float elapsedTime); void updateState(float elapsedTime); bool isState(unsigned int state,unsigned int bit) const; - void onTouchesBegan(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesMoved(const std::vector& touches, cocos2d::Event *event) override; - void onTouchesEnded(const std::vector& touches, cocos2d::Event *event) override; + void onTouchesBegan(const std::vector& touches, cocos2d::Event *event); + void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); + void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); private: cocos2d::Camera * _camera; Vec3 _targetPos; @@ -149,7 +141,7 @@ public: virtual ~Sprite3DLightMapTest(); virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesMoved(const std::vector& touches, cocos2d::Event* event) override; + void onTouchesMoved(const std::vector& touches, cocos2d::Event* event); private: Camera * _camera; }; @@ -263,7 +255,7 @@ public: void addNewSpriteWithCoords(Vec2 p); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); }; class AsyncLoadSprite3DTest : public Sprite3DTestDemo @@ -294,7 +286,7 @@ public: void addNewSpriteWithCoords(Vec2 p); void switchAnimationQualityCallback(Ref* sender); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); private: std::vector _sprits; bool _highQuality; @@ -311,7 +303,7 @@ public: void addNewSpriteWithCoords(Vec2 p); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); }; class Animate3DTest : public Sprite3DTestDemo @@ -323,7 +315,7 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual void update(float dt) override; @@ -362,7 +354,7 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void addNewSpriteWithCoords(Vec2 p); @@ -378,7 +370,7 @@ public: Sprite3DReskinTest(); virtual std::string title() const override; virtual std::string subtitle() const override; - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); void addNewSpriteWithCoords(Vec2 p); void menuCallback_reSkin(Ref* sender); @@ -411,9 +403,9 @@ public: virtual void update(float dt) override; void addNewOBBWithCoords(Vec2 p); void addNewSpriteWithCoords(Vec2 p); - void onTouchesBegan(const std::vector& touches, Event* event) override; - void onTouchesEnded(const std::vector& touches, Event* event) override; - void onTouchesMoved(const std::vector& touches, Event* event) override; + void onTouchesBegan(const std::vector& touches, Event* event); + void onTouchesEnded(const std::vector& touches, Event* event); + void onTouchesMoved(const std::vector& touches, Event* event); void addOBBCallback(Ref* sender); void delOBBCallback(Ref* sender); void addOBBWithCount(float value); @@ -511,13 +503,6 @@ protected: int _vectorIndex; }; -class Sprite3DTestScene : public TestScene -{ -public: - Sprite3DTestScene(); - virtual void runThisTest(); -}; - namespace cocos2d { class TextureCube; diff --git a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp index 5ce1bc0b20..e6c271b5cc 100644 --- a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp +++ b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp @@ -28,7 +28,6 @@ #include #include "../testResource.h" - enum { kTagTileMap = 1, @@ -51,174 +50,75 @@ enum kTagSprite8, }; -enum +SpriteTests::SpriteTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART + ADD_TEST_CASE(Sprite1); + ADD_TEST_CASE(SpriteBatchNode1); + ADD_TEST_CASE(SpriteAnchorPoint); + ADD_TEST_CASE(SpriteBatchNodeAnchorPoint); + ADD_TEST_CASE(SpriteOffsetAnchorRotation); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotation); + ADD_TEST_CASE(SpriteOffsetAnchorScale); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorScale); + ADD_TEST_CASE(SpriteOffsetAnchorSkew); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkew); + ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkew); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkew); + ADD_TEST_CASE(SpriteOffsetAnchorSkewScale); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkewScale); + ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkewScale); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkewScale); + ADD_TEST_CASE(SpriteSkewNegativeScaleChildren); + ADD_TEST_CASE(SpriteBatchNodeSkewNegativeScaleChildren); + ADD_TEST_CASE(SpriteRotationalSkewNegativeScaleChildren); + ADD_TEST_CASE(SpriteBatchNodeRotationalSkewNegativeScaleChildren); + ADD_TEST_CASE(SpriteOffsetAnchorFlip); + ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorFlip); + ADD_TEST_CASE(SpriteChildrenChildren); + ADD_TEST_CASE(SpriteBatchNodeChildrenChildren); + ADD_TEST_CASE(SpriteChildrenAnchorPoint); + ADD_TEST_CASE(SpriteBatchNodeChildrenAnchorPoint); + ADD_TEST_CASE(SpriteColorOpacity); + ADD_TEST_CASE(SpriteBatchNodeColorOpacity); + ADD_TEST_CASE(SpriteZOrder); + ADD_TEST_CASE(SpriteBatchNodeZOrder); + ADD_TEST_CASE(SpriteZVertex); + ADD_TEST_CASE(SpriteBatchNodeZVertex); + ADD_TEST_CASE(SpriteAliased); + ADD_TEST_CASE(SpriteBatchNodeAliased); + ADD_TEST_CASE(SpriteNewTexture); + ADD_TEST_CASE(SpriteBatchNodeNewTexture); + ADD_TEST_CASE(SpriteFlip); + ADD_TEST_CASE(SpriteBatchNodeFlip); + ADD_TEST_CASE(SpriteAnimationSplit); + ADD_TEST_CASE(SpriteFrameTest); + ADD_TEST_CASE(SpriteFrameAliasNameTest); + ADD_TEST_CASE(SpriteFramesFromFileContent); + ADD_TEST_CASE(SpriteBatchNodeReorder); + ADD_TEST_CASE(SpriteBatchNodeReorderIssue744); + ADD_TEST_CASE(SpriteBatchNodeReorderIssue766); + ADD_TEST_CASE(SpriteBatchNodeReorderIssue767); + ADD_TEST_CASE(SpriteBatchNodeReorderSameIndex); + ADD_TEST_CASE(SpriteBatchNodeReorderOneChild); + ADD_TEST_CASE(NodeSort); + ADD_TEST_CASE(Sprite6); + ADD_TEST_CASE(SpriteHybrid); + ADD_TEST_CASE(SpriteBatchNodeChildren); + ADD_TEST_CASE(SpriteBatchNodeChildrenZ); + ADD_TEST_CASE(SpriteChildrenVisibility); + ADD_TEST_CASE(SpriteChildrenVisibilityIssue665); + ADD_TEST_CASE(SpriteBatchNodeChildrenScale); + ADD_TEST_CASE(SpriteNilTexture); + ADD_TEST_CASE(SpriteSubclass); + ADD_TEST_CASE(SpriteDoubleResolution); + ADD_TEST_CASE(SpriteBatchBug1217); + ADD_TEST_CASE(AnimationCacheTest); + ADD_TEST_CASE(AnimationCacheFile); + ADD_TEST_CASE(SpriteCullTest1); + ADD_TEST_CASE(SpriteCullTest2); + ADD_TEST_CASE(Sprite3DRotationTest); }; -static int sceneIdx = -1; - - -Layer* nextSpriteTestAction(); -Layer* backSpriteTestAction(); -Layer* restartSpriteTestAction(); - - -static std::function createFunctions[] = -{ - CL(Sprite1), - CL(SpriteBatchNode1), - CL(SpriteAnchorPoint), - CL(SpriteBatchNodeAnchorPoint), - CL(SpriteOffsetAnchorRotation), - CL(SpriteBatchNodeOffsetAnchorRotation), - CL(SpriteOffsetAnchorScale), - CL(SpriteBatchNodeOffsetAnchorScale), - CL(SpriteOffsetAnchorSkew), - CL(SpriteBatchNodeOffsetAnchorSkew), - CL(SpriteOffsetAnchorRotationalSkew), - CL(SpriteBatchNodeOffsetAnchorRotationalSkew), - CL(SpriteOffsetAnchorSkewScale), - CL(SpriteBatchNodeOffsetAnchorSkewScale), - CL(SpriteOffsetAnchorRotationalSkewScale), - CL(SpriteBatchNodeOffsetAnchorRotationalSkewScale), - CL(SpriteSkewNegativeScaleChildren), - CL(SpriteBatchNodeSkewNegativeScaleChildren), - CL(SpriteRotationalSkewNegativeScaleChildren), - CL(SpriteBatchNodeRotationalSkewNegativeScaleChildren), - CL(SpriteOffsetAnchorFlip), - CL(SpriteBatchNodeOffsetAnchorFlip), - CL(SpriteChildrenChildren), - CL(SpriteBatchNodeChildrenChildren), - CL(SpriteChildrenAnchorPoint), - CL(SpriteBatchNodeChildrenAnchorPoint), - CL(SpriteColorOpacity), - CL(SpriteBatchNodeColorOpacity), - CL(SpriteZOrder), - CL(SpriteBatchNodeZOrder), - CL(SpriteZVertex), - CL(SpriteBatchNodeZVertex), - CL(SpriteAliased), - CL(SpriteBatchNodeAliased), - CL(SpriteNewTexture), - CL(SpriteBatchNodeNewTexture), - CL(SpriteFlip), - CL(SpriteBatchNodeFlip), - CL(SpriteAnimationSplit), - CL(SpriteFrameTest), - CL(SpriteFrameAliasNameTest), - CL(SpriteFramesFromFileContent), - CL(SpriteBatchNodeReorder), - CL(SpriteBatchNodeReorderIssue744), - CL(SpriteBatchNodeReorderIssue766), - CL(SpriteBatchNodeReorderIssue767), - CL(SpriteBatchNodeReorderSameIndex), - CL(SpriteBatchNodeReorderOneChild), - CL(NodeSort), - CL(Sprite6), - CL(SpriteHybrid), - CL(SpriteBatchNodeChildren), - CL(SpriteBatchNodeChildrenZ), - CL(SpriteChildrenVisibility), - CL(SpriteChildrenVisibilityIssue665), - CL(SpriteBatchNodeChildrenScale), - CL(SpriteNilTexture), - CL(SpriteSubclass), - CL(SpriteDoubleResolution), - CL(SpriteBatchBug1217), - CL(AnimationCacheTest), - CL(AnimationCacheFile), - CL(SpriteCullTest1), - CL(SpriteCullTest2), - CL(Sprite3DRotationTest), -}; - -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -Layer* nextSpriteTestAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* backSpriteTestAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -Layer* restartSpriteTestAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -//------------------------------------------------------------------ -// -// SpriteTestDemo -// -//------------------------------------------------------------------ - -SpriteTestDemo::SpriteTestDemo(void) -: BaseTest() -{ -} - -SpriteTestDemo::~SpriteTestDemo(void) -{ -} - -std::string SpriteTestDemo::title() const -{ - return "No title"; -} - -std::string SpriteTestDemo::subtitle() const -{ - return ""; -} - -void SpriteTestDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void SpriteTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) SpriteTestScene(); - s->addChild(restartSpriteTestAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpriteTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) SpriteTestScene(); - s->addChild( nextSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void SpriteTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) SpriteTestScene(); - s->addChild( backSpriteTestAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - - //------------------------------------------------------------------ // // Sprite1 @@ -3816,15 +3716,6 @@ std::string SpriteBatchBug1217::subtitle() const return "Adding big family to spritebatch. You shall see 3 heads"; } - -void SpriteTestScene::runThisTest() -{ - auto layer = nextSpriteTestAction(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - // // SpriteOffsetAnchorSkew // diff --git a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.h b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.h index 8ba80abed7..1bdb55c08f 100644 --- a/tests/cpp-tests/Classes/SpriteTest/SpriteTest.h +++ b/tests/cpp-tests/Classes/SpriteTest/SpriteTest.h @@ -26,27 +26,17 @@ #define _SPRITE_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" #include "../BaseTest.h" #include -class SpriteTestDemo : public BaseTest +DEFINE_TEST_SUITE(SpriteTests); + +class SpriteTestDemo : public TestCase { protected: std::string _title; public: - SpriteTestDemo(void); - virtual ~SpriteTestDemo(void); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - // overrides - virtual std::string title() const override; - virtual std::string subtitle() const override; - virtual void onEnter() override; }; class Sprite1 : public SpriteTestDemo @@ -58,7 +48,7 @@ public: virtual std::string subtitle() const override; void addNewSpriteWithCoords(Vec2 p); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); }; class SpriteBatchNode1: public SpriteTestDemo @@ -67,7 +57,7 @@ public: CREATE_FUNC(SpriteBatchNode1); SpriteBatchNode1(); void addNewSpriteWithCoords(Vec2 p); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -282,7 +272,7 @@ public: SpriteNewTexture(); virtual ~SpriteNewTexture(); void addNewSprite(); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -299,7 +289,7 @@ public: SpriteBatchNodeNewTexture(); virtual ~SpriteBatchNodeNewTexture(); void addNewSprite(); - void onTouchesEnded(const std::vector& touches, Event* event) override; + void onTouchesEnded(const std::vector& touches, Event* event); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -775,10 +765,4 @@ protected: Vec3 rotation; }; -class SpriteTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/TextInputTest/TextInputTest.cpp b/tests/cpp-tests/Classes/TextInputTest/TextInputTest.cpp index 58db1c670a..7704d17070 100644 --- a/tests/cpp-tests/Classes/TextInputTest/TextInputTest.cpp +++ b/tests/cpp-tests/Classes/TextInputTest/TextInputTest.cpp @@ -1,61 +1,12 @@ -// #define COCOS2D_DEBUG 1 - #include "TextInputTest.h" -////////////////////////////////////////////////////////////////////////// -// local function -////////////////////////////////////////////////////////////////////////// - -enum -{ - kTextFieldTTFDefaultTest = 0, - kTextFieldTTFActionTest, - kTextInputTestsCount, -}; - #define FONT_NAME "fonts/Thonburi.ttf" #define FONT_SIZE 36 -static int testIdx = -1; - -KeyboardNotificationLayer* createTextInputTest(int nIndex) +TextInputTests::TextInputTests() { - switch(nIndex) - { - case kTextFieldTTFDefaultTest: return new TextFieldTTFDefaultTest(); - case kTextFieldTTFActionTest: return new TextFieldTTFActionTest(); - default: return 0; - } -} - -Layer* restartTextInputTest() -{ - TextInputTest* pContainerLayer = new (std::nothrow) TextInputTest; - pContainerLayer->autorelease(); - - auto pTestLayer = createTextInputTest(testIdx); - pTestLayer->autorelease(); - pContainerLayer->addKeyboardNotificationLayer(pTestLayer); - - return pContainerLayer; -} - -Layer* nextTextInputTest() -{ - testIdx++; - testIdx = testIdx % kTextInputTestsCount; - - return restartTextInputTest(); -} - -Layer* backTextInputTest() -{ - testIdx--; - int total = kTextInputTestsCount; - if( testIdx < 0 ) - testIdx += total; - - return restartTextInputTest(); + ADD_TEST_CASE(TextFieldTTFDefaultTest); + ADD_TEST_CASE(TextFieldTTFActionTest); } static Rect getRect(Node * node) @@ -68,57 +19,11 @@ static Rect getRect(Node * node) return rc; } -////////////////////////////////////////////////////////////////////////// -// implement TextInputTest -////////////////////////////////////////////////////////////////////////// - -TextInputTest::TextInputTest() -: _notificationLayer(0) -{ - -} - -void TextInputTest::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) TextInputTestScene(); - s->addChild(restartTextInputTest()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TextInputTest::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) TextInputTestScene(); - s->addChild( nextTextInputTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TextInputTest::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) TextInputTestScene(); - s->addChild( backTextInputTest() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TextInputTest::addKeyboardNotificationLayer(KeyboardNotificationLayer * layer) -{ - _notificationLayer = layer; - addChild(layer); -} - -std::string TextInputTest::title() const +std::string KeyboardNotificationLayer::title() const { return "text input test"; } -void TextInputTest::onEnter() -{ - BaseTest::onEnter(); -} - ////////////////////////////////////////////////////////////////////////// // implement KeyboardNotificationLayer ////////////////////////////////////////////////////////////////////////// @@ -133,12 +38,6 @@ KeyboardNotificationLayer::KeyboardNotificationLayer() _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); } -//void KeyboardNotificationLayer::registerWithTouchDispatcher() -//{ -// auto director = Director::getInstance(); -// director->getTouchDispatcher()->addTargetedDelegate(this, 0, false); -//} - void KeyboardNotificationLayer::keyboardWillShow(IMEKeyboardNotificationInfo& info) { CCLOG("TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)", @@ -460,15 +359,3 @@ void TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction(Node * node) { this->removeChild(node, true); } - -////////////////////////////////////////////////////////////////////////// -// implement TextInputTestScene -////////////////////////////////////////////////////////////////////////// - -void TextInputTestScene::runThisTest() -{ - auto layer = nextTextInputTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/TextInputTest/TextInputTest.h b/tests/cpp-tests/Classes/TextInputTest/TextInputTest.h index 2ae0057f82..31550e6e92 100644 --- a/tests/cpp-tests/Classes/TextInputTest/TextInputTest.h +++ b/tests/cpp-tests/Classes/TextInputTest/TextInputTest.h @@ -6,40 +6,21 @@ class KeyboardNotificationLayer; -/** -@brief TextInputTest for retain prev, reset, next, main menu buttons. -*/ -class TextInputTest : public BaseTest -{ - KeyboardNotificationLayer * _notificationLayer; -public: - TextInputTest(); - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - virtual std::string title() const override; - void addKeyboardNotificationLayer(KeyboardNotificationLayer * layer); - - virtual void onEnter() override; -}; +DEFINE_TEST_SUITE(TextInputTests); ////////////////////////////////////////////////////////////////////////// // KeyboardNotificationLayer for test IME keyboard notification. ////////////////////////////////////////////////////////////////////////// -class KeyboardNotificationLayer : public Layer, public IMEDelegate +class KeyboardNotificationLayer : public TestCase, public IMEDelegate { public: KeyboardNotificationLayer(); - - virtual std::string subtitle() const = 0; + virtual std::string title() const override; virtual void onClickTrackNode(bool bClicked) = 0; virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info); - // Layer bool onTouchBegan(Touch *touch, Event *event); void onTouchEnded(Touch *touch, Event *event); @@ -55,6 +36,7 @@ protected: class TextFieldTTFDefaultTest : public KeyboardNotificationLayer { public: + CREATE_FUNC(TextFieldTTFDefaultTest); // KeyboardNotificationLayer virtual std::string subtitle() const override; virtual void onClickTrackNode(bool bClicked) override; @@ -75,6 +57,7 @@ class TextFieldTTFActionTest : public KeyboardNotificationLayer, public TextFiel int _charLimit; // the textfield max char limit public: + CREATE_FUNC(TextFieldTTFActionTest); void callbackRemoveNodeWhenDidAction(Node * node); // KeyboardNotificationLayer @@ -93,10 +76,4 @@ public: virtual bool onDraw(TextFieldTTF * sender); }; -class TextInputTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // __TEXT_INPUT_TEST_H__ diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp index b402a5d0ec..2a928ed21a 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp @@ -33,117 +33,82 @@ enum { kTagSprite2 = 3, }; -static std::function createFunctions[] = +Texture2DTests::Texture2DTests() { - CL(TexturePVRv3Premult), + ADD_TEST_CASE(TexturePVRv3Premult); - CL(TextureMipMap), - CL(TextureMemoryAlloc), - CL(TextureAlias), - CL(TexturePVRMipMap), - CL(TexturePVRMipMap2), - CL(TexturePVRNonSquare), - CL(TexturePVRNPOT4444), - CL(TexturePVRNPOT8888), - CL(TexturePVRTest), - CL(TexturePVR2BPP), - CL(TexturePVR2BPPv3), - CL(TexturePVR4BPP), - CL(TexturePVR4BPPv3), - CL(TexturePVRII4BPPv3), - CL(TexturePVRRGBA8888), - CL(TexturePVRRGBA8888v3), - CL(TexturePVRBGRA8888), - CL(TexturePVRBGRA8888v3), - CL(TexturePVRRGBA4444), - CL(TexturePVRRGBA4444v3), - CL(TexturePVRRGBA4444GZ), - CL(TexturePVRRGBA4444CCZ), - CL(TexturePVRRGBA5551), - CL(TexturePVRRGBA5551v3), - CL(TexturePVRRGB565), - CL(TexturePVRRGB565v3), - CL(TexturePVRRGB888), - CL(TexturePVRRGB888v3), - CL(TexturePVRA8), - CL(TexturePVRA8v3), - CL(TexturePVRI8), - CL(TexturePVRI8v3), - CL(TexturePVRAI88), - CL(TexturePVRAI88v3), + ADD_TEST_CASE(TextureMipMap); + ADD_TEST_CASE(TextureMemoryAlloc); + ADD_TEST_CASE(TextureAlias); + ADD_TEST_CASE(TexturePVRMipMap); + ADD_TEST_CASE(TexturePVRMipMap2); + ADD_TEST_CASE(TexturePVRNonSquare); + ADD_TEST_CASE(TexturePVRNPOT4444); + ADD_TEST_CASE(TexturePVRNPOT8888); + ADD_TEST_CASE(TexturePVRTest); + ADD_TEST_CASE(TexturePVR2BPP); + ADD_TEST_CASE(TexturePVR2BPPv3); + ADD_TEST_CASE(TexturePVR4BPP); + ADD_TEST_CASE(TexturePVR4BPPv3); + ADD_TEST_CASE(TexturePVRII4BPPv3); + ADD_TEST_CASE(TexturePVRRGBA8888); + ADD_TEST_CASE(TexturePVRRGBA8888v3); + ADD_TEST_CASE(TexturePVRBGRA8888); + ADD_TEST_CASE(TexturePVRBGRA8888v3); + ADD_TEST_CASE(TexturePVRRGBA4444); + ADD_TEST_CASE(TexturePVRRGBA4444v3); + ADD_TEST_CASE(TexturePVRRGBA4444GZ); + ADD_TEST_CASE(TexturePVRRGBA4444CCZ); + ADD_TEST_CASE(TexturePVRRGBA5551); + ADD_TEST_CASE(TexturePVRRGBA5551v3); + ADD_TEST_CASE(TexturePVRRGB565); + ADD_TEST_CASE(TexturePVRRGB565v3); + ADD_TEST_CASE(TexturePVRRGB888); + ADD_TEST_CASE(TexturePVRRGB888v3); + ADD_TEST_CASE(TexturePVRA8); + ADD_TEST_CASE(TexturePVRA8v3); + ADD_TEST_CASE(TexturePVRI8); + ADD_TEST_CASE(TexturePVRI8v3); + ADD_TEST_CASE(TexturePVRAI88); + ADD_TEST_CASE(TexturePVRAI88v3); - CL(TexturePVRv3Premult), + ADD_TEST_CASE(TexturePVRv3Premult); - CL(TexturePVRBadEncoding), - CL(TexturePNG), - CL(TextureJPEG), - CL(TextureTIFF), - CL(TextureTGA), + ADD_TEST_CASE(TexturePVRBadEncoding); + ADD_TEST_CASE(TexturePNG); + ADD_TEST_CASE(TextureJPEG); + ADD_TEST_CASE(TextureTIFF); + ADD_TEST_CASE(TextureTGA); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) - CL(TextureWEBP), + ADD_TEST_CASE(TextureWEBP); #endif - CL(TexturePixelFormat), - CL(TextureBlend), - CL(TextureAsync), - CL(TextureGlClamp), - CL(TextureGlRepeat), - CL(TextureSizeTest), - CL(TextureCache1), - CL(TextureDrawAtPoint), - CL(TextureDrawInRect), + ADD_TEST_CASE(TexturePixelFormat); + ADD_TEST_CASE(TextureBlend); + ADD_TEST_CASE(TextureAsync); + ADD_TEST_CASE(TextureGlClamp); + ADD_TEST_CASE(TextureGlRepeat); + ADD_TEST_CASE(TextureSizeTest); + ADD_TEST_CASE(TextureCache1); + ADD_TEST_CASE(TextureDrawAtPoint); + ADD_TEST_CASE(TextureDrawInRect); - CL(TextureETC1), + ADD_TEST_CASE(TextureETC1); - CL(TextureS3TCDxt1), - CL(TextureS3TCDxt3), - CL(TextureS3TCDxt5), - CL(TextureS3TCWithNoMipmaps), + ADD_TEST_CASE(TextureS3TCDxt1); + ADD_TEST_CASE(TextureS3TCDxt3); + ADD_TEST_CASE(TextureS3TCDxt5); + ADD_TEST_CASE(TextureS3TCWithNoMipmaps); - CL(TextureATITCRGB), - CL(TextureATITCExplicit), - CL(TextureATITCInterpolated), + ADD_TEST_CASE(TextureATITCRGB); + ADD_TEST_CASE(TextureATITCExplicit); + ADD_TEST_CASE(TextureATITCInterpolated); - CL(TextureConvertRGB888), - CL(TextureConvertRGBA8888), - CL(TextureConvertI8), - CL(TextureConvertAI88), + ADD_TEST_CASE(TextureConvertRGB888); + ADD_TEST_CASE(TextureConvertRGBA8888); + ADD_TEST_CASE(TextureConvertI8); + ADD_TEST_CASE(TextureConvertAI88); }; -static unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]); - -static int sceneIdx=-1; -Layer* createTextureTest(int index) -{ - auto layer = (createFunctions[index])();; - return layer; -} - -Layer* nextTextureTest(); -Layer* backTextureTest(); -Layer* restartTextureTest(); - -Layer* nextTextureTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % TEST_CASE_COUNT; - - return createTextureTest(sceneIdx); -} - -Layer* backTextureTest() -{ - sceneIdx--; - if( sceneIdx < 0 ) - sceneIdx = TEST_CASE_COUNT -1; - - return createTextureTest(sceneIdx); -} - -Layer* restartTextureTest() -{ - return createTextureTest(sceneIdx); -} - //------------------------------------------------------------------ // // TextureDemo @@ -151,14 +116,12 @@ Layer* restartTextureTest() //------------------------------------------------------------------ void TextureDemo::onEnter() { - BaseTest::onEnter(); - - auto textureCache = Director::getInstance()->getTextureCache(); - log("%s\n", textureCache->getCachedTextureInfo().c_str()); + TestCase::onEnter(); auto col = LayerColor::create(Color4B(128,128,128,255)); addChild(col, -10); - + + auto textureCache = Director::getInstance()->getTextureCache(); log("%s\n", textureCache->getCachedTextureInfo().c_str()); } @@ -169,37 +132,6 @@ TextureDemo::~TextureDemo() log("%s\n", textureCache->getCachedTextureInfo().c_str()); } -void TextureDemo::restartCallback(Ref* sender) -{ - auto s = TextureTestScene::create(); - s->addChild(restartTextureTest()); - Director::getInstance()->replaceScene(s); -} - -void TextureDemo::nextCallback(Ref* sender) -{ - auto s = TextureTestScene::create(); - s->addChild(nextTextureTest()); - Director::getInstance()->replaceScene(s); -} - -void TextureDemo::backCallback(Ref* sender) -{ - auto s = TextureTestScene::create(); - s->addChild(backTextureTest()); - Director::getInstance()->replaceScene(s); -} - -std::string TextureDemo::title() const -{ - return "No title"; -} - -std::string TextureDemo::subtitle() const -{ - return ""; -} - //------------------------------------------------------------------ // // TextureTIFF @@ -1902,18 +1834,6 @@ std::string TextureDrawInRect::subtitle() const return "draws 2 textures using drawInRect"; } -//------------------------------------------------------------------ -// -// TextureTestScene -// -//------------------------------------------------------------------ -void TextureTestScene::runThisTest() -{ - auto layer = nextTextureTest(); - addChild(layer); - Director::getInstance()->replaceScene(this); -} - //------------------------------------------------------------------ // // TextureMemoryAlloc diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.h b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.h index 1e237c2fae..ce4834ae73 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.h +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.h @@ -26,21 +26,15 @@ #ifndef __TEXTURE2D_TEST_H__ #define __TEXTURE2D_TEST_H__ -#include "../testBasic.h" #include "../BaseTest.h" +DEFINE_TEST_SUITE(Texture2DTests); -class TextureDemo : public BaseTest +class TextureDemo : public TestCase { public: virtual ~TextureDemo(); - virtual std::string title() const override; - virtual std::string subtitle() const override; virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; }; class TextureTIFF : public TextureDemo @@ -411,6 +405,8 @@ class TextureAsync : public TextureDemo public: CREATE_FUNC(TextureAsync); virtual ~TextureAsync(); + + virtual float getDuration() const override { return 5.0f; } void loadImages(float dt); void imageLoaded(cocos2d::Texture2D* texture); virtual std::string title() const override; @@ -490,13 +486,6 @@ protected: Texture2D* _tex1, *_Tex2F; }; -class TextureTestScene : public TestScene -{ -public: - CREATE_FUNC(TextureTestScene); - virtual void runThisTest(); -}; - class TextureMemoryAlloc : public TextureDemo { public: diff --git a/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.cpp b/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.cpp index 433d0f83b4..dd884f9880 100644 --- a/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.cpp +++ b/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.cpp @@ -1,4 +1,3 @@ - #include "TextureCacheTest.h" // enable log @@ -6,6 +5,11 @@ USING_NS_CC; +TextureCacheTests::TextureCacheTests() +{ + ADD_TEST_CASE(TextureCacheTest); +} + TextureCacheTest::TextureCacheTest() : _numberOfSprites(20) , _numberOfLoadedSprites(0) @@ -126,13 +130,3 @@ void TextureCacheTest::addSprite() this->addChild(s14); this->addChild(s15); } - - -void TextureCacheTestScene::runThisTest() -{ - auto layer = new (std::nothrow) TextureCacheTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.h b/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.h index b273c31943..20dabeb40b 100644 --- a/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.h +++ b/tests/cpp-tests/Classes/TextureCacheTest/TextureCacheTest.h @@ -3,15 +3,21 @@ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class TextureCacheTest : public Layer +DEFINE_TEST_SUITE(TextureCacheTests); + +class TextureCacheTest : public TestCase { public: + CREATE_FUNC(TextureCacheTest); + TextureCacheTest(); + void addSprite(); void loadingCallBack(cocos2d::Texture2D *texture); + virtual float getDuration() const override { return 3.5f; } private: cocos2d::Label *_labelLoading; cocos2d::Label *_labelPercent; @@ -19,10 +25,4 @@ private: int _numberOfLoadedSprites; }; -class TextureCacheTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _TEXTURECACHE_TEST_H_ diff --git a/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp b/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp index dc37f2fe0d..28b57d782b 100644 --- a/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp +++ b/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp @@ -1,19 +1,19 @@ #include "TextureAtlasEncryptionTest.h" #include "../testResource.h" +TextureAtlasEncryptionTests::TextureAtlasEncryptionTests() +{ + ADD_TEST_CASE(TextureAtlasEncryptionDemo); +} + std::string TextureAtlasEncryptionDemo::title() const { return "Texture Atlas Encryption"; } -std::string TextureAtlasEncryptionDemo::subtitle() const -{ - return ""; -} - void TextureAtlasEncryptionDemo::onEnter() { - Layer::onEnter(); + TestCase::onEnter(); auto s = Director::getInstance()->getWinSize(); @@ -68,14 +68,3 @@ void TextureAtlasEncryptionDemo::onEnter() encryptedSpriteLabel->setPosition(Vec2(s.width * 0.75f, encryptedSprite->getBoundingBox().getMinY() - encryptedSpriteLabel->getContentSize().height/2)); this->addChild(encryptedSpriteLabel, 1); } - -void TextureAtlasEncryptionTestScene::runThisTest() -{ - auto layer = new (std::nothrow) TextureAtlasEncryptionDemo; - layer->autorelease(); - - addChild(layer); - - Director::getInstance()->replaceScene(this); -} - diff --git a/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h b/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h index 4b722477ef..c525cf53c5 100644 --- a/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h +++ b/tests/cpp-tests/Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h @@ -2,24 +2,21 @@ #define _TextureAtlasEncryption_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" #include -class TextureAtlasEncryptionDemo : public Layer +DEFINE_TEST_SUITE(TextureAtlasEncryptionTests); + +class TextureAtlasEncryptionDemo : public TestCase { public: + CREATE_FUNC(TextureAtlasEncryptionDemo); + virtual std::string title() const; - virtual std::string subtitle() const; virtual void onEnter() override; protected: std::string _title; }; -class TextureAtlasEncryptionTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp index 530e1eabfa..a276566e4d 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp @@ -6,93 +6,54 @@ enum kTagTileMap = 1, }; -Layer* nextTileMapAction(); -Layer* backTileMapAction(); -Layer* restartTileMapAction(); - //------------------------------------------------------------------ // // TileDemo // //------------------------------------------------------------------ -enum + +TileMapTests::TileMapTests() { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART -}; - -static int sceneIdx = -1; - -#define MAX_LAYER 29 - -static std::function createFunctions[] = { - CLN(TMXIsoZorder), - CLN(TMXOrthoZorder), - CLN(TMXStaggeredTest), - CLN(TMXIsoVertexZ), - CLN(TMXOrthoVertexZ), - CLN(TMXOrthoTest), - CLN(TMXOrthoTest2), - CLN(TMXOrthoTest3), - CLN(TMXOrthoTest4), - CLN(TMXIsoTest), - CLN(TMXIsoTest1), - CLN(TMXIsoTest2), - CLN(TMXUncompressedTest), - CLN(TMXHexTest), - CLN(TMXReadWriteTest), - CLN(TMXTilesetTest), - CLN(TMXOrthoObjectsTest), - CLN(TMXIsoObjectsTest), - CLN(TMXResizeTest), - CLN(TMXIsoMoveLayer), - CLN(TMXOrthoMoveLayer), - CLN(TMXOrthoFlipTest), - CLN(TMXOrthoFlipRunTimeTest), - CLN(TMXOrthoFromXMLTest), - CLN(TMXOrthoXMLFormatTest), - CLN(TileMapTest), - CLN(TileMapEditTest), - CLN(TMXBug987), - CLN(TMXBug787), - CLN(TMXGIDObjectsTest), - -}; - -Layer* createTileMalayer(int nIndex) -{ - return createFunctions[nIndex](); + ADD_TEST_CASE(TMXIsoZorder); + ADD_TEST_CASE(TMXOrthoZorder); + ADD_TEST_CASE(TMXStaggeredTest); + ADD_TEST_CASE(TMXIsoVertexZ); + ADD_TEST_CASE(TMXOrthoVertexZ); + ADD_TEST_CASE(TMXOrthoTest); + ADD_TEST_CASE(TMXOrthoTest2); + ADD_TEST_CASE(TMXOrthoTest3); + ADD_TEST_CASE(TMXOrthoTest4); + ADD_TEST_CASE(TMXIsoTest); + ADD_TEST_CASE(TMXIsoTest1); + ADD_TEST_CASE(TMXIsoTest2); + ADD_TEST_CASE(TMXUncompressedTest); + ADD_TEST_CASE(TMXHexTest); + ADD_TEST_CASE(TMXReadWriteTest); + ADD_TEST_CASE(TMXTilesetTest); + ADD_TEST_CASE(TMXOrthoObjectsTest); + ADD_TEST_CASE(TMXIsoObjectsTest); + ADD_TEST_CASE(TMXResizeTest); + ADD_TEST_CASE(TMXIsoMoveLayer); + ADD_TEST_CASE(TMXOrthoMoveLayer); + ADD_TEST_CASE(TMXOrthoFlipTest); + ADD_TEST_CASE(TMXOrthoFlipRunTimeTest); + ADD_TEST_CASE(TMXOrthoFromXMLTest); + ADD_TEST_CASE(TMXOrthoXMLFormatTest); + ADD_TEST_CASE(TileMapTest); + ADD_TEST_CASE(TileMapEditTest); + ADD_TEST_CASE(TMXBug987); + ADD_TEST_CASE(TMXBug787); + ADD_TEST_CASE(TMXGIDObjectsTest); } -Layer* nextTileMapAction() +TileDemo::TileDemo() { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; + // fix bug #486, #419. + // "test" is the default value in Director::setGLDefaultValues() + // but TransitionTest may setDepthTest(false), we should revert it here + Director::getInstance()->setDepthTest(true); - return createTileMalayer(sceneIdx); -} - -Layer* backTileMapAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - return createTileMalayer(sceneIdx); -} - -Layer* restartTileMapAction() -{ - return createTileMalayer(sceneIdx); -} - - -TileDemo::TileDemo(void) -: BaseTest() -{ auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesMoved = CC_CALLBACK_2(TileDemo::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); @@ -112,40 +73,11 @@ std::string TileDemo::subtitle() const return "drag the screen"; } -void TileDemo::onEnter() -{ - BaseTest::onEnter(); -} - void TileDemo::onExit() { - BaseTest::onExit(); + TestCase::onExit(); Director::getInstance()->setDepthTest(false); } -void TileDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestScene(); - s->addChild(restartTileMapAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TileDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestScene(); - s->addChild( nextTileMapAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TileDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestScene(); - s->addChild( backTileMapAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} void TileDemo::onTouchesMoved(const std::vector& touches, Event *event) { @@ -157,20 +89,6 @@ void TileDemo::onTouchesMoved(const std::vector& touches, Event *event) node->setPosition(currentPos + diff); } -void TileMapTestScene::runThisTest() -{ - auto layer = nextTileMapAction(); - addChild(layer); - - // fix bug #486, #419. - // "test" is the default value in Director::setGLDefaultValues() - // but TransitionTest may setDepthTest(false), we should revert it here - Director::getInstance()->setDepthTest(true); - - Director::getInstance()->replaceScene(this); -} - - //------------------------------------------------------------------ // // TileMapTest diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h index 10c1d2141c..bb90f02005 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h @@ -1,38 +1,36 @@ #ifndef _TILEMAP_TEST_H_ #define _TILEMAP_TEST_H_ -#include "../testBasic.h" #include "../BaseTest.h" -class TileDemo : public BaseTest +DEFINE_TEST_SUITE(TileMapTests); + +class TileDemo : public TestCase { public: - TileDemo(void); - virtual ~TileDemo(void); + TileDemo(); + virtual ~TileDemo(); virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void onEnter() override; virtual void onExit() override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - void onTouchesMoved(const std::vector& touches, Event *event) override; + void onTouchesMoved(const std::vector& touches, Event *event); }; class TileMapTest : public TileDemo { public: - TileMapTest(void); + CREATE_FUNC(TileMapTest); + TileMapTest(); virtual std::string title() const override; }; class TileMapEditTest : public TileDemo { public: - TileMapEditTest (void); + CREATE_FUNC(TileMapEditTest); + TileMapEditTest (); virtual std::string title() const override; void updateMap(float dt); @@ -41,7 +39,8 @@ public: class TMXOrthoTest : public TileDemo { public: - TMXOrthoTest(void); + CREATE_FUNC(TMXOrthoTest); + TMXOrthoTest(); virtual std::string title() const override; virtual void onEnter() override; @@ -51,7 +50,8 @@ public: class TMXStaggeredTest : public TileDemo { public: - TMXStaggeredTest(void); + CREATE_FUNC(TMXStaggeredTest); + TMXStaggeredTest(); virtual std::string title() const override; virtual void onEnter() override; @@ -61,21 +61,24 @@ public: class TMXOrthoTest2 : public TileDemo { public: - TMXOrthoTest2(void); + CREATE_FUNC(TMXOrthoTest2); + TMXOrthoTest2(); virtual std::string title() const override; }; class TMXOrthoTest3 : public TileDemo { public: - TMXOrthoTest3(void); + CREATE_FUNC(TMXOrthoTest3); + TMXOrthoTest3(); virtual std::string title() const override; }; class TMXOrthoTest4 : public TileDemo { public: - TMXOrthoTest4(void); + CREATE_FUNC(TMXOrthoTest4); + TMXOrthoTest4(); void removeSprite(float dt); virtual std::string title() const override; }; @@ -85,7 +88,8 @@ class TMXReadWriteTest : public TileDemo unsigned int _gid; unsigned int _gid2; public: - TMXReadWriteTest(void); + CREATE_FUNC(TMXReadWriteTest); + TMXReadWriteTest(); virtual std::string title() const override; void removeSprite(Node* sender); @@ -97,42 +101,48 @@ public: class TMXHexTest : public TileDemo { public: - TMXHexTest(void); + CREATE_FUNC(TMXHexTest); + TMXHexTest(); virtual std::string title() const override; }; class TMXIsoTest : public TileDemo { public: - TMXIsoTest(void); + CREATE_FUNC(TMXIsoTest); + TMXIsoTest(); virtual std::string title() const override; }; class TMXIsoTest1 : public TileDemo { public: - TMXIsoTest1(void); + CREATE_FUNC(TMXIsoTest1); + TMXIsoTest1(); virtual std::string title() const override; }; class TMXIsoTest2 : public TileDemo { public: - TMXIsoTest2(void); + CREATE_FUNC(TMXIsoTest2); + TMXIsoTest2(); virtual std::string title() const override; }; class TMXUncompressedTest : public TileDemo { public: - TMXUncompressedTest(void); + CREATE_FUNC(TMXUncompressedTest); + TMXUncompressedTest(); virtual std::string title() const override; }; class TMXTilesetTest : public TileDemo { public: - TMXTilesetTest(void); + CREATE_FUNC(TMXTilesetTest); + TMXTilesetTest(); virtual std::string title() const override; }; @@ -141,7 +151,8 @@ public: class TMXOrthoObjectsTest : public TileDemo { public: - TMXOrthoObjectsTest(void); + CREATE_FUNC(TMXOrthoObjectsTest); + TMXOrthoObjectsTest(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -150,7 +161,8 @@ public: class TMXIsoObjectsTest : public TileDemo { public: - TMXIsoObjectsTest(void); + CREATE_FUNC(TMXIsoObjectsTest); + TMXIsoObjectsTest(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -159,7 +171,8 @@ public: class TMXResizeTest : public TileDemo { public: - TMXResizeTest(void); + CREATE_FUNC(TMXResizeTest); + TMXResizeTest(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -169,10 +182,11 @@ class TMXIsoZorder : public TileDemo { Sprite* _tamara; public: - TMXIsoZorder(void); + CREATE_FUNC(TMXIsoZorder); + TMXIsoZorder(); virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void onExit(void); + virtual void onExit(); ~TMXIsoZorder(); void repositionSprite(float dt); @@ -182,7 +196,8 @@ class TMXOrthoZorder : public TileDemo { Sprite* _tamara; public: - TMXOrthoZorder(void); + CREATE_FUNC(TMXOrthoZorder); + TMXOrthoZorder(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -194,7 +209,8 @@ class TMXIsoVertexZ : public TileDemo { Sprite* _tamara; public: - TMXIsoVertexZ(void); + CREATE_FUNC(TMXIsoVertexZ); + TMXIsoVertexZ(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -208,7 +224,8 @@ class TMXOrthoVertexZ : public TileDemo { Sprite* _tamara; public: - TMXOrthoVertexZ(void); + CREATE_FUNC(TMXOrthoVertexZ); + TMXOrthoVertexZ(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -221,7 +238,8 @@ public: class TMXIsoMoveLayer : public TileDemo { public: - TMXIsoMoveLayer(void); + CREATE_FUNC(TMXIsoMoveLayer); + TMXIsoMoveLayer(); virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -229,7 +247,8 @@ public: class TMXOrthoMoveLayer : public TileDemo { public: - TMXOrthoMoveLayer(void); + CREATE_FUNC(TMXOrthoMoveLayer); + TMXOrthoMoveLayer(); virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -237,6 +256,7 @@ public: class TMXTilePropertyTest : public TileDemo { public: + CREATE_FUNC(TMXTilePropertyTest); TMXTilePropertyTest(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -245,6 +265,7 @@ public: class TMXOrthoFlipTest : public TileDemo { public: + CREATE_FUNC(TMXOrthoFlipTest); TMXOrthoFlipTest(); virtual std::string title() const override; }; @@ -252,6 +273,7 @@ public: class TMXOrthoFlipRunTimeTest : public TileDemo { public: + CREATE_FUNC(TMXOrthoFlipRunTimeTest); TMXOrthoFlipRunTimeTest(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -261,6 +283,7 @@ public: class TMXOrthoFromXMLTest : public TileDemo { public: + CREATE_FUNC(TMXOrthoFromXMLTest); TMXOrthoFromXMLTest(); virtual std::string title() const override; }; @@ -268,6 +291,7 @@ public: class TMXOrthoXMLFormatTest : public TileDemo { public: + CREATE_FUNC(TMXOrthoXMLFormatTest); TMXOrthoXMLFormatTest(); virtual std::string title() const override; }; @@ -275,6 +299,7 @@ public: class TMXBug987 : public TileDemo { public: + CREATE_FUNC(TMXBug987); TMXBug987(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -283,6 +308,7 @@ public: class TMXBug787 : public TileDemo { public: + CREATE_FUNC(TMXBug787); TMXBug787(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -291,15 +317,10 @@ public: class TMXGIDObjectsTest : public TileDemo { public: + CREATE_FUNC(TMXGIDObjectsTest); TMXGIDObjectsTest(); virtual std::string title() const override; virtual std::string subtitle() const override; }; -class TileMapTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp index 623725b0d4..66db937a3b 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp @@ -5,105 +5,57 @@ #include "2d/CCFastTMXTiledMap.h" -namespace +enum { - enum - { - kTagTileMap = 1, - }; - - Layer* nextTileMapActionNew(); - Layer* backTileMapActionNew(); - Layer* restartTileMapAction(); - - //------------------------------------------------------------------ - // - // TileDemoNew - // - //------------------------------------------------------------------ - - enum - { - IDC_NEXT = 100, - IDC_BACK, - IDC_RESTART - }; - - static int sceneIdx = -1; - - static std::function createFunctions[] = { - CLN(TMXIsoZorderNew), - CLN(TMXOrthoZorderNew), - CLN(TMXIsoVertexZNew), - CLN(TMXOrthoVertexZNew), - CLN(TMXOrthoTestNew), - CLN(TMXOrthoTest2New), - CLN(TMXOrthoTest3New), - CLN(TMXOrthoTest4New), - CLN(TMXIsoTestNew), - CLN(TMXIsoTest1New), - CLN(TMXIsoTest2New), - CLN(TMXUncompressedTestNew), - CLN(TMXHexTestNew), - CLN(TMXReadWriteTestNew), - CLN(TMXTilesetTestNew), - CLN(TMXOrthoObjectsTestNew), - CLN(TMXIsoObjectsTestNew), - CLN(TMXResizeTestNew), - CLN(TMXIsoMoveLayerNew), - CLN(TMXOrthoMoveLayerNew), - CLN(TMXOrthoFlipTestNew), - CLN(TMXOrthoFlipRunTimeTestNew), - CLN(TMXOrthoFromXMLTestNew), - CLN(TMXOrthoXMLFormatTestNew), - CLN(TileMapTestNew), - CLN(TileMapEditTestNew), - CLN(TMXBug987New), - CLN(TMXBug787New), - CLN(TMXGIDObjectsTestNew), - - }; + kTagTileMap = 1, +}; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - - Layer* createTileMalayer(int nIndex) - { - return createFunctions[nIndex](); - } - - Layer* nextTileMapAction() - { - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - return createTileMalayer(sceneIdx); - } - - Layer* backTileMapAction() - { - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - return createTileMalayer(sceneIdx); - } - - Layer* restartTileMapAction() - { - return createTileMalayer(sceneIdx); - } +FastTileMapTests::FastTileMapTests() +{ + ADD_TEST_CASE(TMXIsoZorderNew); + ADD_TEST_CASE(TMXOrthoZorderNew); + ADD_TEST_CASE(TMXIsoVertexZNew); + ADD_TEST_CASE(TMXOrthoVertexZNew); + ADD_TEST_CASE(TMXOrthoTestNew); + ADD_TEST_CASE(TMXOrthoTest2New); + ADD_TEST_CASE(TMXOrthoTest3New); + ADD_TEST_CASE(TMXOrthoTest4New); + ADD_TEST_CASE(TMXIsoTestNew); + ADD_TEST_CASE(TMXIsoTest1New); + ADD_TEST_CASE(TMXIsoTest2New); + ADD_TEST_CASE(TMXUncompressedTestNew); + ADD_TEST_CASE(TMXHexTestNew); + ADD_TEST_CASE(TMXReadWriteTestNew); + ADD_TEST_CASE(TMXTilesetTestNew); + ADD_TEST_CASE(TMXOrthoObjectsTestNew); + ADD_TEST_CASE(TMXIsoObjectsTestNew); + ADD_TEST_CASE(TMXResizeTestNew); + ADD_TEST_CASE(TMXIsoMoveLayerNew); + ADD_TEST_CASE(TMXOrthoMoveLayerNew); + ADD_TEST_CASE(TMXOrthoFlipTestNew); + ADD_TEST_CASE(TMXOrthoFlipRunTimeTestNew); + ADD_TEST_CASE(TMXOrthoFromXMLTestNew); + ADD_TEST_CASE(TMXOrthoXMLFormatTestNew); + ADD_TEST_CASE(TileMapTestNew); + ADD_TEST_CASE(TileMapEditTestNew); + ADD_TEST_CASE(TMXBug987New); + ADD_TEST_CASE(TMXBug787New); + ADD_TEST_CASE(TMXGIDObjectsTestNew); } -TileDemoNew::TileDemoNew(void) -: BaseTest() +TileDemoNew::TileDemoNew() { + // fix bug #486, #419. + // "test" is the default value in Director::setGLDefaultValues() + // but TransitionTest may setDepthTest(false), we should revert it here + Director::getInstance()->setDepthTest(true); + auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesMoved = CC_CALLBACK_2(TileDemoNew::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); } -TileDemoNew::~TileDemoNew(void) +TileDemoNew::~TileDemoNew() { } @@ -117,40 +69,11 @@ std::string TileDemoNew::subtitle() const return "drag the screen"; } -void TileDemoNew::onEnter() -{ - BaseTest::onEnter(); -} - void TileDemoNew::onExit() { - BaseTest::onExit(); + TestCase::onExit(); Director::getInstance()->setDepthTest(false); } -void TileDemoNew::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestSceneNew(); - s->addChild(restartTileMapAction()); - - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TileDemoNew::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestSceneNew(); - s->addChild( nextTileMapAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void TileDemoNew::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) TileMapTestSceneNew(); - s->addChild( backTileMapAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} void TileDemoNew::onTouchesMoved(const std::vector& touches, Event *event) { @@ -162,20 +85,6 @@ void TileDemoNew::onTouchesMoved(const std::vector& touches, Event *eve node->setPosition(currentPos + diff); } -void TileMapTestSceneNew::runThisTest() -{ - auto layer = nextTileMapAction(); - addChild(layer); - - // fix bug #486, #419. - // "test" is the default value in Director::setGLDefaultValues() - // but TransitionTest may setDepthTest(false), we should revert it here - Director::getInstance()->setDepthTest(true); - - Director::getInstance()->replaceScene(this); -} - - //------------------------------------------------------------------ // // TileMapTestNew diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.h b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.h index a37cd1730d..b8c8afa12f 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.h +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.h @@ -1,38 +1,36 @@ #ifndef _TILEMAP_TEST_NEW_H_ #define _TILEMAP_TEST_NEW_H_ -#include "../testBasic.h" #include "../BaseTest.h" -class TileDemoNew : public BaseTest +DEFINE_TEST_SUITE(FastTileMapTests); + +class TileDemoNew : public TestCase { public: - TileDemoNew(void); - virtual ~TileDemoNew(void); + TileDemoNew(); + virtual ~TileDemoNew(); virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void onEnter() override; virtual void onExit() override; - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - void onTouchesMoved(const std::vector& touches, Event *event) override; + void onTouchesMoved(const std::vector& touches, Event *event); }; class TileMapTestNew : public TileDemoNew { public: - TileMapTestNew(void); + CREATE_FUNC(TileMapTestNew); + TileMapTestNew(); virtual std::string title() const override; }; class TileMapEditTestNew : public TileDemoNew { public: - TileMapEditTestNew (void); + CREATE_FUNC(TileMapEditTestNew); + TileMapEditTestNew (); virtual std::string title() const override; void updateMap(float dt); @@ -41,7 +39,8 @@ public: class TMXOrthoTestNew : public TileDemoNew { public: - TMXOrthoTestNew(void); + CREATE_FUNC(TMXOrthoTestNew); + TMXOrthoTestNew(); virtual std::string title() const override; virtual void onEnter() override; @@ -51,21 +50,24 @@ public: class TMXOrthoTest2New : public TileDemoNew { public: - TMXOrthoTest2New(void); + CREATE_FUNC(TMXOrthoTest2New); + TMXOrthoTest2New(); virtual std::string title() const override; }; class TMXOrthoTest3New : public TileDemoNew { public: - TMXOrthoTest3New(void); + CREATE_FUNC(TMXOrthoTest3New); + TMXOrthoTest3New(); virtual std::string title() const override; }; class TMXOrthoTest4New : public TileDemoNew { public: - TMXOrthoTest4New(void); + CREATE_FUNC(TMXOrthoTest4New); + TMXOrthoTest4New(); void removeSprite(float dt); virtual std::string title() const override; }; @@ -75,7 +77,8 @@ class TMXReadWriteTestNew : public TileDemoNew unsigned int _gid; unsigned int _gid2; public: - TMXReadWriteTestNew(void); + CREATE_FUNC(TMXReadWriteTestNew); + TMXReadWriteTestNew(); virtual std::string title() const override; void removeSprite(Node* sender); @@ -87,51 +90,56 @@ public: class TMXHexTestNew : public TileDemoNew { public: - TMXHexTestNew(void); + CREATE_FUNC(TMXHexTestNew); + TMXHexTestNew(); virtual std::string title() const override; }; class TMXIsoTestNew : public TileDemoNew { public: - TMXIsoTestNew(void); + CREATE_FUNC(TMXIsoTestNew); + TMXIsoTestNew(); virtual std::string title() const override; }; class TMXIsoTest1New : public TileDemoNew { public: - TMXIsoTest1New(void); + CREATE_FUNC(TMXIsoTest1New); + TMXIsoTest1New(); virtual std::string title() const override; }; class TMXIsoTest2New : public TileDemoNew { public: - TMXIsoTest2New(void); + CREATE_FUNC(TMXIsoTest2New); + TMXIsoTest2New(); virtual std::string title() const override; }; class TMXUncompressedTestNew : public TileDemoNew { public: - TMXUncompressedTestNew(void); + CREATE_FUNC(TMXUncompressedTestNew); + TMXUncompressedTestNew(); virtual std::string title() const override; }; class TMXTilesetTestNew : public TileDemoNew { public: - TMXTilesetTestNew(void); + CREATE_FUNC(TMXTilesetTestNew); + TMXTilesetTestNew(); virtual std::string title() const override; }; - - class TMXOrthoObjectsTestNew : public TileDemoNew { public: - TMXOrthoObjectsTestNew(void); + CREATE_FUNC(TMXOrthoObjectsTestNew); + TMXOrthoObjectsTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -140,7 +148,8 @@ public: class TMXIsoObjectsTestNew : public TileDemoNew { public: - TMXIsoObjectsTestNew(void); + CREATE_FUNC(TMXIsoObjectsTestNew); + TMXIsoObjectsTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -149,7 +158,8 @@ public: class TMXResizeTestNew : public TileDemoNew { public: - TMXResizeTestNew(void); + CREATE_FUNC(TMXResizeTestNew); + TMXResizeTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -159,10 +169,11 @@ class TMXIsoZorderNew : public TileDemoNew { Sprite* _tamara; public: - TMXIsoZorderNew(void); + CREATE_FUNC(TMXIsoZorderNew); + TMXIsoZorderNew(); virtual std::string title() const override; virtual std::string subtitle() const override; - virtual void onExit(void); + virtual void onExit(); ~TMXIsoZorderNew(); void repositionSprite(float dt); @@ -172,7 +183,8 @@ class TMXOrthoZorderNew : public TileDemoNew { Sprite* _tamara; public: - TMXOrthoZorderNew(void); + CREATE_FUNC(TMXOrthoZorderNew); + TMXOrthoZorderNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -184,7 +196,8 @@ class TMXIsoVertexZNew : public TileDemoNew { Sprite* _tamara; public: - TMXIsoVertexZNew(void); + CREATE_FUNC(TMXIsoVertexZNew); + TMXIsoVertexZNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -198,7 +211,8 @@ class TMXOrthoVertexZNew : public TileDemoNew { Sprite* _tamara; public: - TMXOrthoVertexZNew(void); + CREATE_FUNC(TMXOrthoVertexZNew); + TMXOrthoVertexZNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -211,7 +225,8 @@ public: class TMXIsoMoveLayerNew : public TileDemoNew { public: - TMXIsoMoveLayerNew(void); + CREATE_FUNC(TMXIsoMoveLayerNew); + TMXIsoMoveLayerNew(); virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -219,7 +234,8 @@ public: class TMXOrthoMoveLayerNew : public TileDemoNew { public: - TMXOrthoMoveLayerNew(void); + CREATE_FUNC(TMXOrthoMoveLayerNew); + TMXOrthoMoveLayerNew(); virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -227,6 +243,7 @@ public: class TMXTilePropertyTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXTilePropertyTestNew); TMXTilePropertyTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -235,6 +252,7 @@ public: class TMXOrthoFlipTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXOrthoFlipTestNew); TMXOrthoFlipTestNew(); virtual std::string title() const override; }; @@ -242,6 +260,7 @@ public: class TMXOrthoFlipRunTimeTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXOrthoFlipRunTimeTestNew); TMXOrthoFlipRunTimeTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -251,6 +270,7 @@ public: class TMXOrthoFromXMLTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXOrthoFromXMLTestNew); TMXOrthoFromXMLTestNew(); virtual std::string title() const override; }; @@ -258,6 +278,7 @@ public: class TMXOrthoXMLFormatTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXOrthoXMLFormatTestNew); TMXOrthoXMLFormatTestNew(); virtual std::string title() const override; }; @@ -265,6 +286,7 @@ public: class TMXBug987New : public TileDemoNew { public: + CREATE_FUNC(TMXBug987New); TMXBug987New(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -273,6 +295,7 @@ public: class TMXBug787New : public TileDemoNew { public: + CREATE_FUNC(TMXBug787New); TMXBug787New(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -281,15 +304,10 @@ public: class TMXGIDObjectsTestNew : public TileDemoNew { public: + CREATE_FUNC(TMXGIDObjectsTestNew); TMXGIDObjectsTestNew(); virtual std::string title() const override; virtual std::string subtitle() const override; }; -class TileMapTestSceneNew : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif diff --git a/tests/cpp-tests/Classes/TouchesTest/TouchesTest.cpp b/tests/cpp-tests/Classes/TouchesTest/TouchesTest.cpp index e6b56661aa..248cc5b653 100644 --- a/tests/cpp-tests/Classes/TouchesTest/TouchesTest.cpp +++ b/tests/cpp-tests/Classes/TouchesTest/TouchesTest.cpp @@ -17,17 +17,25 @@ enum kSpriteTag }; - +TouchesTests::TouchesTests() +{ + ADD_TEST_CASE(PongScene); +} //------------------------------------------------------------------ // // PongScene // //------------------------------------------------------------------ -PongScene::PongScene() +bool PongScene::init() { - auto pongLayer = new (std::nothrow) PongLayer();//PongLayer::create(); - addChild(pongLayer); - pongLayer->release(); + if (TestCase::init()) + { + auto pongLayer = PongLayer::create(); + addChild(pongLayer); + + return true; + } + return false; } //------------------------------------------------------------------ @@ -100,9 +108,4 @@ void PongLayer::doStep(float delta) resetAndScoreBallForPlayer( kLowPlayer ); else if (_ball->getPosition().y < VisibleRect::bottom().y-_ball->radius()) resetAndScoreBallForPlayer( kHighPlayer ); -} - -void PongScene::runThisTest() -{ - Director::getInstance()->replaceScene(this); } diff --git a/tests/cpp-tests/Classes/TouchesTest/TouchesTest.h b/tests/cpp-tests/Classes/TouchesTest/TouchesTest.h index 873ced2c58..733ba5eaa5 100644 --- a/tests/cpp-tests/Classes/TouchesTest/TouchesTest.h +++ b/tests/cpp-tests/Classes/TouchesTest/TouchesTest.h @@ -1,17 +1,18 @@ #ifndef _TOUCHES_TEST__H_ #define _TOUCHES_TEST__H_ -////----#include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" USING_NS_CC; -class PongScene : public TestScene +DEFINE_TEST_SUITE(TouchesTests); + +class PongScene : public TestCase { public: - PongScene(); - - virtual void runThisTest(); + CREATE_FUNC(PongScene); + + virtual bool init() override; }; class Ball; @@ -23,6 +24,7 @@ private: Vector _paddles; Vec2 _ballStartingVelocity; public: + CREATE_FUNC(PongLayer); PongLayer(); ~PongLayer(); diff --git a/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.cpp b/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.cpp index 1a3abb4682..d4b2cb68b4 100644 --- a/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.cpp +++ b/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.cpp @@ -227,31 +227,50 @@ struct _transitions { TRANS(TransitionSlideInB), }; - -#define MAX_LAYER (sizeof(transitions) / sizeof(transitions[0])) - - -static int s_nSceneIdx = 0; - -TransitionScene* createTransition(int index, float t, Scene* s) +TransitionsTests::TransitionsTests() { - // fix bug #486, without setDepthTest(false), FlipX,Y will flickers - Director::getInstance()->setDepthTest(false); + int sceneIndex = 0; - return transitions[index].function(t,s); + for (auto& test : transitions) + { + addTestCase(test.name, [sceneIndex](){ + auto scene = TransitionsTest::create(); + // fix bug #486, without setDepthTest(false), FlipX,Y will flickers + Director::getInstance()->setDepthTest(false); + + if (sceneIndex % 2) + { + scene->addChild(TestLayer2::create(transitions[sceneIndex].name)); + } + else + { + scene->addChild(TestLayer1::create(transitions[sceneIndex].name)); + } + + return transitions[sceneIndex].function(TRANSITION_DURATION, scene); + }); + + sceneIndex++; + } } - -void TransitionsTestScene::runThisTest() +TestLayer1* TestLayer1::create(const std::string& transitionName) { - auto layer = new (std::nothrow) TestLayer1(); - addChild(layer); - layer->release(); + auto layer = new (std::nothrow) TestLayer1(transitionName); + if (layer && layer->init()) + { + layer->autorelease(); + } + else + { + delete layer; + layer = nullptr; + } - Director::getInstance()->replaceScene(this); + return layer; } -TestLayer1::TestLayer1(void) +TestLayer1::TestLayer1(const std::string& transitionName) { float x,y; @@ -263,7 +282,7 @@ TestLayer1::TestLayer1(void) bg1->setPosition( Vec2(size.width/2, size.height/2) ); addChild(bg1, -1); - auto title = Label::createWithTTF( (transitions[s_nSceneIdx]).name, "fonts/Thonburi.ttf", 32 ); + auto title = Label::createWithTTF(transitionName, "fonts/Thonburi.ttf", 32); addChild(title); title->setColor( Color3B(255,32,32) ); title->setPosition( Vec2(x/2, y-100) ); @@ -273,84 +292,14 @@ TestLayer1::TestLayer1(void) label->setPosition( Vec2(x/2,y/2)); addChild( label); - // menu - auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(TestLayer1::backCallback, this) ); - auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(TestLayer1::restartCallback, this) ); - auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(TestLayer1::nextCallback, this) ); - - auto menu = Menu::create(item1, item2, item3, nullptr); - - menu->setPosition( Vec2::ZERO ); - item1->setPosition(Vec2(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(Vec2(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); - schedule( CC_SCHEDULE_SELECTOR(TestLayer1::step), 1.0f); } -TestLayer1::~TestLayer1(void) +TestLayer1::~TestLayer1() { } -void TestLayer1::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer2(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - -void TestLayer1::nextCallback(Ref* sender) -{ - s_nSceneIdx++; - s_nSceneIdx = s_nSceneIdx % MAX_LAYER; - - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer2(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - -void TestLayer1::backCallback(Ref* sender) -{ - s_nSceneIdx--; - int total = MAX_LAYER; - if( s_nSceneIdx < 0 ) - s_nSceneIdx += total; - - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer2(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - void TestLayer1::step(float dt) { @@ -381,7 +330,23 @@ void TestLayer1::onExit() log("Scene 1 onExit"); } -TestLayer2::TestLayer2() +TestLayer2* TestLayer2::create(const std::string& transitionName) +{ + auto layer = new (std::nothrow) TestLayer2(transitionName); + if (layer && layer->init()) + { + layer->autorelease(); + } + else + { + delete layer; + layer = nullptr; + } + + return layer; +} + +TestLayer2::TestLayer2(const std::string& transitionName) { float x,y; @@ -393,7 +358,7 @@ TestLayer2::TestLayer2() bg1->setPosition( Vec2(size.width/2, size.height/2) ); addChild(bg1, -1); - auto title = Label::createWithTTF((transitions[s_nSceneIdx]).name, "fonts/Thonburi.ttf", 32 ); + auto title = Label::createWithTTF(transitionName, "fonts/Thonburi.ttf", 32); addChild(title); title->setColor( Color3B(255,32,32) ); title->setPosition( Vec2(x/2, y-100) ); @@ -403,20 +368,6 @@ TestLayer2::TestLayer2() label->setPosition( Vec2(x/2,y/2)); addChild( label); - // menu - auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(TestLayer2::backCallback, this) ); - auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(TestLayer2::restartCallback, this) ); - auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(TestLayer2::nextCallback, this) ); - - auto menu = Menu::create(item1, item2, item3, nullptr); - - menu->setPosition( Vec2::ZERO ); - item1->setPosition(Vec2(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(Vec2(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); - schedule(CC_SCHEDULE_SELECTOR(TestLayer2::step), 1.0f); } @@ -425,62 +376,6 @@ TestLayer2::~TestLayer2() } -void TestLayer2::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer1(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - -void TestLayer2::nextCallback(Ref* sender) -{ - s_nSceneIdx++; - s_nSceneIdx = s_nSceneIdx % MAX_LAYER; - - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer1(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - -void TestLayer2::backCallback(Ref* sender) -{ - s_nSceneIdx--; - int total = MAX_LAYER; - if( s_nSceneIdx < 0 ) - s_nSceneIdx += total; - - auto s = new (std::nothrow) TransitionsTestScene(); - - auto layer = new (std::nothrow) TestLayer1(); - s->addChild(layer); - - auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); - s->release(); - layer->release(); - if (scene) - { - Director::getInstance()->replaceScene(scene); - } -} - void TestLayer2::step(float dt) { diff --git a/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.h b/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.h index dfe7ac182f..4ca1036ace 100644 --- a/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.h +++ b/tests/cpp-tests/Classes/TransitionsTest/TransitionsTest.h @@ -26,25 +26,25 @@ #ifndef _TRANSITIONS_TEST_H_ #define _TRANSITIONS_TEST_H_ -#include "../testBasic.h" +#include "../BaseTest.h" USING_NS_CC; -class TransitionsTestScene : public TestScene +DEFINE_TEST_SUITE(TransitionsTests); + +class TransitionsTest : public TestCase { public: - virtual void runThisTest(); + CREATE_FUNC(TransitionsTest); }; class TestLayer1 : public Layer { public: - TestLayer1(void); - ~TestLayer1(void); + static TestLayer1* create(const std::string& transitionName); - void restartCallback(Ref* sender); - void nextCallback(Ref* sender); - void backCallback(Ref* sender); + TestLayer1(const std::string& transitionName); + ~TestLayer1(); void step(float dt); @@ -57,12 +57,10 @@ public: class TestLayer2 : public Layer { public: - TestLayer2(void); - ~TestLayer2(void); + static TestLayer2* create(const std::string& transitionName); - void restartCallback(Ref* sender); - void nextCallback(Ref* sender); - void backCallback(Ref* sender); + TestLayer2(const std::string& transitionName); + ~TestLayer2(); void step(float dt); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.cpp index 73c54d4754..e69de29bb2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.cpp @@ -1,150 +0,0 @@ - - -#include "CocoStudioGUITest.h" -#include "../../ExtensionsTest/ExtensionsTest.h" -#include "CocosGUIScene.h" -#include "GUIEditorTest.h" -#include "CustomGUIScene.h" -#include "controller.h" -#include "cocostudio/CocoStudio.h" -#include "CocostudioParserTest.h" - -enum -{ - LINE_SPACE = 40, - kItemTagBasic = 1000, -}; - -static struct -{ - const char *name; - std::function callback; -} -g_guisTests[] = -{ - { - "GUI Dynamic Create Test", - [](Ref* sender) - { - CocosGUITestScene *scene = new (std::nothrow) CocosGUITestScene(); - scene->runThisTest(); - scene->release(); - } - }, - { - "GUI Editor Test", - [](Ref* sender) - { - GUIEditorTestScene* scene = new (std::nothrow) GUIEditorTestScene(); - scene->runThisTest(); - scene->release(); - } - }, - { - "Custom GUI Test", - [](Ref* sender) - { - CustomGUITestScene* scene = new (std::nothrow) CustomGUITestScene(); - scene->runThisTest(); - scene->release(); - } - }, - { - "Cocostudio Parser Test", - [](Ref* sender) - { - CocostudioParserTestScene* scene = new (std::nothrow) CocostudioParserTestScene(); - scene->runThisTest(); - scene->release(); - } - }, -}; - -static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]); - -//////////////////////////////////////////////////////// -// -// CocoStudioGUIMainLayer -// -//////////////////////////////////////////////////////// - -static Vec2 _curPos = Vec2::ZERO; - -void CocoStudioGUIMainLayer::onEnter() -{ - using namespace ui; - - CCLayer::onEnter(); - - Size s = Director::getInstance()->getWinSize(); - - _itemMenu = CCMenu::create(); - _itemMenu->setPosition(Vec2::ZERO); - CCMenuItemFont::setFontName("fonts/arial.ttf"); - CCMenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback); - pItem->setPosition(s.width / 2, s.height / 4 * 3 - (i + 1) * LINE_SPACE); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - addChild(_itemMenu); -} - -void CocoStudioGUIMainLayer::onTouchesBegan(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - - -//////////////////////////////////////////////////////// -// -// CocoStudioGUITestScene -// -//////////////////////////////////////////////////////// - -void CocoStudioGUITestScene::onEnter() -{ - CCScene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocoStudioGUITestScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} - -void CocoStudioGUITestScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CocoStudioGUIMainLayer(); - addChild(pLayer); - pLayer->release(); - - CCDirector::getInstance()->replaceScene(this); -} - -void CocoStudioGUITestScene::BackCallback(Ref* pSender) -{ - auto scene = Scene::create(); - - auto layer = new (std::nothrow) TestController(); - scene->addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(scene); - - cocostudio::ArmatureDataManager::destroyInstance(); -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.h index 4f2ec3e041..7aaf36631d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocoStudioGUITest.h @@ -1,28 +1,5 @@ - - #ifndef __TestCpp__CocoStudioGUITest__ #define __TestCpp__CocoStudioGUITest__ -#include "../../testBasic.h" - -class CocoStudioGUIMainLayer : public Layer -{ -public: - virtual void onEnter() override; - void onTouchesBegan(const std::vector& touches, Event *event) override; -// void onTouchesMoved(const std::vector& touches, Event *event) override; - -private: - Vec2 _beginPos; - Menu* _itemMenu; -}; - -class CocoStudioGUITestScene : public TestScene -{ -public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(Ref* pSender); -}; #endif /* defined(__TestCpp__CocoStudioGUITest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index b5489b4451..99765e720d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -1,375 +1,62 @@ #include "CocosGUIScene.h" -#include "CocoStudioGUITest.h" -#include "UISceneManager.h" -#include "cocostudio/CocoStudio.h" -enum -{ - LINE_SPACE = 40, - kItemTagBasic = 1000, -}; - -static struct -{ - const char *name; - std::function callback; -} -g_guisTests[] = -{ +#include "UIButtonTest/UIButtonTest.h" +#include "UICheckBoxTest/UICheckBoxTest.h" +#include "UISliderTest/UISliderTest.h" +#include "UIImageViewTest/UIImageViewTest.h" +#include "UILoadingBarTest/UILoadingBarTest.h" +#include "UITextAtlasTest/UITextAtlasTest.h" +#include "UITextTest/UITextTest.h" +#include "UITextBMFontTest/UITextBMFontTest.h" +#include "UITextFieldTest/UITextFieldTest.h" +#include "UILayoutTest/UILayoutTest.h" +#include "UIScrollViewTest/UIScrollViewTest.h" +#include "UIPageViewTest/UIPageViewTest.h" +#include "UIListViewTest/UIListViewTest.h" +#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h" +#include "UIRichTextTest/UIRichTextTest.h" +#include "UIFocusTest/UIFocusTest.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - { - "VideoPlayerTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIVideoPlayerTest); - sceneManager->setMinUISceneId(kUIVideoPlayerTest); - sceneManager->setMaxUISceneId(kUIVideoPlayerTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, +#include "UIVideoPlayerTest/UIVideoPlayerTest.h" #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - { - "WebViewTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(KWebViewTest); - sceneManager->setMinUISceneId(KWebViewTest); - sceneManager->setMaxUISceneId(KWebViewTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, +#include "UIWebViewTest/UIWebViewTest.h" +#endif +#include "UIScale9SpriteTest.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) +#include "UIEditBoxTest.h" +#endif + +GUIDynamicCreateTests::GUIDynamicCreateTests() +{ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + addTest("VideoPlayer Test", [](){ return new (std::nothrow) VideoPlayerTests; }); +#endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + addTest("WebView Test", [](){ return new (std::nothrow) WebViewTests; }); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - { - "EditBox Test", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIEditBoxTest); - sceneManager->setMinUISceneId(kUIEditBoxTest); - sceneManager->setMaxUISceneId(kUIEditBoxTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - #endif - { - "focus test", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(KUIFocusTest_HBox); - sceneManager->setMinUISceneId(KUIFocusTest_HBox); - // TODO: improve ListView focus - sceneManager->setMaxUISceneId(KUIFocusTest_NestedLayout3); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "Scale9 Sprite Test", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIScale9SpriteTest); - sceneManager->setMinUISceneId(kUIScale9SpriteTest); - sceneManager->setMaxUISceneId(kUIS9ChangeAnchorPoint); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - - "ButtonTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIButtonTest); - sceneManager->setMinUISceneId(kUIButtonTest); - sceneManager->setMaxUISceneId(kUIButtonDisableDefaultTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "CheckBoxTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUICheckBoxTest); - sceneManager->setMinUISceneId(kUICheckBoxTest); - sceneManager->setMaxUISceneId(kUICheckBoxDefaultBehaviorTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "SliderTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUISliderTest); - sceneManager->setMinUISceneId(kUISliderTest); - sceneManager->setMaxUISceneId(kUISliderDisabledDefaultTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "ImageViewTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIImageViewTest); - sceneManager->setMinUISceneId(kUIImageViewTest); - sceneManager->setMaxUISceneId(kUIImageViewFlipTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "LoadingBarTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUILoadingBarTest_Left); - sceneManager->setMinUISceneId(kUILoadingBarTest_Left); - sceneManager->setMaxUISceneId(kUILoadingBarReloadTexture); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "TextAtlasTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUITextAtlasTest); - sceneManager->setMinUISceneId(kUITextAtlasTest); - sceneManager->setMaxUISceneId(kUITextAtlasTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "TextTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUITextTest); - sceneManager->setMinUISceneId(kUITextTest); - sceneManager->setMaxUISceneId(kUITextTest_IgnoreConentSize); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "TextBMFontTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUITextBMFontTest); - sceneManager->setMinUISceneId(kUITextBMFontTest); - sceneManager->setMaxUISceneId(kUITextBMFontTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "TextFieldTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUITextFieldTest); - sceneManager->setMinUISceneId(kUITextFieldTest); - sceneManager->setMaxUISceneId(kUITextFieldTest_PlaceHolderColor); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "LayoutTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUILayoutTest); - sceneManager->setMinUISceneId(kUILayoutTest); - sceneManager->setMaxUISceneId(kUILayoutComponent_Berth_Stretch_Test); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "ScrollViewTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIScrollViewTest_Vertical); - sceneManager->setMinUISceneId(kUIScrollViewTest_Vertical); - sceneManager->setMaxUISceneId(kUIScrollViewRotated); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "PageViewTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIPageViewTest); - sceneManager->setMinUISceneId(kUIPageViewTest); - sceneManager->setMaxUISceneId(kUIPageViewDynamicAddAndRemoveTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "ListViewTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIListViewTest_Vertical); - sceneManager->setMinUISceneId(kUIListViewTest_Vertical); - sceneManager->setMaxUISceneId(kUIListViewTest_Horizontal); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "WidgetAddNodeTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIWidgetAddNodeTest); - sceneManager->setMinUISceneId(kUIWidgetAddNodeTest); - sceneManager->setMaxUISceneId(kUIWidgetAddNodeTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - { - "RichTextTest", - [](Ref* sender) - { - UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); - sceneManager->setCurrentUISceneId(kUIRichTextTest); - sceneManager->setMinUISceneId(kUIRichTextTest); - sceneManager->setMaxUISceneId(kUIRichTextTest); - Scene* scene = sceneManager->currentUIScene(); - Director::getInstance()->replaceScene(scene); - } - }, - -}; - -static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]); - -static Vec2 s_tCurPos = Vec2::ZERO; - -//////////////////////////////////////////////////////// -// -// CocosGUITestMainLayer -// -//////////////////////////////////////////////////////// -void CocosGUITestMainLayer::onEnter() -{ - Layer::onEnter(); + addTest("EditBox Test", [](){ return new (std::nothrow) UIEditBoxTests; }); +#endif + addTest("Focus Test", [](){ return new (std::nothrow) UIFocusTests; }); + addTest("Scale9Sprite Test", [](){ return new (std::nothrow) UIScale9SpriteTests; }); + addTest("Button Test", [](){ return new (std::nothrow) UIButtonTests; }); + addTest("CheckBox Test", [](){ return new (std::nothrow) UICheckBoxTests; }); + addTest("Slider Test", [](){ return new (std::nothrow) UISliderTests; }); + + addTest("ImageView Test", [](){ return new (std::nothrow) UIImageViewTests; }); + addTest("LoadingBar Test", [](){ return new (std::nothrow) UILoadingBarTests; }); + addTest("TextAtlas Test", [](){ return new (std::nothrow) UITextAtlasTests; }); - auto s = Director::getInstance()->getWinSize(); + addTest("Text Test", [](){ return new (std::nothrow) UITextTests; }); + addTest("TextBMFont Test", [](){ return new (std::nothrow) UITextBMFontTests; }); + addTest("TextField Test", [](){ return new (std::nothrow) UITextFieldTests; }); + addTest("Layout Test", [](){ return new (std::nothrow) UILayoutTests; }); - _itemMenu = Menu::create(); - _itemMenu->setPosition( s_tCurPos ); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback); - pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } + addTest("ScrollView Test", [](){ return new (std::nothrow) UIScrollViewTests; }); + addTest("PageView Test", [](){ return new (std::nothrow) UIPageViewTests; }); + addTest("ListView Test", [](){ return new (std::nothrow) UIListViewTests; }); - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(CocosGUITestMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(CocosGUITestMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - - addChild(_itemMenu); -} - -void CocosGUITestMainLayer::onTouchesBegan(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - -void CocosGUITestMainLayer::onTouchesMoved(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - auto touchLocation = touch->getLocation(); - float nMoveY = touchLocation.y - _beginPos.y; - - auto curPos = _itemMenu->getPosition(); - auto nextPos = Vec2(curPos.x, curPos.y + nMoveY); - - if (nextPos.y < 0.0f) - { - _itemMenu->setPosition(Vec2::ZERO); - return; - } - - if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) - { - _itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)); - return; - } - - _itemMenu->setPosition(nextPos); - _beginPos = touchLocation; - s_tCurPos = nextPos; -} - -//////////////////////////////////////////////////////// -// -// CocosGUITestScene -// -//////////////////////////////////////////////////////// - -void CocosGUITestScene::onEnter() -{ - Scene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - auto pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocosGUITestScene::BackCallback, this)); - - Menu* pMenu =Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} - -void CocosGUITestScene::runThisTest() -{ - auto layer = new (std::nothrow) CocosGUITestMainLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); -} - -void CocosGUITestScene::BackCallback(Ref* pSender) -{ - CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene(); - pScene->runThisTest(); - pScene->release(); + addTest("WidgetAddNode Test", [](){ return new (std::nothrow) UIWidgetAddNodeTests; }); + addTest("RichText Test", [](){ return new (std::nothrow) UIRichTextTests; }); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.h index 51e02f512e..3acf5cf004 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.h @@ -25,36 +25,8 @@ #ifndef __TestCpp__CocosGUIScene__ #define __TestCpp__CocosGUIScene__ -#include "cocos2d.h" -#include "extensions/cocos-ext.h" -#include "../../testBasic.h" -#include "ui/CocosGUI.h" - -USING_NS_CC; -USING_NS_CC_EXT; -using namespace cocos2d::ui; - -class CocosGUITestMainLayer : public Layer -{ -public: - virtual void onEnter() override; - - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; - - Vec2 _beginPos; - Menu* _itemMenu; - - int _testcount; -}; - -class CocosGUITestScene : public TestScene -{ -public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(Ref* pSender); -}; +#include "BaseTest.h" +DEFINE_TEST_LIST(GUIDynamicCreateTests); #endif /* defined(__TestCpp__CocosGUIScene__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp index 0738ea0e5d..631efa239a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - Copyright (c) 2013-2014 Chukong Technologies Inc. + Copyright (c) 2013-2015 Chukong Technologies Inc. http://www.cocos2d-x.org @@ -23,133 +23,11 @@ ****************************************************************************/ #include "CocostudioParserTest.h" - -#include "CocoStudioGUITest.h" #include "CocostudioParserTest/CocostudioParserJsonTest.h" -enum +CocostudioParserTests::CocostudioParserTests() { - LINE_SPACE = 40, - kItemTagBasic = 1000, -}; - -static struct -{ - const char *name; - std::function callback; + addTestCase("cocostudio 1.3", [](){ return CocostudioParserJsonScene::create("cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson"); }); + addTestCase("cocostudio 1.4", [](){ return CocostudioParserJsonScene::create("cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson"); }); + addTestCase("cocostudio 1.5", [](){ return CocostudioParserJsonScene::create("cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson"); }); } -g_guisTests[] = -{ - { - "cocostudio 1.3", - [](Ref* sender) - { - CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson"); - pScene->runThisTest(); - pScene->release(); - } - }, - { - "cocostudio 1.4", - [](Ref* sender) - { - CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson"); - pScene->runThisTest(); - pScene->release(); - } - }, - { - "cocostudio 1.5", - [](Ref* sender) - { - CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson"); - pScene->runThisTest(); - pScene->release(); - } - }, - -}; - -static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]); - -//////////////////////////////////////////////////////// -// -// CocostudioParserTestMainLayer -// -//////////////////////////////////////////////////////// - -static Vec2 _curPos = Vec2::ZERO; - - -void CocostudioParserTestMainLayer::onEnter() -{ - Layer::onEnter(); - - auto s = Director::getInstance()->getWinSize(); - - _itemMenu = Menu::create(); - _itemMenu->setPosition( _curPos ); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback); - // pItem->setPosition(s.width / 2, s.height / 2); - pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(CocostudioParserTestMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(CocostudioParserTestMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - - addChild(_itemMenu); -} - -void CocostudioParserTestMainLayer::onTouchesBegan(const std::vector &touches, cocos2d::Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - - -//////////////////////////////////////////////////////// -// -// CocostudioParserTestScene -// -//////////////////////////////////////////////////////// - -void CocostudioParserTestScene::onEnter() -{ - CCScene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocostudioParserTestScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} - -void CocostudioParserTestScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CocostudioParserTestMainLayer(); - addChild(pLayer); - pLayer->release(); - - CCDirector::getInstance()->replaceScene(this); -} - -void CocostudioParserTestScene::BackCallback(Ref* pSender) -{ - CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene(); - pScene->runThisTest(); - pScene->release(); -} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.h index 9f4822e6c9..1c2feae9dd 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest.h @@ -25,34 +25,8 @@ #ifndef __cocos2d_tests__CocostudioParserTest__ #define __cocos2d_tests__CocostudioParserTest__ -#include "cocos2d.h" -#include "extensions/cocos-ext.h" -#include "../../testBasic.h" -#include "ui/CocosGUI.h" +#include "../../BaseTest.h" -USING_NS_CC; -USING_NS_CC_EXT; -using namespace cocos2d::ui; - -class CocostudioParserTestMainLayer : public Layer -{ -public: - virtual void onEnter() override; - void onTouchesBegan(const std::vector& touches, Event *event) override; - - void touchEvent(Ref* pSender, Widget::TouchEventType type); - -private: - Vec2 _beginPos; - Menu* _itemMenu; -}; - -class CocostudioParserTestScene : public TestScene -{ -public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(Ref* pSender); -}; +DEFINE_TEST_SUITE(CocostudioParserTests); #endif /* defined(__cocos2d_tests__CocostudioParserTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp index d9d2b5768f..33ca899466 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp @@ -63,39 +63,23 @@ void CocostudioParserJsonLayer::onEnter() // CocostudioParserJsonScene -CocostudioParserJsonScene::CocostudioParserJsonScene(std::string jsonFile) -{ - _jsonFile = jsonFile; -} -void CocostudioParserJsonScene::onEnter() +CocostudioParserJsonScene* CocostudioParserJsonScene::create(const std::string& jsonFile) { - CCScene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocostudioParserJsonScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} + auto scene = new (std::nothrow) CocostudioParserJsonScene; + if (scene && scene->init()) + { + auto layer = new (std::nothrow) CocostudioParserJsonLayer(jsonFile); + scene->addChild(layer); + layer->release(); -void CocostudioParserJsonScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CocostudioParserJsonLayer(_jsonFile); - addChild(pLayer); - pLayer->release(); + scene->autorelease(); + } + else + { + delete scene; + scene = nullptr; + } - CCDirector::getInstance()->replaceScene(this); + return scene; } - -void CocostudioParserJsonScene::BackCallback(Ref* pSender) -{ - CocostudioParserTestScene* pScene = new (std::nothrow) CocostudioParserTestScene(); - pScene->runThisTest(); - pScene->release(); -} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.h index acf89628b2..0b27966640 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.h @@ -26,7 +26,7 @@ #define __cocos2d_tests__CocostudioParserJsonTest__ #include "cocos2d.h" -#include "../../../testBasic.h" +#include "../../../BaseTest.h" class CocostudioParserJsonLayer : public cocos2d::Layer { @@ -38,16 +38,12 @@ private: std::string _jsonFile; }; -class CocostudioParserJsonScene : public TestScene +class CocostudioParserJsonScene : public TestCase { public: - CocostudioParserJsonScene(std::string jsonFile); - ~CocostudioParserJsonScene(){} - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(cocos2d::Ref* pSender); -private: - std::string _jsonFile; + static CocostudioParserJsonScene* create(const std::string& jsonFile); + + virtual std::string title() const override { return getTestCaseName(); } }; #endif /* defined(__cocos2d_tests__CocostudioParserJsonTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp index 4deea07fa6..57011dc169 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp @@ -1,159 +1,12 @@ - - #include "CustomGUIScene.h" -#include "CocoStudioGUITest.h" + #include "CustomTest/CustomImageTest/CustomImageTest.h" #include "CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.h" #include "CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.h" - -enum +CustomGUITests::CustomGUITests() { - LINE_SPACE = 40, - kItemTagBasic = 1000, -}; - -static struct -{ - const char *name; - std::function callback; -} -g_guisTests[] = -{ - { - "custom widget call back bind Test", - [](Ref* sender) - { - CustomWidgetCallbackBindScene* pScene = new (std::nothrow) CustomWidgetCallbackBindScene(); - pScene->runThisTest(); - pScene->release(); - } - }, - /* - { - "custom gui image Test", - [](Ref* sender) - { - CustomImageScene* pScene = new (std::nothrow) CustomImageScene(); - pScene->runThisTest(); - pScene->release(); - } - }, - { - "custom gui particle widget Test", - [](Ref* sender) - { - CustomParticleWidgetScene* pScene = new (std::nothrow) CustomParticleWidgetScene(); - pScene->runThisTest(); - pScene->release(); - } - }, - */ -}; - -static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]); - -//////////////////////////////////////////////////////// -// -// CustomGUITestMainLayer -// -//////////////////////////////////////////////////////// - -static Vec2 _curPos = Vec2::ZERO; - - -void CustomGUITestMainLayer::onEnter() -{ - Layer::onEnter(); - - auto s = Director::getInstance()->getWinSize(); - - _itemMenu = Menu::create(); - _itemMenu->setPosition( _curPos ); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback); -// pItem->setPosition(s.width / 2, s.height / 2); - pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(CustomGUITestMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(CustomGUITestMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - - addChild(_itemMenu); -} - -void CustomGUITestMainLayer::onTouchesBegan(const std::vector &touches, cocos2d::Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - -/* -void CustomGUITestMainLayer::onTouchesMoved(const std::vector &touches, cocos2d::Event *event) -{ - auto touch = static_cast(touches[0]); - - auto touchLocation = touch->getLocation(); - - float nMoveY = touchLocation.y - _beginPos.y; - - Vec2 curPos = _itemMenu->getPosition(); - Vec2 nextPos = ccp(curPos.x, curPos.y + nMoveY); - - if (nextPos.y < 0.0f) - { - _itemMenu->setPosition(CCPointZero); - return; - } - - _itemMenu->setPosition(nextPos); - _beginPos = touchLocation; - _curPos = nextPos; -} - */ - -//////////////////////////////////////////////////////// -// -// CustomGUITestScene -// -//////////////////////////////////////////////////////// - -void CustomGUITestScene::onEnter() -{ - CCScene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CustomGUITestScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} - -void CustomGUITestScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CustomGUITestMainLayer(); - addChild(pLayer); - pLayer->release(); - - CCDirector::getInstance()->replaceScene(this); -} - -void CustomGUITestScene::BackCallback(Ref* pSender) -{ - CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene(); - pScene->runThisTest(); - pScene->release(); + addTestCase("Custom widget call back bind Test", [](){ return CustomWidgetCallbackBindScene::create(); }); + addTestCase("Custom GUI image Test", [](){ return CustomImageScene::create(); }); + addTestCase("Custom GUI particle widget Test", [](){ return CustomParticleWidgetScene::create(); }); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.h index 6bef6fe9a3..9cfd2070e2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomGUIScene.h @@ -1,37 +1,8 @@ - - #ifndef __TestCpp__CutomGUIScene__ #define __TestCpp__CutomGUIScene__ -#include "cocos2d.h" -#include "extensions/cocos-ext.h" -#include "../../testBasic.h" -#include "ui/CocosGUI.h" +#include "../../BaseTest.h" -USING_NS_CC; -USING_NS_CC_EXT; -using namespace cocos2d::ui; - -class CustomGUITestMainLayer : public Layer -{ -public: - virtual void onEnter() override; - void onTouchesBegan(const std::vector& touches, Event *event) override; -// void onTouchesMoved(const std::vector& touches, Event *event) override; - - void touchEvent(Ref* pSender, Widget::TouchEventType type); - -private: - Vec2 _beginPos; - Menu* _itemMenu; -}; - -class CustomGUITestScene : public TestScene -{ -public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(Ref* pSender); -}; +DEFINE_TEST_SUITE(CustomGUITests); #endif /* defined(__TestCpp__CutomGUIScene__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp index 4596b09fe5..9ce2776043 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp @@ -1,5 +1,3 @@ - - #include "CustomImageTest.h" #include "../../CustomGUIScene.h" #include "../../CustomWidget/CustomImageView.h" @@ -12,54 +10,38 @@ USING_NS_CC_EXT; // CustomImageLayer - - -void CustomImageLayer::onEnter() +bool CustomImageLayer::init() { - Layer::onEnter(); + if (Layer::init()) + { + GUIReader* guiReader = GUIReader::getInstance(); + guiReader->registerTypeAndCallBack("CustomImageView", + &CustomImageView::createInstance, + CustomImageViewReader::getInstance(), + parseselector(CustomImageViewReader::setProperties)); + + Layout* layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/CustomImageViewTest/NewProject_2_1.ExportJson")); + addChild(layout); + + return true; + } - GUIReader* guiReader = GUIReader::getInstance(); - guiReader->registerTypeAndCallBack("CustomImageView", - &CustomImageView::createInstance, - CustomImageViewReader::getInstance(), - parseselector(CustomImageViewReader::setProperties)); - - Layout* layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/CustomImageViewTest/NewProject_2_1.ExportJson")); - addChild(layout); + return false; } // CustomImageScene -void CustomImageScene::onEnter() +bool CustomImageScene::init() { - CCScene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CustomImageScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); + if (TestCase::init()) + { + addChild(CustomImageLayer::create()); + + return true; + } + + return false; } -void CustomImageScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CustomImageLayer(); - addChild(pLayer); - pLayer->release(); - - CCDirector::getInstance()->replaceScene(this); -} - -void CustomImageScene::BackCallback(Ref* pSender) -{ - CustomGUITestScene* pScene = new (std::nothrow) CustomGUITestScene(); - pScene->runThisTest(); - pScene->release(); -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.h index 09ea196575..19e443a2bb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.h @@ -1,24 +1,25 @@ - - #ifndef __TestCpp__CustomImageScene__ #define __TestCpp__CustomImageScene__ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "../../../../testBasic.h" +#include "BaseTest.h" class CustomImageLayer : public cocos2d::Layer { public: - virtual void onEnter() override; + CREATE_FUNC(CustomImageLayer); + + virtual bool init() override; }; -class CustomImageScene : public TestScene +class CustomImageScene : public TestCase { public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(cocos2d::Ref* pSender); + CREATE_FUNC(CustomImageScene); + + virtual bool init() override; + virtual std::string title() const override { return getTestCaseName(); } }; #endif /* defined(__TestCpp__CustomUIScene__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.cpp index 01147458b7..b5733c09eb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.cpp @@ -1,11 +1,3 @@ -// -// CustomParticleWidgetTest.cpp -// CustomUI -// -// Created by cai wenzhi on 14-3-7. -// -// - #include "CustomParticleWidgetTest.h" #include "../../CustomGUIScene.h" #include "../../CustomWidget/CustomParticleWidget.h" @@ -20,60 +12,35 @@ using namespace cocostudio; // CustomParticleWidgetLayer - - -void CustomParticleWidgetLayer::onEnter() +bool CustomParticleWidgetLayer::init() { - CCLayer::onEnter(); - - GUIReader* guiReader = GUIReader::getInstance(); - guiReader->registerTypeAndCallBack("CustomParticleWidget", - &CustomParticleWidget::createInstance, - CustomParticleWidgetReader::getInstance(), - parseselector(CustomParticleWidgetReader::setProperties)); - - CustomParticleWidget* custom = CustomParticleWidget::create(); - custom->setParticlePlist("Particles/BoilingFoam.plist"); - custom->setPosition(Vec2(VisibleRect::center())); - addChild(custom, 10, -1); + if (Layer::init()) + { + GUIReader* guiReader = GUIReader::getInstance(); + guiReader->registerTypeAndCallBack("CustomParticleWidget", + &CustomParticleWidget::createInstance, + CustomParticleWidgetReader::getInstance(), + parseselector(CustomParticleWidgetReader::setProperties)); + + CustomParticleWidget* custom = CustomParticleWidget::create(); + custom->setParticlePlist("Particles/BoilingFoam.plist"); + custom->setPosition(Vec2(VisibleRect::center())); + addChild(custom, 10, -1); + + return true; + } + + return false; } - -// CustomImageScene - - -void CustomParticleWidgetScene::onEnter() +bool CustomParticleWidgetScene::init() { - CCScene::onEnter(); - - Layer* pLayer = new (std::nothrow) CustomParticleWidgetLayer(); - addChild(pLayer); - pLayer->release(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CustomParticleWidgetScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} + if (TestCase::init()) + { + addChild(CustomParticleWidgetLayer::create()); -void CustomParticleWidgetScene::runThisTest() -{ - Layer* pLayer = new (std::nothrow) CustomParticleWidgetLayer(); - addChild(pLayer); - pLayer->release(); + return true; + } - CCDirector::getInstance()->replaceScene(this); -} - -void CustomParticleWidgetScene::BackCallback(Ref* pSender) -{ - CustomGUITestScene* pScene = new (std::nothrow) CustomGUITestScene(); - pScene->runThisTest(); - pScene->release(); + return false; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.h index 68c994e55f..6ffa74b270 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.h @@ -1,30 +1,25 @@ -// -// CustomParticleWidgetTest.h -// CustomUI -// -// Created by cai wenzhi on 14-3-7. -// -// - #ifndef __CustomUI__CustomParticleWidgetTest__ #define __CustomUI__CustomParticleWidgetTest__ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "../../../../testBasic.h" +#include "BaseTest.h" class CustomParticleWidgetLayer : public cocos2d::Layer { public: - virtual void onEnter() override; + CREATE_FUNC(CustomParticleWidgetLayer); + + virtual bool init() override; }; -class CustomParticleWidgetScene : public cocos2d::Scene +class CustomParticleWidgetScene : public TestCase { public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(cocos2d::Ref* pSender); + CREATE_FUNC(CustomParticleWidgetScene); + + virtual bool init() override; + virtual std::string title() const override { return getTestCaseName(); } }; #endif /* defined(__CustomUI__CustomParticleWidgetTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.cpp index 7e963fc9c8..92dc7cd447 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.cpp @@ -1,13 +1,9 @@ - - #include "CustomWidgetCallbackBindTest.h" #include "../../CustomGUIScene.h" #include "cocostudio/ActionTimeline/CSLoader.h" #include "cocostudio/CocoStudio.h" - #include "base/ObjectFactory.h" - #include "CustomRootNode.h" #include "CustomRootNodeReader.h" @@ -16,45 +12,26 @@ using namespace flatbuffers; // CustomWidgetCallbackBindScene -void CustomWidgetCallbackBindScene::onEnter() +bool CustomWidgetCallbackBindScene::init() { - Scene::onEnter(); + if (TestCase::init()) + { + CSLoader* instance = CSLoader::getInstance(); + instance->registReaderObject("CustomRootNodeReader", + (ObjectFactory::Instance)CustomRootNodeReader::getInstance); + + auto layer = CSLoader::createNode("cocosui/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.csb"); + addChild(layer); + + return true; + } - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - //#endif - MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CustomWidgetCallbackBindScene::BackCallback, this)); - - Menu* pMenu = Menu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); + return false; } void CustomWidgetCallbackBindScene::onExit() { cocostudio::destroyCocosStudio(); - - Scene::onExit(); -} -void CustomWidgetCallbackBindScene::runThisTest() -{ - CSLoader* instance = CSLoader::getInstance(); - instance->registReaderObject("CustomRootNodeReader", - (ObjectFactory::Instance)CustomRootNodeReader::getInstance); - - auto pLayer = CSLoader::createNode("cocosui/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.csb"); - addChild(pLayer); - - - Director::getInstance()->replaceScene(this); + TestCase::onExit(); } - -void CustomWidgetCallbackBindScene::BackCallback(Ref* pSender) -{ - CustomGUITestScene* pScene = new (std::nothrow) CustomGUITestScene(); - pScene->runThisTest(); - pScene->release(); -} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.h index 74f551e1ab..7b4fbb13d4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CustomTest/CustomWidgetCallbackBindTest/CustomWidgetCallbackBindTest.h @@ -1,18 +1,17 @@ - - #ifndef __cocos2d_tests__CustomWidgetCallbackBindTest__ #define __cocos2d_tests__CustomWidgetCallbackBindTest__ -#include "cocos2d.h" -#include "../../../../testBasic.h" +#include "../../../../BaseTest.h" -class CustomWidgetCallbackBindScene : public TestScene +class CustomWidgetCallbackBindScene : public TestCase { public: - virtual void onEnter() override; + CREATE_FUNC(CustomWidgetCallbackBindScene); + + virtual bool init() override; + virtual std::string title() const override { return getTestCaseName(); } + virtual void onExit() override; - virtual void runThisTest(); - void BackCallback(cocos2d::Ref* pSender); }; #endif /* defined(__cocos2d_tests__CustomWidgetCallbackBindTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp index 152bfc4cbf..2f1b38b23d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp @@ -1,367 +1,36 @@ - - #include "GUIEditorTest.h" #include "cocostudio/ActionTimeline/CSLoader.h" #include "CocoStudioGUITest.h" -#include "UISceneManager_Editor.h" +#include "UIButtonTest/UIButtonTest_Editor.h" +#include "UICheckBoxTest/UICheckBoxTest_Editor.h" +#include "UIImageViewTest/UIImageViewTest_Editor.h" +#include "UITextAtlasTest/UITextAtlasTest_Editor.h" +#include "UITextBMFontTest/UITextBMFontTest_Editor.h" +#include "UITextTest/UITextTest_Editor.h" +#include "UILoadingBarTest/UILoadingBarTest_Editor.h" +#include "UISliderTest/UISliderTest_Editor.h" +#include "UITextFieldTest/UITextFieldTest_Editor.h" +#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h" +#include "UILayoutTest/UILayoutTest_Editor.h" +#include "UIListViewTest/UIListViewTest_Editor.h" +#include "UIPageViewTest/UIPageViewTest_Editor.h" +#include "UIScrollViewTest/UIScrollViewTest_Editor.h" -enum +GUIEditorTests::GUIEditorTests() { - LINE_SPACE = 40, - kItemTagBasic = 1000, + addTest("GUI Button Editor Test", [](){ return new (std::nothrow) UIButtonEditorTests; }); + addTest("GUI CheckBox Editor Test", [](){ return new (std::nothrow) UICheckBoxEditorTests; }); + addTest("GUI Slider Editor Test", [](){ return new (std::nothrow) UISliderEditorTests; }); + addTest("GUI ImageView Editor Test", [](){ return new (std::nothrow) UIImageViewEditorTests; }); + addTest("GUI LoadingBar Editor Test", [](){ return new (std::nothrow) UILoadingBarEditorTests; }); + addTest("GUI Text Editor Test", [](){ return new (std::nothrow) UITextEditorTests; }); + addTest("GUI TextBMFont Editor Test", [](){ return new (std::nothrow) UITextBMFontEditorTest; }); + addTest("GUI TextField Editor Test", [](){ return new (std::nothrow) UITextFieldEditorTests; }); + addTest("GUI Layout Editor Test", [](){ return new (std::nothrow) UILayoutEditorTests; }); + addTest("GUI ScrollView Editor Test", [](){ return new (std::nothrow) UIScrollViewEditorTests; }); + addTest("GUI PageView Editor Test", [](){ return new (std::nothrow) UIPageViewEditorTests; }); + addTest("GUI ListView Editor Test", [](){ return new (std::nothrow) UIListViewEditorTests; }); + addTest("GUI WidgetAddNode Editor Test", [](){ return new (std::nothrow) UIWidgetAddNodeEditorTests; }); }; - -static struct -{ - const char *name; - std::function callback; -} -g_guisTests[] = -{ - { - "gui Button Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIButtonTest_Editor); - pManager->setMinUISceneId(kUIButtonTest_Editor); - pManager->setMaxUISceneId(kUIButtonTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui CheckBox Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUICheckBoxTest_Editor); - pManager->setMinUISceneId(kUICheckBoxTest_Editor); - pManager->setMaxUISceneId(kUICheckBoxTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui Slider Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUISliderTest_Editor); - pManager->setMinUISceneId(kUISliderTest_Editor); - pManager->setMaxUISceneId(kUISliderTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - /* - { - "gui PotentiometerTest", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIPotentiometerTest); - pManager->setMinUISceneId(kUIPotentiometerTest); - pManager->setMaxUISceneId(kUIPotentiometerTest); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui SwitchTest", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUISwitchTest_Horizontal); - pManager->setMinUISceneId(kUISwitchTest_Horizontal); - pManager->setMaxUISceneId(kUISwitchTest_VerticalAndTitleVertical); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - */ - { - "gui ImageView Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIImageViewTest_Editor); - pManager->setMinUISceneId(kUIImageViewTest_Editor); - pManager->setMaxUISceneId(kUIImageViewTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui LoadingBar Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUILoadingBarTest_Editor); - pManager->setMinUISceneId(kUILoadingBarTest_Editor); - pManager->setMaxUISceneId(kUILoadingBarTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - /* - { - "gui ProgressTimerTest", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIProgressTimerTest_Radial); - pManager->setMinUISceneId(kUIProgressTimerTest_Radial); - pManager->setMaxUISceneId(kUIProgressTimerTest_WithSpriteFrame); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - */ - /* - { - "gui TextAtlas Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUITextAtlasTest_Editor); - pManager->setMinUISceneId(kUITextAtlasTest_Editor); - pManager->setMaxUISceneId(kUITextAtlasTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - */ - { - "gui Text Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUITextTest_Editor); - pManager->setMinUISceneId(kUITextTest_Editor); - pManager->setMaxUISceneId(kUITextTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui TextBMFont Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUITextBMFontTest_Editor); - pManager->setMinUISceneId(kUITextBMFontTest_Editor); - pManager->setMaxUISceneId(kUITextBMFontTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui TextField Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUITextFieldTest_Editor); - pManager->setMinUISceneId(kUITextFieldTest_Editor); - pManager->setMaxUISceneId(kUITextFieldTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui Layout Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUILayoutTest_Editor); - pManager->setMinUISceneId(kUILayoutTest_Editor); - pManager->setMaxUISceneId(kUILayoutComponentTest_Editor); -// pManager->setMaxUISceneId(kUILayoutTest_Layout_Relative_Location_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui ScrollView Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIScrollViewTest_Vertical_Editor); - pManager->setMinUISceneId(kUIScrollViewTest_Vertical_Editor); - pManager->setMaxUISceneId(kUIScrollViewTest_Both_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui PageView Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIPageViewTest_Editor); - pManager->setMinUISceneId(kUIPageViewTest_Editor); - pManager->setMaxUISceneId(kUIPageViewTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui ListView Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIListViewTest_Vertical_Editor); - pManager->setMinUISceneId(kUIListViewTest_Vertical_Editor); - pManager->setMaxUISceneId(kUIListViewTest_Horizontal_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - /* - { - "gui GridViewTest", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIGridViewTest_Mode_Column); - pManager->setMinUISceneId(kUIGridViewTest_Mode_Column); - pManager->setMaxUISceneId(kUIGridViewTest_Mode_Row); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - { - "gui PickerViewTest", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIPickerViewTest_Vertical); - pManager->setMinUISceneId(kUIPickerViewTest_Vertical); - pManager->setMaxUISceneId(kUIPickerViewTest_Horizontal); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, - */ - { - "gui WidgetAddNode Editor Test", - [](Ref* sender) - { - UISceneManager_Editor* pManager = UISceneManager_Editor::sharedUISceneManager_Editor(); - pManager->setCurrentUISceneId(kUIWidgetAddNodeTest_Editor); - pManager->setMinUISceneId(kUIWidgetAddNodeTest_Editor); - pManager->setMaxUISceneId(kUIWidgetAddNodeTest_Editor); - Scene* pScene = pManager->currentUIScene(); - Director::getInstance()->replaceScene(pScene); - } - }, -}; - -static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]); - -static Vec2 s_tCurPos = Vec2::ZERO; - -//////////////////////////////////////////////////////// -// -// GUIEditorMainLayer -// -//////////////////////////////////////////////////////// -void GUIEditorMainLayer::onEnter() -{ - Layer::onEnter(); - - auto s = Director::getInstance()->getWinSize(); - - _itemMenu = Menu::create(); - _itemMenu->setPosition( s_tCurPos ); - MenuItemFont::setFontName("fonts/arial.ttf"); - MenuItemFont::setFontSize(24); - for (int i = 0; i < g_maxTests; ++i) - { - auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback); - pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE); - _itemMenu->addChild(pItem, kItemTagBasic + i); - } - - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = CC_CALLBACK_2(GUIEditorMainLayer::onTouchesBegan, this); - listener->onTouchesMoved = CC_CALLBACK_2(GUIEditorMainLayer::onTouchesMoved, this); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); - - addChild(_itemMenu); -} - -void GUIEditorMainLayer::onTouchesBegan(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - _beginPos = touch->getLocation(); -} - -void GUIEditorMainLayer::onTouchesMoved(const std::vector& touches, Event *event) -{ - auto touch = static_cast(touches[0]); - - auto touchLocation = touch->getLocation(); - float nMoveY = touchLocation.y - _beginPos.y; - - auto curPos = _itemMenu->getPosition(); - auto nextPos = Vec2(curPos.x, curPos.y + nMoveY); - - if (nextPos.y < 0.0f) - { - _itemMenu->setPosition(Vec2::ZERO); - return; - } - - if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) - { - _itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)); - return; - } - - _itemMenu->setPosition(nextPos); - _beginPos = touchLocation; - s_tCurPos = nextPos; -} - -//////////////////////////////////////////////////////// -// -// GUIEditorTestScene -// -//////////////////////////////////////////////////////// - -void GUIEditorTestScene::onEnter() -{ - Scene::onEnter(); - - auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20); - - auto pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(GUIEditorTestScene::BackCallback, this)); - - Menu* pMenu =CCMenu::create(pMenuItem, nullptr); - - pMenu->setPosition( Vec2::ZERO ); - pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25); - - addChild(pMenu, 1); -} - -void GUIEditorTestScene::runThisTest() -{ - auto layer = new (std::nothrow) GUIEditorMainLayer(); - addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(this); -} - -void GUIEditorTestScene::BackCallback(Ref* pSender) -{ - CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene(); - pScene->runThisTest(); - pScene->release(); -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.h index 6641071755..0867d4fe3c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/GUIEditorTest.h @@ -1,30 +1,8 @@ - - #ifndef __TestCpp__GUIEditorTest__ #define __TestCpp__GUIEditorTest__ -#include "../../testBasic.h" +#include "../../BaseTest.h" -class GUIEditorMainLayer : public Layer -{ -public: - virtual void onEnter() override; - void menuCallback(Ref* pSender); - void onTouchesBegan(const std::vector& touches, Event *event) override; - void onTouchesMoved(const std::vector& touches, Event *event) override; -private: - Vec2 _beginPos; - Menu* _itemMenu; - - int _testcount; -}; - -class GUIEditorTestScene : public TestScene -{ -public: - virtual void onEnter() override; - virtual void runThisTest(); - void BackCallback(Ref* pSender); -}; +DEFINE_TEST_LIST(GUIEditorTests); #endif /* defined(__TestCpp__GUIEditorTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 4d298bcd31..5beb96015e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -1,7 +1,22 @@ - - #include "UIButtonTest.h" +UIButtonTests::UIButtonTests() +{ + ADD_TEST_CASE(UIButtonTest); + ADD_TEST_CASE(UIButtonTest_Scale9); + ADD_TEST_CASE(UIButtonTest_Scale9_State_Change); + ADD_TEST_CASE(UIButtonTest_PressedAction); + ADD_TEST_CASE(UIButtonTest_Title); + ADD_TEST_CASE(UIButtonTestRemoveSelf); + ADD_TEST_CASE(UIButtonTestSwitchScale9); + ADD_TEST_CASE(UIButtonTestZoomScale); + ADD_TEST_CASE(UIButtonTextOnly); + ADD_TEST_CASE(UIButtonIgnoreContentSizeTest); + ADD_TEST_CASE(UIButtonTitleEffectTest); + ADD_TEST_CASE(UIButtonFlipTest); + ADD_TEST_CASE(UIButtonNormalDefaultTest); + ADD_TEST_CASE(UIButtonDisableDefaultTest); +} // UIButtonTest UIButtonTest::UIButtonTest() @@ -1006,4 +1021,3 @@ bool UIButtonDisableDefaultTest::init() } return false; } - diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h index 485c70d0db..e261c760c4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h @@ -27,179 +27,209 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIButtonTests); + class UIButtonTest : public UIScene { public: + CREATE_FUNC(UIButtonTest); + UIButtonTest(); ~UIButtonTest(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTest) Text* _displayValueLabel; }; class UIButtonTest_Scale9 : public UIScene { public: + CREATE_FUNC(UIButtonTest_Scale9); + UIButtonTest_Scale9(); ~UIButtonTest_Scale9(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTest_Scale9) Text* _displayValueLabel; }; class UIButtonTest_Scale9_State_Change : public UIScene { public: + CREATE_FUNC(UIButtonTest_Scale9_State_Change); + UIButtonTest_Scale9_State_Change(); ~UIButtonTest_Scale9_State_Change(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTest_Scale9_State_Change) Text* _displayValueLabel; }; class UIButtonTest_PressedAction : public UIScene { public: + CREATE_FUNC(UIButtonTest_PressedAction); + UIButtonTest_PressedAction(); ~UIButtonTest_PressedAction(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTest_PressedAction) Text* _displayValueLabel; }; class UIButtonTest_Title : public UIScene { public: + CREATE_FUNC(UIButtonTest_Title); + UIButtonTest_Title(); ~UIButtonTest_Title(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTest_Title) Text* _displayValueLabel; }; class UIButtonTestRemoveSelf : public UIScene { public: + CREATE_FUNC(UIButtonTestRemoveSelf); + UIButtonTestRemoveSelf(); ~UIButtonTestRemoveSelf(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTestRemoveSelf) Text* _displayValueLabel; }; class UIButtonTestSwitchScale9 : public UIScene { public: + CREATE_FUNC(UIButtonTestSwitchScale9); + UIButtonTestSwitchScale9(); ~UIButtonTestSwitchScale9(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTestSwitchScale9) Text* _displayValueLabel; }; class UIButtonTestZoomScale : public UIScene { public: + CREATE_FUNC(UIButtonTestZoomScale); + UIButtonTestZoomScale(); ~UIButtonTestZoomScale(); - bool init(); + + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); protected: - UI_SCENE_CREATE_FUNC(UIButtonTestZoomScale) Text* _displayValueLabel; }; class UIButtonTextOnly : public UIScene { public: + CREATE_FUNC(UIButtonTextOnly); + UIButtonTextOnly(); ~UIButtonTextOnly(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonTextOnly) Text* _displayValueLabel; }; class UIButtonIgnoreContentSizeTest : public UIScene { public: + CREATE_FUNC(UIButtonIgnoreContentSizeTest); + UIButtonIgnoreContentSizeTest(); ~UIButtonIgnoreContentSizeTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonIgnoreContentSizeTest) Text* _displayValueLabel; }; class UIButtonTitleEffectTest : public UIScene { public: + CREATE_FUNC(UIButtonTitleEffectTest); + UIButtonTitleEffectTest(); ~UIButtonTitleEffectTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest) Text* _displayValueLabel; }; class UIButtonFlipTest : public UIScene { public: + CREATE_FUNC(UIButtonFlipTest); + UIButtonFlipTest(); ~UIButtonFlipTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonFlipTest) Text* _displayValueLabel; }; class UIButtonNormalDefaultTest : public UIScene { public: + CREATE_FUNC(UIButtonNormalDefaultTest); + UIButtonNormalDefaultTest(); ~UIButtonNormalDefaultTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonNormalDefaultTest) Text* _displayValueLabel; }; class UIButtonDisableDefaultTest : public UIScene { public: + CREATE_FUNC(UIButtonDisableDefaultTest); + UIButtonDisableDefaultTest(); ~UIButtonDisableDefaultTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIButtonDisableDefaultTest) Text* _displayValueLabel; }; #endif /* defined(__TestCpp__UIButtonTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp index e89aff9cbc..4d757cc632 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp @@ -1,10 +1,12 @@ - - #include "UIButtonTest_Editor.h" - // UIButtonTest_Editor +UIButtonEditorTests::UIButtonEditorTests() +{ + ADD_TEST_CASE(UIButtonTest_Editor); +} + UIButtonTest_Editor::UIButtonTest_Editor() : _displayValueLabel(nullptr) { @@ -16,85 +18,12 @@ UIButtonTest_Editor::~UIButtonTest_Editor() } -void UIButtonTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton/windows_UIButton_Editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton/windows_UIButton_Editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.ExportJson"); - Node* child = node->getChildByTag(4); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIButton_Editor/crossplatform_UIButton_Editor_1.csb"); - Node* child = node->getChildByTag(4); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UIButtonTest_Editor::configureGUIScene() { - Size screenSize = Director::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); + UIScene_Editor::configureGUIScene(); Layout* root = static_cast(_layout->getChildByName("root_Panel")); - ui::Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - Button* button = static_cast(Helper::seekWidgetByName(root, "Button_123")); button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); @@ -103,7 +32,6 @@ void UIButtonTest_Editor::configureGUIScene() Button* scale9_button = static_cast(Helper::seekWidgetByName(root, "Button_129")); scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent,this)); - } bool UIButtonTest_Editor::init() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h index 33f8e5c72e..ffed2a42be 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h @@ -26,20 +26,24 @@ #define __TestCpp__UIButtonTest_Editor__ #include "../UIScene_Editor.h" +#include "BaseTest.h" + +DEFINE_TEST_SUITE(UIButtonEditorTests); class UIButtonTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIButtonTest_Editor); + UIButtonTest_Editor(); ~UIButtonTest_Editor(); - bool init(); + virtual bool init() override; + void touchEvent(Ref* pSender, Widget::TouchEventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + virtual void configureGUIScene() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIButtonTest_Editor); Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 00a7b2aa48..554021a103 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -1,7 +1,10 @@ - - #include "UICheckBoxTest.h" +UICheckBoxTests::UICheckBoxTests() +{ + ADD_TEST_CASE(UICheckBoxTest); + ADD_TEST_CASE(UICheckBoxDefaultBehaviorTest); +} // UICheckBoxTest UICheckBoxTest::UICheckBoxTest() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h index b64374cbf9..dbcd9d6e36 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h @@ -27,28 +27,34 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UICheckBoxTests); + class UICheckBoxTest : public UIScene { public: + CREATE_FUNC(UICheckBoxTest); + UICheckBoxTest(); ~UICheckBoxTest(); - bool init(); + + virtual bool init() override; void selectedEvent(Ref* pSender,CheckBox::EventType type); protected: - UI_SCENE_CREATE_FUNC(UICheckBoxTest) Text* _displayValueLabel; }; class UICheckBoxDefaultBehaviorTest : public UIScene { public: + CREATE_FUNC(UICheckBoxDefaultBehaviorTest); + UICheckBoxDefaultBehaviorTest(); ~UICheckBoxDefaultBehaviorTest(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UICheckBoxDefaultBehaviorTest) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp index c52119ce97..c4dc97a1d0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp @@ -1,7 +1,9 @@ - - #include "UICheckBoxTest_Editor.h" +UICheckBoxEditorTests::UICheckBoxEditorTests() +{ + ADD_TEST_CASE(UICheckBoxTest_Editor); +} // UICheckBoxTest_Editor @@ -16,85 +18,12 @@ UICheckBoxTest_Editor::~UICheckBoxTest_Editor() } -void UICheckBoxTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox/windows_ui_checkbox_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UICheckBox/windows_ui_checkbox_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UICheckBox/crossplatform_UICheckBox_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UICheckBox/crossplatform_UICheckBox_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UICheckBoxTest_Editor::configureGUIScene() { - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); + UIScene_Editor::configureGUIScene(); Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - + CheckBox* checkbox = static_cast(Helper::seekWidgetByName(root, "CheckBox_540")); checkbox->addEventListener(CC_CALLBACK_2(UICheckBoxTest_Editor::selectedStateEvent, this)); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h index d2d03b7ce6..250be160c9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h @@ -27,17 +27,21 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UICheckBoxEditorTests); + class UICheckBoxTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UICheckBoxTest_Editor); + UICheckBoxTest_Editor(); ~UICheckBoxTest_Editor(); - bool init(); + + virtual bool init() override; + void selectedStateEvent(Ref* pSender, CheckBox::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + virtual void configureGUIScene() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UICheckBoxTest_Editor) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp index 68697ec8f9..95a484c166 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -25,15 +25,12 @@ #include "UIEditBoxTest.h" #include "testResource.h" -// UIEditBoxTest -UIEditBoxTest::UIEditBoxTest() +UIEditBoxTests::UIEditBoxTests() { - + ADD_TEST_CASE(UIEditBoxTest); } -UIEditBoxTest::~UIEditBoxTest() -{ -} +// UIEditBoxTest bool UIEditBoxTest::init() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h index 3d93dd7717..11b60eabbb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h @@ -27,12 +27,14 @@ #include "UIScene.h" +DEFINE_TEST_SUITE(UIEditBoxTests); + class UIEditBoxTest : public UIScene, public cocos2d::ui::EditBoxDelegate { public: - UIEditBoxTest(); - ~UIEditBoxTest(); - bool init(); + CREATE_FUNC(UIEditBoxTest); + + virtual bool init() override; virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox); virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox); @@ -45,8 +47,6 @@ protected: cocos2d::ui::EditBox* _editName; cocos2d::ui::EditBox* _editPassword; cocos2d::ui::EditBox* _editEmail; - - UI_SCENE_CREATE_FUNC(UIEditBoxTest) }; #endif /* defined(__cocos2d_tests__UIEditBoxTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp index f410e521c0..4db1ab44dc 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp @@ -8,6 +8,16 @@ #include "UIFocusTest.h" +UIFocusTests::UIFocusTests() +{ + ADD_TEST_CASE(UIFocusTestHorizontal); + ADD_TEST_CASE(UIFocusTestVertical); + ADD_TEST_CASE(UIFocusTestNestedLayout1); + ADD_TEST_CASE(UIFocusTestNestedLayout2); + ADD_TEST_CASE(UIFocusTestNestedLayout3); + ADD_TEST_CASE(UIFocusTestListView); +} + UIFocusTestBase::UIFocusTestBase() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h index e222df1683..8c0fff6247 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h @@ -11,14 +11,15 @@ #include "../UIScene.h" - +DEFINE_TEST_SUITE(UIFocusTests); class UIFocusTestBase : public UIScene { public: UIFocusTestBase(); virtual ~UIFocusTestBase(); - bool init(); + + virtual bool init() override; virtual void onLeftKeyPressed(); virtual void onRightKeyPressed(); @@ -37,15 +38,16 @@ protected: class UIFocusTestHorizontal : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestHorizontal); + UIFocusTestHorizontal(); virtual ~UIFocusTestHorizontal(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestHorizontal); Layout *_horizontalLayout; Text *_loopText; }; @@ -53,14 +55,15 @@ protected: class UIFocusTestVertical : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestVertical); + UIFocusTestVertical(); virtual ~UIFocusTestVertical(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestVertical); Layout *_verticalLayout; Text *_loopText; }; @@ -68,14 +71,15 @@ protected: class UIFocusTestNestedLayout1 : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestNestedLayout1); + UIFocusTestNestedLayout1(); virtual ~UIFocusTestNestedLayout1(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestNestedLayout1); Layout *_verticalLayout; Text *_loopText; }; @@ -83,14 +87,15 @@ protected: class UIFocusTestNestedLayout2 : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestNestedLayout2); + UIFocusTestNestedLayout2(); virtual ~UIFocusTestNestedLayout2(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestNestedLayout2); Layout *_horizontalLayout; Text *_loopText; }; @@ -98,14 +103,15 @@ protected: class UIFocusTestNestedLayout3 : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestNestedLayout3); + UIFocusTestNestedLayout3(); virtual ~UIFocusTestNestedLayout3(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestNestedLayout3); Layout *_verticalLayout; Text *_loopText; }; @@ -113,14 +119,15 @@ protected: class UIFocusTestListView : public UIFocusTestBase { public: + CREATE_FUNC(UIFocusTestListView); + UIFocusTestListView(); virtual ~UIFocusTestListView(); - bool init(); - + + virtual bool init() override; void toggleFocusLoop(Ref*,Widget::TouchEventType); protected: - UI_SCENE_CREATE_FUNC(UIFocusTestListView); ListView *_listView; Text *_loopText; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index e6c458d474..3cf5769324 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -1,7 +1,13 @@ - - #include "UIImageViewTest.h" +UIImageViewTests::UIImageViewTests() +{ + ADD_TEST_CASE(UIImageViewTest); + ADD_TEST_CASE(UIImageViewTest_Scale9); + ADD_TEST_CASE(UIImageViewTest_Scale9_State_Change); + ADD_TEST_CASE(UIImageViewTest_ContentSize); + ADD_TEST_CASE(UIImageViewFlipTest); +} // UIImageViewTest diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h index cf78b366ee..e98c498d24 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h @@ -27,49 +27,46 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIImageViewTests); + class UIImageViewTest : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIImageViewTest) + CREATE_FUNC(UIImageViewTest); + + virtual bool init() override; }; class UIImageViewTest_Scale9 : public UIScene { -public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIImageViewTest_Scale9) +public: + CREATE_FUNC(UIImageViewTest_Scale9); + + virtual bool init() override; }; class UIImageViewTest_Scale9_State_Change : public UIScene { public: - bool init(); + CREATE_FUNC(UIImageViewTest_Scale9_State_Change); -protected: - UI_SCENE_CREATE_FUNC(UIImageViewTest_Scale9_State_Change) + virtual bool init() override; }; class UIImageViewTest_ContentSize : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIImageViewTest_ContentSize) + CREATE_FUNC(UIImageViewTest_ContentSize); + + virtual bool init() override; }; class UIImageViewFlipTest : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIImageViewFlipTest) + CREATE_FUNC(UIImageViewFlipTest); + + virtual bool init() override; }; #endif /* defined(__TestCpp__UIImageViewTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp index 3b269af2fc..5a7088ff95 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp @@ -1,90 +1,11 @@ - - #include "UIImageViewTest_Editor.h" +UIImageViewEditorTests::UIImageViewEditorTests() +{ + ADD_TEST_CASE(UIImageViewTest_Editor); +} // UIImageViewTest_Editor -void UIImageViewTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView/windows_ui_ImageView_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIImageView/windows_ui_ImageView_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIImageView/crossplatform_UIImageView_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIImageView/crossplatform_UIImageView_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIImageViewTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - -} - bool UIImageViewTest_Editor::init() { if (UIScene_Editor::init()) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h index 37a1604d73..0795672455 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h @@ -27,15 +27,16 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UIImageViewEditorTests); + class UIImageViewTest_Editor : public UIScene_Editor { public: - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + CREATE_FUNC(UIImageViewTest_Editor); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIImageViewTest_Editor) }; #endif /* defined(__TestCpp__UIImageViewTest_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index 67ab74a09c..b55eaf1210 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -1,7 +1,20 @@ - - #include "UILayoutTest.h" +UILayoutTests::UILayoutTests() +{ + ADD_TEST_CASE(UILayoutTest); + ADD_TEST_CASE(UILayoutTest_Color); + ADD_TEST_CASE(UILayoutTest_Gradient); + ADD_TEST_CASE(UILayoutTest_BackGroundImage); + ADD_TEST_CASE(UILayoutTest_BackGroundImage_Scale9); + ADD_TEST_CASE(UILayoutTest_Layout_Linear_Vertical); + ADD_TEST_CASE(UILayoutTest_Layout_Linear_Horizontal); + ADD_TEST_CASE(UILayoutTest_Layout_Relative_Align_Parent); + ADD_TEST_CASE(UILayoutTest_Layout_Relative_Location); + ADD_TEST_CASE(UILayoutComponentTest); + ADD_TEST_CASE(UILayoutComponent_Berth_Test); + ADD_TEST_CASE(UILayoutComponent_Berth_Stretch_Test); +} // UILayoutTest @@ -738,7 +751,7 @@ void UILayoutComponentTest::touchEvent(Ref *pSender, Widget::TouchEventType type _baseLayer->setContentSize(Size(200, 200)); else _baseLayer->setContentSize(widgetSize); - ui:Helper::doLayout(_baseLayer); + Helper::doLayout(_baseLayer); } break; @@ -843,4 +856,3 @@ bool UILayoutComponent_Berth_Stretch_Test::init() } return false; } - diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h index 0292f85e7b..ed0f9195ab 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h @@ -27,15 +27,16 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UILayoutTests); + class UILayoutTest : public UIScene { public: UILayoutTest(); ~UILayoutTest(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest) + CREATE_FUNC(UILayoutTest); }; class UILayoutTest_Color : public UIScene @@ -43,10 +44,9 @@ class UILayoutTest_Color : public UIScene public: UILayoutTest_Color(); ~UILayoutTest_Color(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Color) + CREATE_FUNC(UILayoutTest_Color); }; class UILayoutTest_Gradient : public UIScene @@ -54,10 +54,9 @@ class UILayoutTest_Gradient : public UIScene public: UILayoutTest_Gradient(); ~UILayoutTest_Gradient(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Gradient) + CREATE_FUNC(UILayoutTest_Gradient); }; class UILayoutTest_BackGroundImage : public UIScene @@ -65,10 +64,9 @@ class UILayoutTest_BackGroundImage : public UIScene public: UILayoutTest_BackGroundImage(); ~UILayoutTest_BackGroundImage(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_BackGroundImage) + CREATE_FUNC(UILayoutTest_BackGroundImage); }; class UILayoutTest_BackGroundImage_Scale9 : public UIScene @@ -76,10 +74,9 @@ class UILayoutTest_BackGroundImage_Scale9 : public UIScene public: UILayoutTest_BackGroundImage_Scale9(); ~UILayoutTest_BackGroundImage_Scale9(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_BackGroundImage_Scale9) + CREATE_FUNC(UILayoutTest_BackGroundImage_Scale9); }; class UILayoutTest_Layout_Linear_Vertical : public UIScene @@ -87,10 +84,9 @@ class UILayoutTest_Layout_Linear_Vertical : public UIScene public: UILayoutTest_Layout_Linear_Vertical(); ~UILayoutTest_Layout_Linear_Vertical(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Linear_Vertical) + CREATE_FUNC(UILayoutTest_Layout_Linear_Vertical); }; class UILayoutTest_Layout_Linear_Horizontal : public UIScene @@ -98,10 +94,9 @@ class UILayoutTest_Layout_Linear_Horizontal : public UIScene public: UILayoutTest_Layout_Linear_Horizontal(); ~UILayoutTest_Layout_Linear_Horizontal(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Linear_Horizontal) + CREATE_FUNC(UILayoutTest_Layout_Linear_Horizontal); }; class UILayoutTest_Layout_Relative_Align_Parent : public UIScene @@ -109,10 +104,9 @@ class UILayoutTest_Layout_Relative_Align_Parent : public UIScene public: UILayoutTest_Layout_Relative_Align_Parent(); ~UILayoutTest_Layout_Relative_Align_Parent(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Relative_Align_Parent) + CREATE_FUNC(UILayoutTest_Layout_Relative_Align_Parent); }; class UILayoutTest_Layout_Relative_Location : public UIScene @@ -120,49 +114,37 @@ class UILayoutTest_Layout_Relative_Location : public UIScene public: UILayoutTest_Layout_Relative_Location(); ~UILayoutTest_Layout_Relative_Location(); - bool init(); + virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Relative_Location) + CREATE_FUNC(UILayoutTest_Layout_Relative_Location); }; class UILayoutComponentTest : public UIScene { public: + CREATE_FUNC(UILayoutComponentTest); + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); protected: LayerColor* _baseLayer; - UI_SCENE_CREATE_FUNC(UILayoutComponentTest) + }; class UILayoutComponent_Berth_Test : public UILayoutComponentTest { public: virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutComponent_Berth_Test) + + CREATE_FUNC(UILayoutComponent_Berth_Test); }; class UILayoutComponent_Berth_Stretch_Test : public UILayoutComponentTest { public: virtual bool init() override; -protected: - UI_SCENE_CREATE_FUNC(UILayoutComponent_Berth_Stretch_Test) -}; -/* -class UILayoutTest_Layout_Grid : public UIScene -{ -public: - UILayoutTest_Layout_Grid(); - ~UILayoutTest_Layout_Grid(); - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UILayoutTest_Layout_Grid) + CREATE_FUNC(UILayoutComponent_Berth_Stretch_Test); }; - */ #endif /* defined(__TestCpp__UILayoutTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index 69c1c5d738..75364e23fb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -1,9 +1,20 @@ - - #include "UILayoutTest_Editor.h" #include "VisibleRect.h" +UILayoutEditorTests::UILayoutEditorTests() +{ + ADD_TEST_CASE(UILayoutTest_Editor); + ADD_TEST_CASE(UILayoutTest_Color_Editor); + ADD_TEST_CASE(UILayoutTest_Gradient_Editor); + ADD_TEST_CASE(UILayoutTest_BackGroundImage_Editor); + ADD_TEST_CASE(UILayoutTest_BackGroundImage_Scale9_Editor); + ADD_TEST_CASE(UILayoutTest_Layout_Linear_Vertical_Editor); + ADD_TEST_CASE(UILayoutTest_Layout_Linear_Horizontal_Editor); + ADD_TEST_CASE(UILayoutTest_Layout_Relative_Align_Parent_Editor); + ADD_TEST_CASE(UILayoutTest_Layout_Relative_Location_Editor); + ADD_TEST_CASE(UILayoutComponentTest_Editor); +} // UILayoutTest_Editor UILayoutTest_Editor::UILayoutTest_Editor() @@ -14,106 +25,6 @@ UILayoutTest_Editor::UILayoutTest_Editor() UILayoutTest_Editor::~UILayoutTest_Editor() { -} - -void UILayoutTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Layout/windows_ui_layout_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Layout/windows_ui_layout_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Layout/crossplatform_UILayout_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Layout/crossplatform_UILayout_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - - } bool UILayoutTest_Editor::init() @@ -128,13 +39,6 @@ bool UILayoutTest_Editor::init() this->configureGUIScene(); - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - return true; } @@ -154,104 +58,6 @@ UILayoutTest_Color_Editor::~UILayoutTest_Color_Editor() } -void UILayoutTest_Color_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Color/windows_ui_color.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Color/windows_ui_color.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Color/crossplatform_Colo.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Color/crossplatform_UILayout_Color_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Color_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); -} - bool UILayoutTest_Color_Editor::init() { if (UIScene_Editor::init()) @@ -264,13 +70,6 @@ bool UILayoutTest_Color_Editor::init() this->configureGUIScene(); - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - return true; } @@ -290,105 +89,6 @@ UILayoutTest_Gradient_Editor::~UILayoutTest_Gradient_Editor() } -void UILayoutTest_Gradient_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Gradient_Color/windows_ui_gradient_color.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Gradient_Color/windows_ui_gradient_color.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Gradient_Color/crossplatform_Gradient_Color.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Gradient_Color/crossplatform_Gradient_Color.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Gradient_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_Gradient_Editor::init() { if (UIScene_Editor::init()) @@ -401,13 +101,6 @@ bool UILayoutTest_Gradient_Editor::init() this->configureGUIScene(); - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - return true; } @@ -427,105 +120,6 @@ UILayoutTest_BackGroundImage_Editor::~UILayoutTest_BackGroundImage_Editor() } -void UILayoutTest_BackGroundImage_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/BackgroundImage/windows_ui_backgroundimage.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/BackgroundImage/windows_ui_backgroundimage.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/BackgroundImage/crossplatform_BackgroundImage.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/BackgroundImage/crossplatform_BackgroundImage.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_BackGroundImage_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_BackGroundImage_Editor::init() { if (UIScene_Editor::init()) @@ -538,13 +132,6 @@ bool UILayoutTest_BackGroundImage_Editor::init() this->configureGUIScene(); - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - return true; } @@ -564,105 +151,6 @@ UILayoutTest_BackGroundImage_Scale9_Editor::~UILayoutTest_BackGroundImage_Scale9 } -void UILayoutTest_BackGroundImage_Scale9_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage/windows_ui_scale9_backgroundimage.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage/windows_ui_scale9_backgroundimage.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage/crossplatform_Scale9_BackgroundImage.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage/crossplatform_Scale9_BackgroundImage.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_BackGroundImage_Scale9_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_BackGroundImage_Scale9_Editor::init() { if (UIScene_Editor::init()) @@ -701,105 +189,6 @@ UILayoutTest_Layout_Linear_Vertical_Editor::~UILayoutTest_Layout_Linear_Vertical } -void UILayoutTest_Layout_Linear_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Linear_Vertical_Layout/windows_ui_linear_vertical_layout.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Linear_Vertical_Layout/windows_ui_linear_vertical_layout.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Linear_Vertical_Layout/crossplatform_Linear_Vertical_Layout.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Linear_Vertical_Layout/crossplatform_Linear_Vertical_Layout.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Layout_Linear_Vertical_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_Layout_Linear_Vertical_Editor::init() { if (UIScene_Editor::init()) @@ -810,11 +199,6 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init() this->configureGUIScene(); - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f)); - return true; } @@ -834,105 +218,6 @@ UILayoutTest_Layout_Linear_Horizontal_Editor::~UILayoutTest_Layout_Linear_Horizo } -void UILayoutTest_Layout_Linear_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Linear_Horizontal_Layout/windows_ui_linear_horizontal_layout.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Linear_Horizontal_Layout/windows_ui_linear_horizontal_layout.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Linear_Horizontal_Layout/crossplatform_Linear_Horizontal_Layout.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Linear_Horizontal_Layout/crossplatform_Linear_Horizontal_Layout.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Layout_Linear_Horizontal_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() { if (UIScene_Editor::init()) @@ -942,11 +227,6 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() this->configureGUIScene(); - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f)); - return true; } @@ -966,105 +246,6 @@ UILayoutTest_Layout_Relative_Align_Parent_Editor::~UILayoutTest_Layout_Relative_ } -void UILayoutTest_Layout_Relative_Align_Parent_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Relative_Align_Parent/windows_ui_relative_align_parent.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Relative_Align_Parent/windows_ui_relative_align_parent.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Relative_Align_Parent/crossplatform_Relative_Align_Parent.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Relative_Align_Parent/crossplatform_Relative_Align_Parent.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Layout_Relative_Align_Parent_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() { if (UIScene_Editor::init()) @@ -1073,11 +254,6 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() _touchGroup->addChild(_layout); this->configureGUIScene(); - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f)); - return true; } @@ -1097,105 +273,6 @@ UILayoutTest_Layout_Relative_Location_Editor::~UILayoutTest_Layout_Relative_Loca } -void UILayoutTest_Layout_Relative_Location_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Relative_Align_Location/windows_ui_relative_align_location.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout/Relative_Align_Location/windows_ui_relative_align_location.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Relative_Align_Location/crossplatform_Relative_Align_Location.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILayout/Relative_Align_Location/crossplatform_Relative_Align_Location.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UILayoutTest_Layout_Relative_Location_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UILayoutTest_Layout_Relative_Location_Editor::init() { if (UIScene_Editor::init()) @@ -1204,11 +281,6 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() _touchGroup->addChild(_layout); this->configureGUIScene(); - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f)); - return true; } @@ -1227,36 +299,10 @@ UILayoutComponentTest_Editor::~UILayoutComponentTest_Editor() void UILayoutComponentTest_Editor::configureGUIScene() { - Size screenSize = Director::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); + UIScene_Editor::configureGUIScene(); _root = static_cast(_layout->getChildByName("root_Panel")); - ui::Text* back_label = static_cast(Helper::seekWidgetByName(_root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(_root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - _hUnchecked = static_cast(Helper::seekWidgetByName(_root, "Button_h_unchecked")); _vUnchecked = static_cast(Helper::seekWidgetByName(_root, "Button_v_unchecked")); _hChecked = static_cast(Helper::seekWidgetByName(_root, "Button_h_checked")); @@ -1492,4 +538,4 @@ void UILayoutComponentTest_Editor::onResizeContainer(Ref* sender) } }, 0.025, 39, 0, "2"); } -} \ No newline at end of file +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h index 15497c6219..01211abc02 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h @@ -27,132 +27,125 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UILayoutEditorTests); + class UILayoutTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Editor); + UILayoutTest_Editor(); ~UILayoutTest_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Editor) + + virtual bool init() override; }; class UILayoutTest_Color_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Color_Editor); + UILayoutTest_Color_Editor(); ~UILayoutTest_Color_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Color_Editor) -}; + virtual bool init() override; +}; class UILayoutTest_Gradient_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Gradient_Editor); + UILayoutTest_Gradient_Editor(); ~UILayoutTest_Gradient_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Gradient_Editor) + + virtual bool init() override; }; class UILayoutTest_BackGroundImage_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_BackGroundImage_Editor); + UILayoutTest_BackGroundImage_Editor(); ~UILayoutTest_BackGroundImage_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_BackGroundImage_Editor) + + virtual bool init() override; }; class UILayoutTest_BackGroundImage_Scale9_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_BackGroundImage_Scale9_Editor); + UILayoutTest_BackGroundImage_Scale9_Editor(); ~UILayoutTest_BackGroundImage_Scale9_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_BackGroundImage_Scale9_Editor) + + virtual bool init() override; }; class UILayoutTest_Layout_Linear_Vertical_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Layout_Linear_Vertical_Editor); + UILayoutTest_Layout_Linear_Vertical_Editor(); ~UILayoutTest_Layout_Linear_Vertical_Editor(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); - bool init(); - -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Linear_Vertical_Editor) + + virtual bool init() override; }; class UILayoutTest_Layout_Linear_Horizontal_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Layout_Linear_Horizontal_Editor); + UILayoutTest_Layout_Linear_Horizontal_Editor(); ~UILayoutTest_Layout_Linear_Horizontal_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Linear_Horizontal_Editor) + + virtual bool init() override; }; class UILayoutTest_Layout_Relative_Align_Parent_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Layout_Relative_Align_Parent_Editor); + UILayoutTest_Layout_Relative_Align_Parent_Editor(); ~UILayoutTest_Layout_Relative_Align_Parent_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Relative_Align_Parent_Editor) + + virtual bool init() override; }; class UILayoutTest_Layout_Relative_Location_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutTest_Layout_Relative_Location_Editor); + UILayoutTest_Layout_Relative_Location_Editor(); ~UILayoutTest_Layout_Relative_Location_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Relative_Location_Editor) + + virtual bool init() override; }; class UILayoutComponentTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILayoutComponentTest_Editor); + UILayoutComponentTest_Editor(); ~UILayoutComponentTest_Editor(); + virtual bool init() override; - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILayoutComponentTest_Editor) + virtual void configureGUIScene() override; + private: void onChangeLayoutComponent(Ref* sender); void onResizeContainer(Ref* sender); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 8de636b9de..652646ac1d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -1,9 +1,13 @@ - - #include "UIListViewTest.h" const char* font_UIListViewTest = "fonts/Marker Felt.ttf"; +UIListViewTests::UIListViewTests() +{ + ADD_TEST_CASE(UIListViewTest_Vertical); + ADD_TEST_CASE(UIListViewTest_Horizontal); +} + // UIListViewTest_Vertical UIListViewTest_Vertical::UIListViewTest_Vertical() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h index 72e7382f5c..60ba198a6a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h @@ -28,17 +28,22 @@ #include "../UIScene.h" #include "ui/UIScrollView.h" +DEFINE_TEST_SUITE(UIListViewTests); + class UIListViewTest_Vertical : public UIScene { public: + CREATE_FUNC(UIListViewTest_Vertical); + UIListViewTest_Vertical(); ~UIListViewTest_Vertical(); - bool init(); + + virtual bool init() override; void selectedItemEvent(Ref* pSender, ListView::EventType type); void selectedItemEventScrollView(Ref* pSender, ui::ScrollView::EventType type); protected: - UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical) + Text* _displayValueLabel; std::vector _array; @@ -47,14 +52,17 @@ protected: class UIListViewTest_Horizontal : public UIScene { public: + CREATE_FUNC(UIListViewTest_Horizontal); + UIListViewTest_Horizontal(); ~UIListViewTest_Horizontal(); - bool init(); + + virtual bool init() override; void selectedItemEvent(Ref* pSender, ListView::EventType type); protected: - UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal) + Text* _displayValueLabel; std::vector _array; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp index 7afe1b1b92..e8f6b43ae2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp @@ -1,8 +1,11 @@ - #include "UIListViewTest_Editor.h" #include "VisibleRect.h" - +UIListViewEditorTests::UIListViewEditorTests() +{ + ADD_TEST_CASE(UIListViewTest_Vertical_Editor); + ADD_TEST_CASE(UIListViewTest_Horizontal_Editor); +} // UIListViewTest_Vertical_Editor UIListViewTest_Vertical_Editor::UIListViewTest_Vertical_Editor() @@ -16,110 +19,6 @@ UIListViewTest_Vertical_Editor::~UIListViewTest_Vertical_Editor() } -void UIListViewTest_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView/Vertical/windows_ui_listview_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView/Vertical/windows_ui_listview_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/Vertical/crossplatform_UIListView_Vertical_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/Vertical/crossplatform_UIListView_Vertical_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIListViewTest_Vertical_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - // ListView* listView = static_cast(UIHelper::seekWidgetByName(root, "ListView_1214")); - // CCLOG("listView isBounceEnabled = %d", listView->isBounceEnabled()); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); - - - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback,this)); - _layout->addChild(right_button); - -} - bool UIListViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) @@ -198,7 +97,6 @@ void UIListViewTest_Vertical_Editor::setupListView(ListView* listView) listView->pushBackDefaultItem(); } - // UIListViewTest_Horizontal_Editor UIListViewTest_Horizontal_Editor::UIListViewTest_Horizontal_Editor() @@ -207,105 +105,6 @@ UIListViewTest_Horizontal_Editor::UIListViewTest_Horizontal_Editor() } -void UIListViewTest_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView/Horizontal/windows_ui_listview_horizontal_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView/Horizontal/windows_ui_listview_horizontal_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/Horizontal/crossplatform_UIListView_Horizontal_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIListView/Horizontal/crossplatform_UIListView_Horizontal_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIListViewTest_Horizontal_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - UIListViewTest_Horizontal_Editor::~UIListViewTest_Horizontal_Editor() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h index d6761b3566..5d876a34ca 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h @@ -27,18 +27,20 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UIListViewEditorTests); + class UIListViewTest_Vertical_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIListViewTest_Vertical_Editor); + static void setupListView(ListView* listView); UIListViewTest_Vertical_Editor(); ~UIListViewTest_Vertical_Editor(); - bool init(); + + virtual bool init() override; void selectedItemEvent(Ref* pSender, ListView::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIListViewTest_Vertical_Editor) Text* _displayValueLabel; __Array* _array; @@ -48,14 +50,14 @@ protected: class UIListViewTest_Horizontal_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIListViewTest_Horizontal_Editor); + UIListViewTest_Horizontal_Editor(); ~UIListViewTest_Horizontal_Editor(); - bool init(); + + virtual bool init() override; void selectedItemEvent(Ref* pSender, ListView::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIListViewTest_Horizontal_Editor) Text* _displayValueLabel; __Array* _array; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index fcf8ed7580..19b1d086cd 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -1,7 +1,14 @@ - - #include "UILoadingBarTest.h" +UILoadingBarTests::UILoadingBarTests() +{ + ADD_TEST_CASE(UILoadingBarTest_Left); + ADD_TEST_CASE(UILoadingBarTest_Right); + ADD_TEST_CASE(UILoadingBarTest_Left_Scale9); + ADD_TEST_CASE(UILoadingBarTest_Right_Scale9); + ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change); + ADD_TEST_CASE(UILoadingBarReloadTexture); +} // UILoadingBarTest_Left @@ -68,33 +75,6 @@ void UILoadingBarTest_Left::update(float delta) loadingBar->setPercent(_count); } -void UILoadingBarTest_Left::previousCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::previousCallback(sender, type); - } -} - -void UILoadingBarTest_Left::restartCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::restartCallback(sender, type); - } -} - -void UILoadingBarTest_Left::nextCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::nextCallback(sender, type); - } -} - // UILoadingBarTest_Right UILoadingBarTest_Right::UILoadingBarTest_Right() @@ -148,33 +128,6 @@ void UILoadingBarTest_Right::update(float delta) loadingBar->setPercent(_count); } -void UILoadingBarTest_Right::previousCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::previousCallback(sender, type); - } -} - -void UILoadingBarTest_Right::restartCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::restartCallback(sender, type); - } -} - -void UILoadingBarTest_Right::nextCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::nextCallback(sender, type); - } -} - // UILoadingBarTest_Left_Scale9 UILoadingBarTest_Left_Scale9::UILoadingBarTest_Left_Scale9() @@ -230,33 +183,6 @@ void UILoadingBarTest_Left_Scale9::update(float delta) loadingBar->setPercent(_count); } -void UILoadingBarTest_Left_Scale9::previousCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::previousCallback(sender, type); - } -} - -void UILoadingBarTest_Left_Scale9::restartCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::restartCallback(sender, type); - } -} - -void UILoadingBarTest_Left_Scale9::nextCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::nextCallback(sender, type); - } -} - // UILoadingBarTest_Right_Scale9 UILoadingBarTest_Right_Scale9::UILoadingBarTest_Right_Scale9() @@ -313,34 +239,6 @@ void UILoadingBarTest_Right_Scale9::update(float delta) loadingBar->setPercent(_count); } -void UILoadingBarTest_Right_Scale9::previousCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::previousCallback(sender, type); - } -} - -void UILoadingBarTest_Right_Scale9::restartCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::restartCallback(sender, type); - } -} - -void UILoadingBarTest_Right_Scale9::nextCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - unscheduleUpdate(); - UIScene::nextCallback(sender, type); - } -} - - // UILoadingBarTest_Scale9_State_Change UILoadingBarTest_Scale9_State_Change::UILoadingBarTest_Scale9_State_Change() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h index 9a71e3f8b0..c5a2e58865 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h @@ -27,96 +27,88 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UILoadingBarTests); + class UILoadingBarTest_Left : public UIScene { public: + CREATE_FUNC(UILoadingBarTest_Left); + UILoadingBarTest_Left(); ~UILoadingBarTest_Left(); - bool init(); + virtual bool init() override; void update(float delta); - - virtual void previousCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void restartCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void nextCallback(Ref* sender, Widget::TouchEventType type) override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarTest_Left) int _count; }; class UILoadingBarTest_Right : public UIScene { public: + CREATE_FUNC(UILoadingBarTest_Right); + UILoadingBarTest_Right(); ~UILoadingBarTest_Right(); - bool init(); + virtual bool init() override; void update(float delta); - - virtual void previousCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void restartCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void nextCallback(Ref* sender, Widget::TouchEventType type) override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarTest_Right) int _count; }; class UILoadingBarTest_Left_Scale9 : public UIScene { public: + CREATE_FUNC(UILoadingBarTest_Left_Scale9); + UILoadingBarTest_Left_Scale9(); ~UILoadingBarTest_Left_Scale9(); - bool init(); + virtual bool init() override; void update(float delta); - - virtual void previousCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void restartCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void nextCallback(Ref* sender, Widget::TouchEventType type) override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarTest_Left_Scale9) int _count; }; class UILoadingBarTest_Right_Scale9 : public UIScene { public: + CREATE_FUNC(UILoadingBarTest_Right_Scale9); + UILoadingBarTest_Right_Scale9(); ~UILoadingBarTest_Right_Scale9(); - bool init(); + virtual bool init() override; void update(float delta); - - virtual void previousCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void restartCallback(Ref* sender, Widget::TouchEventType type) override; - virtual void nextCallback(Ref* sender, Widget::TouchEventType type) override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarTest_Right_Scale9) int _count; }; class UILoadingBarTest_Scale9_State_Change : public UIScene { public: + CREATE_FUNC(UILoadingBarTest_Scale9_State_Change); + UILoadingBarTest_Scale9_State_Change(); ~UILoadingBarTest_Scale9_State_Change(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarTest_Scale9_State_Change) int _count; }; class UILoadingBarReloadTexture : public UIScene { public: + CREATE_FUNC(UILoadingBarReloadTexture); + UILoadingBarReloadTexture(); ~UILoadingBarReloadTexture(); void update(float dt) override; - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UILoadingBarReloadTexture); int _count; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp index 9d2ccff706..7b32cf908b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp @@ -1,8 +1,9 @@ - - #include "UILoadingBarTest_Editor.h" - +UILoadingBarEditorTests::UILoadingBarEditorTests() +{ + ADD_TEST_CASE(UILoadingBarTest_Editor); +} // UILoadingBarTest_Editor UILoadingBarTest_Editor::UILoadingBarTest_Editor() @@ -16,93 +17,17 @@ UILoadingBarTest_Editor::~UILoadingBarTest_Editor() } -void UILoadingBarTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - _count = 0; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar/windows_ui_loadingbar_editor_1.json")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILoadingBar/windows_ui_loadingbar_editor_1.csb")); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILoadingBar/crossplatform_UILoadingBar_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILoadingBar/crossplatform_UILoadingBar_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UILoadingBarTest_Editor::configureGUIScene() { - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - + UIScene_Editor::configureGUIScene(); + Layout* root = static_cast(_layout->getChildByName("root_Panel")); - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - // back_label->addTouchEventListener(this, toucheventselector(UIScene_Editor::toGUIEditorTestScene)); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - LoadingBar* loadingBar_left_to_right = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_856")); loadingBar_left_to_right->setPercent(0); LoadingBar* loadingBar_right_to_left = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_857")); loadingBar_right_to_left->setPercent(0); - } bool UILoadingBarTest_Editor::init() @@ -141,20 +66,3 @@ void UILoadingBarTest_Editor::update(float delta) LoadingBar* loadingBar_right_to_left = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_857")); loadingBar_right_to_left->setPercent(_count); } - -void UILoadingBarTest_Editor::toCocosGUITestScene(Ref* sender, Widget::TouchEventType event) -{ - switch (event) - { - case Widget::TouchEventType::ENDED: - { - unscheduleUpdate(); - - UIScene_Editor::toGUIEditorTestScene(sender, event); - } - break; - - default: - break; - } -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h index ed7c26d39e..5d12bb196a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h @@ -5,18 +5,20 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UILoadingBarEditorTests); + class UILoadingBarTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UILoadingBarTest_Editor); + UILoadingBarTest_Editor(); ~UILoadingBarTest_Editor(); - bool init(); + virtual bool init() override; void update(float delta); - void toCocosGUITestScene(Ref* sender, Widget::TouchEventType event); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + + virtual void configureGUIScene() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UILoadingBarTest_Editor) int _count; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 234164a37c..f6e11882bc 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -1,8 +1,15 @@ - - #include "UIPageViewTest.h" #include "cocos2d.h" +UIPageViewTests::UIPageViewTests() +{ + ADD_TEST_CASE(UIPageViewTest); + ADD_TEST_CASE(UIPageViewButtonTest); + ADD_TEST_CASE(UIPageViewCustomScrollThreshold); + ADD_TEST_CASE(UIPageViewTouchPropagationTest); + ADD_TEST_CASE(UIPageViewDynamicAddAndRemoveTest); +} + // UIPageViewTest UIPageViewTest::UIPageViewTest() : _displayValueLabel(nullptr) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h index 5f9c492bc7..3886dcbda0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h @@ -27,76 +27,88 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIPageViewTests); + class UIPageViewTest : public UIScene { public: + CREATE_FUNC(UIPageViewTest); + UIPageViewTest(); ~UIPageViewTest(); - bool init(); + virtual bool init() override; void pageViewEvent(Ref* pSender, PageView::EventType type); protected: - UI_SCENE_CREATE_FUNC(UIPageViewTest) + Text* _displayValueLabel; }; class UIPageViewButtonTest : public UIScene { public: + CREATE_FUNC(UIPageViewButtonTest); + UIPageViewButtonTest(); ~UIPageViewButtonTest(); - bool init(); + virtual bool init() override; void pageViewEvent(Ref* pSender, PageView::EventType type); void onButtonClicked(Ref* pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIPageViewButtonTest) + Text* _displayValueLabel; }; class UIPageViewCustomScrollThreshold : public UIScene { public: + CREATE_FUNC(UIPageViewCustomScrollThreshold); + UIPageViewCustomScrollThreshold(); ~UIPageViewCustomScrollThreshold(); - bool init(); + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); void pageViewEvent(Ref* pSender, PageView::EventType type); protected: - UI_SCENE_CREATE_FUNC(UIPageViewCustomScrollThreshold) + Text* _displayValueLabel; }; class UIPageViewTouchPropagationTest : public UIScene { public: + CREATE_FUNC(UIPageViewTouchPropagationTest); + UIPageViewTouchPropagationTest(); ~UIPageViewTouchPropagationTest(); - bool init(); + virtual bool init() override; void pageViewEvent(Ref* pSender, PageView::EventType type); void onButtonClicked(Ref* pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIPageViewTouchPropagationTest) + Text* _displayValueLabel; }; class UIPageViewDynamicAddAndRemoveTest : public UIScene { public: + CREATE_FUNC(UIPageViewDynamicAddAndRemoveTest); + UIPageViewDynamicAddAndRemoveTest(); ~UIPageViewDynamicAddAndRemoveTest(); - bool init(); + virtual bool init() override; void pageViewEvent(Ref* pSender, PageView::EventType type); void onButtonClicked(Ref* pSender, Widget::TouchEventType type); protected: - UI_SCENE_CREATE_FUNC(UIPageViewDynamicAddAndRemoveTest) + Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp index 715604ef83..5c86f0e044 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp @@ -1,8 +1,10 @@ - - #include "UIPageViewTest_Editor.h" #include "VisibleRect.h" +UIPageViewEditorTests::UIPageViewEditorTests() +{ + ADD_TEST_CASE(UIPageViewTest_Editor); +} // UIPageViewTest_Editor @@ -17,107 +19,6 @@ UIPageViewTest_Editor::~UIPageViewTest_Editor() } -void UIPageViewTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView/windows_ui_pageview_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIPageView/windows_ui_pageview_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIPageView/crossplatform_UIPageView_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIPageView/crossplatform_UIPageView_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIPageViewTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UIPageViewTest_Editor::init() { if (UIScene_Editor::init()) @@ -129,14 +30,7 @@ bool UIPageViewTest_Editor::init() _touchGroup->addChild(_layout); this->configureGUIScene(); - - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - + return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h index 82248d2fdc..9e2b7a190b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h @@ -27,18 +27,20 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UIPageViewEditorTests); + class UIPageViewTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIPageViewTest_Editor); + UIPageViewTest_Editor(); ~UIPageViewTest_Editor(); - bool init(); + + virtual bool init() override; void pageViewEvent(Ref* pSender, PageView::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIPageViewTest_Editor) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index c9c3049ec6..dcb63c8652 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -1,9 +1,12 @@ - - #include "UIRichTextTest.h" #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCArmature.h" +UIRichTextTests::UIRichTextTests() +{ + ADD_TEST_CASE(UIRichTextTest); +} + UIRichTextTest::UIRichTextTest() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h index 0563fec64e..ac47afdd02 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h @@ -5,17 +5,19 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIRichTextTests); + class UIRichTextTest : public UIScene { public: + CREATE_FUNC(UIRichTextTest); + UIRichTextTest(); ~UIRichTextTest(); - bool init(); + + virtual bool init() override; void touchEvent(Ref *pSender, Widget::TouchEventType type); -protected: - UI_SCENE_CREATE_FUNC(UIRichTextTest) - protected: RichText* _richText; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp index df3f9c6433..7195c65e09 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp @@ -25,6 +25,32 @@ #include "UIScale9SpriteTest.h" #include "testResource.h" +UIScale9SpriteTests::UIScale9SpriteTests() +{ + ADD_TEST_CASE(UIScale9SpriteTest); + ADD_TEST_CASE(UIScale9SpriteHierarchialTest); + ADD_TEST_CASE(UIScale9SpriteTouchTest); + ADD_TEST_CASE(UIS9BatchNodeBasic); + ADD_TEST_CASE(UIS9FrameNameSpriteSheet); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetRotated); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetCropped); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetCroppedRotated); + ADD_TEST_CASE(UIS9BatchNodeScaledNoInsets); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetScaledNoInsets); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetRotatedScaledNoInsets); + ADD_TEST_CASE(UIS9BatchNodeScaleWithCapInsets); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetInsets); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetInsetsScaled); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetRotatedInsets); + ADD_TEST_CASE(UIS9_TexturePacker); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetRotatedInsetsScaled); + ADD_TEST_CASE(UIS9FrameNameSpriteSheetRotatedSetCapInsetLater); + ADD_TEST_CASE(UIS9CascadeOpacityAndColor); + ADD_TEST_CASE(UIS9ZOrder); + ADD_TEST_CASE(UIS9Flip); + ADD_TEST_CASE(UIS9ChangeAnchorPoint); +} + // UIScale9SpriteTest UIScale9SpriteTest::UIScale9SpriteTest() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h index d66733f995..3edba14cb4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h @@ -26,37 +26,39 @@ #define __cocos2d_tests__UIScale9SpriteTest__ #include "UIScene.h" +DEFINE_TEST_SUITE(UIScale9SpriteTests); + class UIScale9SpriteTest : public UIScene { public: + CREATE_FUNC(UIScale9SpriteTest); + UIScale9SpriteTest(); ~UIScale9SpriteTest(); - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIScale9SpriteTest) + + virtual bool init() override; }; class UIScale9SpriteHierarchialTest : public UIScene { public: + CREATE_FUNC(UIScale9SpriteHierarchialTest); + UIScale9SpriteHierarchialTest(); ~UIScale9SpriteHierarchialTest(); - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIScale9SpriteHierarchialTest) + + virtual bool init() override; }; class UIScale9SpriteTouchTest : public UIScene { public: + CREATE_FUNC(UIScale9SpriteTouchTest); + UIScale9SpriteTouchTest(); ~UIScale9SpriteTouchTest(); - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIScale9SpriteTouchTest) + + virtual bool init() override; }; // S9BatchNodeBasic @@ -66,9 +68,7 @@ class UIS9BatchNodeBasic : public UIScene public: CREATE_FUNC(UIS9BatchNodeBasic); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9BatchNodeBasic) + virtual bool init() override; }; // S9FrameNameSpriteSheet @@ -78,10 +78,7 @@ class UIS9FrameNameSpriteSheet : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheet); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheet) - + virtual bool init() override; }; // S9FrameNameSpriteSheetRotated @@ -91,9 +88,7 @@ class UIS9FrameNameSpriteSheetRotated : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetRotated); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetRotated) + virtual bool init() override; }; // S9FrameNameSpriteSheetCropped @@ -103,9 +98,7 @@ class UIS9FrameNameSpriteSheetCropped : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetCropped); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetCropped) + virtual bool init() override; }; // S9FrameNameSpriteSheetCroppedRotated @@ -115,9 +108,7 @@ class UIS9FrameNameSpriteSheetCroppedRotated : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetCroppedRotated); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetCroppedRotated) + virtual bool init() override; }; // S9BatchNodeScaledNoInsets @@ -127,9 +118,7 @@ class UIS9BatchNodeScaledNoInsets : public UIScene public: CREATE_FUNC(UIS9BatchNodeScaledNoInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9BatchNodeScaledNoInsets) + virtual bool init() override; }; // S9FrameNameSpriteSheetScaledNoInsets @@ -139,9 +128,7 @@ class UIS9FrameNameSpriteSheetScaledNoInsets : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetScaledNoInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetScaledNoInsets) + virtual bool init() override; }; // S9FrameNameSpriteSheetRotatedScaledNoInsets @@ -151,9 +138,7 @@ class UIS9FrameNameSpriteSheetRotatedScaledNoInsets : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedScaledNoInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedScaledNoInsets) + virtual bool init() override; }; @@ -164,9 +149,7 @@ class UIS9BatchNodeScaleWithCapInsets : public UIScene public: CREATE_FUNC(UIS9BatchNodeScaleWithCapInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9BatchNodeScaleWithCapInsets) + virtual bool init() override; }; // S9FrameNameSpriteSheetInsets @@ -176,9 +159,7 @@ class UIS9FrameNameSpriteSheetInsets : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetInsets) + virtual bool init() override; }; // S9FrameNameSpriteSheetInsetsScaled @@ -188,9 +169,7 @@ class UIS9FrameNameSpriteSheetInsetsScaled : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetInsetsScaled); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetInsetsScaled) + virtual bool init() override; }; // S9FrameNameSpriteSheetRotatedInsets @@ -200,9 +179,7 @@ class UIS9FrameNameSpriteSheetRotatedInsets : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedInsets); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedInsets) + virtual bool init() override; }; // S9_TexturePacker @@ -212,10 +189,7 @@ class UIS9_TexturePacker : public UIScene public: CREATE_FUNC(UIS9_TexturePacker); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9_TexturePacker) - + virtual bool init() override; }; // S9FrameNameSpriteSheetRotatedInsetsScaled @@ -225,9 +199,7 @@ class UIS9FrameNameSpriteSheetRotatedInsetsScaled : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedInsetsScaled); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedInsetsScaled) + virtual bool init() override; }; // S9FrameNameSpriteSheetRotatedInsetsScaled @@ -237,9 +209,7 @@ class UIS9FrameNameSpriteSheetRotatedSetCapInsetLater : public UIScene public: CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedSetCapInsetLater); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9FrameNameSpriteSheetRotatedSetCapInsetLater) + virtual bool init() override; }; // S9CascadeOpacityAndColor @@ -249,9 +219,7 @@ class UIS9CascadeOpacityAndColor : public UIScene public: CREATE_FUNC(UIS9CascadeOpacityAndColor); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9CascadeOpacityAndColor) + virtual bool init() override; }; // Scale9Sprite ZOrder @@ -261,10 +229,7 @@ class UIS9ZOrder : public UIScene public: CREATE_FUNC(UIS9ZOrder); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9ZOrder) - + virtual bool init() override; }; // Scale9Sprite Flip @@ -274,9 +239,7 @@ class UIS9Flip : public UIScene public: CREATE_FUNC(UIS9Flip); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9Flip) + virtual bool init() override; }; class UIS9ChangeAnchorPoint : public UIScene @@ -284,9 +247,7 @@ class UIS9ChangeAnchorPoint : public UIScene public: CREATE_FUNC(UIS9ChangeAnchorPoint); - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UIS9ChangeAnchorPoint) + virtual bool init() override; }; #endif /* defined(__cocos2d_tests__UIScale9SpriteTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.cpp index 3f212dbddf..6b7b11cf85 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.cpp @@ -1,4 +1,3 @@ - #include "extensions/cocos-ext.h" #include "UIScene.h" #include "UISceneManager.h" @@ -8,8 +7,8 @@ using namespace ui; UIScene::UIScene() -: _sceneTitle(nullptr) -, _uiLayer(nullptr) +: _uiLayer(nullptr) +, _sceneTitle(nullptr) { } @@ -21,7 +20,7 @@ UIScene::~UIScene() bool UIScene::init() { - if (CCLayer::init()) + if (TestCase::init()) { _uiLayer = Layer::create(); addChild(_uiLayer); @@ -33,81 +32,21 @@ bool UIScene::init() Size rootSize = _widget->getContentSize(); _uiLayer->setPosition(Vec2((screenSize.width - rootSize.width) / 2, (screenSize.height - rootSize.height) / 2)); - + Layout* root = static_cast(_uiLayer->getChildByTag(81)); - + _sceneTitle = dynamic_cast(root->getChildByName("UItest")); - - Text* back_label = dynamic_cast(root->getChildByName("back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene::toCocosGUITestScene, this)); - - Button* left_button = dynamic_cast(root->getChildByName("left_Button")); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene::previousCallback, this)); - - Button* middle_button = dynamic_cast(root->getChildByName("middle_Button")); - middle_button->addTouchEventListener(CC_CALLBACK_2(UIScene::restartCallback, this)); - - Button* right_button = dynamic_cast(root->getChildByName("right_Button")); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene::nextCallback, this)); - - /* - Text* mainMenuLabel = Text::create(); - mainMenuLabel->setText("MainMenu"); - mainMenuLabel->setFontSize(20); - mainMenuLabel->setTouchScaleChangeEnabled(true); - mainMenuLabel->setPosition(Vec2(430,30)); - mainMenuLabel->setTouchEnabled(true); - mainMenuLabel->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback)); - _uiLayer->addWidget(mainMenuLabel); - */ - - return true; } return false; } -void UIScene::menuCloseCallback(Ref* sender, Widget::TouchEventType type) +void UIScene::onEnter() { - if (type == Widget::TouchEventType::ENDED) - { - _uiLayer->removeFromParent(); - - } -} + TestCase::onEnter(); -void UIScene::toCocosGUITestScene(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) + if (_sceneTitle) { - UISceneManager::purgeUISceneManager(); - - CocosGUITestScene* pScene = new (std::nothrow) CocosGUITestScene(); - pScene->runThisTest(); - pScene->release(); - } -} - -void UIScene::previousCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->previousUIScene()); - } -} - -void UIScene::restartCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->currentUIScene()); - } -} - -void UIScene::nextCallback(Ref* sender, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) - { - CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->nextUIScene()); + _sceneTitle->setString(getTestCaseName()); } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h index dcdca668bb..02c34cee1e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h @@ -28,54 +28,24 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "ui/CocosGUI.h" +#include "BaseTest.h" USING_NS_CC; USING_NS_CC_EXT; using namespace cocos2d::ui; -#define UI_SCENE_CREATE_FUNC(UIScene) \ -public: \ -static Scene* sceneWithTitle(const char * title) \ -{ \ - Scene* pScene = Scene::create(); \ - UIScene* uiLayer = new (std::nothrow) UIScene(); \ - if (uiLayer && uiLayer->init()) \ - { \ - uiLayer->autorelease(); \ - uiLayer->getSceneTitle()->setString(title); \ - pScene->addChild(uiLayer); \ - } \ - else \ - { \ - CC_SAFE_DELETE(uiLayer); \ - } \ - return pScene; \ -} - -class UIScene : public Layer +class UIScene : public TestCase { public: UIScene(); ~UIScene(); - bool init(); - // Menu Callbacks - void toCocosGUITestScene(Ref* sender, Widget::TouchEventType type); - virtual void previousCallback(Ref* sender, Widget::TouchEventType type); - virtual void restartCallback(Ref* sender, Widget::TouchEventType type); - virtual void nextCallback(Ref* sender, Widget::TouchEventType type); - - /** Title label of the scene. */ - CC_SYNTHESIZE_READONLY(Text*, _sceneTitle, SceneTitle) - - UI_SCENE_CREATE_FUNC(UIScene); - -protected: - // a selector callback - void menuCloseCallback(Ref* sender, Widget::TouchEventType type); - + + virtual bool init() override; + virtual void onEnter() override; protected: Layer* _uiLayer; Layout* _widget; + Text* _sceneTitle; }; #endif /* defined(__TestCpp__UIScene__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 90439e937a..e69de29bb2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -1,471 +0,0 @@ - - -#include "UISceneManager.h" -#include "UIScene.h" -#include "UIButtonTest/UIButtonTest.h" -#include "UICheckBoxTest/UICheckBoxTest.h" -#include "UISliderTest/UISliderTest.h" -#include "UIImageViewTest/UIImageViewTest.h" -#include "UILoadingBarTest/UILoadingBarTest.h" -#include "UITextAtlasTest/UITextAtlasTest.h" -#include "UITextTest/UITextTest.h" -#include "UITextBMFontTest/UITextBMFontTest.h" -#include "UITextFieldTest/UITextFieldTest.h" -#include "UILayoutTest/UILayoutTest.h" -#include "UIScrollViewTest/UIScrollViewTest.h" -#include "UIPageViewTest/UIPageViewTest.h" -#include "UIListViewTest/UIListViewTest.h" -#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h" -#include "UIRichTextTest/UIRichTextTest.h" -#include "UIFocusTest/UIFocusTest.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "UIVideoPlayerTest/UIVideoPlayerTest.h" -#endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "UIWebViewTest/UIWebViewTest.h" -#endif -#include "UIScale9SpriteTest.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) -#include "UIEditBoxTest.h" -#endif - - -USING_NS_CC; - -static const char* s_testArray[] = -{ - "UIButtonTest", - "UIButtonTest_Scale9", - "UIButtonTest_Scale9_State_Change", - "UIButtonTest_PressedAction", - "UIButtonTest_Title", - "UIButtonTest_RemoveSelf", - "UIButtonTestSwitchScale9", - "UIButtonTestZoomScale", - "UIButtonTextOnly", - "UIButtonIgnoreContentSizeTest", - "UIButtonTitleEffectTest", - "UIButtonFlipTest", - "UIButtonNormalDefaultTest", - "UIButtonDisableDefaultTest", - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - "UIEditBoxTest", -#endif - "UICheckBoxTest", - "UICheckBoxDefaultBehaviorTest", - "UISliderTest", - "UISliderTest_Scale9", - "UISliderTest_Scale9_Stata_Change", - "UISliderNormalDefaultTest", - "UISliderDisabledDefaultTest", - - "UIImageViewTest", - "UIImageViewTest_Scale9", - "UIImageViewTest_Scale9_State_Change", - "UIImageViewTest_ContentSize", - "UIImageViewFlipTest", - - "UILoadingBarTest_Left", - "UILoadingBarTest_Right", - "UILoadingBarTest_Scale9_State_Change", - "UILoadingBarTest_Left_Scale9", - "UILoadingBarTest_Right_Scale9", - "UILoadingBarReloadTexture", - - "UITextAtlasTest", - "UITextTest", - "UITextTest_LineWrap", - "UILabelTest_Effect", - "UITextTest_TTF", - "UITextTest_IgnoreConentSize", - "UITextBMFontTest", - - "UITextFieldTest", - "UITextFieldTest_MaxLength", - "UITextFieldTest_Password", - "UITextFieldTest_LineWrap", - "UITextFieldTest_TrueTypeFont", - "UITextFieldTest_PlaceHolderColor", - - "UILayoutTest", - "UILayoutTest_Color", - "UILayoutTest_Gradient", - "UILayoutTest_BackGroundImage", - "UILayoutTest_BackGroundImage_Scale9", - "UILayoutTest_Layout_Linear_Vertical", - "UILayoutTest_Layout_Linear_Horizontal", - "UILayoutTest_Layout_Relative_Align_Parent", - "UILayoutTest_Layout_Relative_Location", - "UILayoutComponent_Berth_Test", - "UILayoutComponent_Berth_Stretch_Test", - - "UIScrollViewTest_Vertical", - "UIScrollViewTest_Horizontal", - "UIScrollViewTest_Both", - "UIScrollViewTest_ScrollToPercentBothDirection", - "UIScrollViewTest_ScrollToPercentBothDirection_Bounce", - "UIScrollViewNestTest", - "UIScrollViewRotated", - - "UIPageViewTest", - "UIPageViewButtonTest", - "UIPageViewCustomScrollThreshold", - "UIPageViewTouchPropagationTest", - "UIPageViewDynamicAddAndRemoveTest", - - "UIListViewTest_Vertical", - "UIListViewTest_Horizontal", - - "UIWidgetAddNodeTest", - - "UIRichTextTest", - - "UIFocusTest-HBox", - "UIFocusTest-VBox", - "UIFocusTest-NestedLayout1", - "UIFocusTest-NestedLayout2", - "UIFocusTest-NestedLayout3", - "UIFocusTest-ListView", -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - "UIVideoPlayerTest", -#endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - "UIWebViewTest", -#endif - "UIScale9SpriteTest", - "UIScale9SpriteHierarchialTest", - "UIScale9SpriteTouchTest", - "UIS9BatchNodeBasic", - "UIS9FrameNameSpriteSheet", - "UIS9FrameNameSpriteSheetRotated", - "UIS9FrameNameSpriteSheetCropped", - "UIS9FrameNameSpriteSheetCroppedRotated", - "UIS9BatchNodeScaledNoInsets", - "UIS9FrameNameSpriteSheetScaledNoInsets", - "UIS9FrameNameSpriteSheetRotatedScaledNoInsets", - "UIS9BatchNodeScaleWithCapInsets", - "UIS9FrameNameSpriteSheetInsets", - "UIS9FrameNameSpriteSheetInsetsScaled", - "UIS9FrameNameSpriteSheetRotatedInsets", - "UIS9_TexturePacker", - "UIS9FrameNameSpriteSheetRotatedInsetsScaled", - "UIS9FrameNameSpriteSheetRotatedSetCapInsetLater", - "UIS9CascadeOpacityAndColor", - "UIS9ZOrder", - "UIS9Flip", - "UIS9ChangeAnchorPoint", -}; - -static UISceneManager *sharedInstance = nullptr; - - -UISceneManager::UISceneManager() -{ - _currentUISceneId = kUIButtonTest; -} - -UISceneManager::~UISceneManager() -{ - -} - -UISceneManager * UISceneManager::sharedUISceneManager() -{ - if (sharedInstance == nullptr) - { - sharedInstance = new (std::nothrow) UISceneManager(); - } - return sharedInstance; -} - -void UISceneManager::purgeUISceneManager() -{ - CC_SAFE_DELETE(sharedInstance); -} - -Scene *UISceneManager::nextUIScene() -{ - _currentUISceneId = _currentUISceneId + 1; - if (_currentUISceneId > _maxUISceneId) - { - _currentUISceneId = _minUISceneId; - } - - return currentUIScene(); -} - -Scene *UISceneManager::previousUIScene() -{ - _currentUISceneId = _currentUISceneId - 1; - if (_currentUISceneId < _minUISceneId) - { - _currentUISceneId = _maxUISceneId; - } - - return currentUIScene(); -} - -Scene *UISceneManager::currentUIScene() -{ - switch (_currentUISceneId) - { - case kUIButtonTest: - return UIButtonTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIButtonTest_Scale9: - return UIButtonTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTest_Scale9_State_Change: - return UIButtonTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIButtonTest_PressedAction: - return UIButtonTest_PressedAction::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIButtonTest_Title: - return UIButtonTest_Title::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTest_RemoveSelf: - return UIButtonTestRemoveSelf::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTestSwitchScale9: - return UIButtonTestSwitchScale9::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTestZoomScale: - return UIButtonTestZoomScale::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTextOnly: - return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonIgnoreContentSizeTest: - return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonTitleEffectTest: - return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonFlipTest: - return UIButtonFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonNormalDefaultTest: - return UIButtonNormalDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIButtonDisableDefaultTest: - return UIButtonDisableDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUICheckBoxTest: - return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUICheckBoxDefaultBehaviorTest: - return UICheckBoxDefaultBehaviorTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUISliderTest: - return UISliderTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUISliderTest_Scale9: - return UISliderTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUISliderTest_Scale9_State_Change: - return UISliderTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUISliderNormalDefaultTest: - return UISliderNormalDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUISliderDisabledDefaultTest: - return UISliderDisabledDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIImageViewTest: - return UIImageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIImageViewTest_Scale9: - return UIImageViewTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIImageViewTest_Scale9_State_Change: - return UIImageViewTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIImageViewTest_ContentSize: - return UIImageViewTest_ContentSize::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIImageViewFlipTest: - return UIImageViewFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Left: - return UILoadingBarTest_Left::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Right: - return UILoadingBarTest_Right::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Scale9_State_Change: - return UILoadingBarTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Left_Scale9: - return UILoadingBarTest_Left_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Right_Scale9: - return UILoadingBarTest_Right_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUILoadingBarReloadTexture: - return UILoadingBarReloadTexture::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextAtlasTest: - return UITextAtlasTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextBMFontTest: - return UITextBMFontTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextTest: - return UITextTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextTest_LineWrap: - return UITextTest_LineWrap::sceneWithTitle(s_testArray[_currentUISceneId]); - - - case kUILabelTest_Effect: - return UILabelTest_Effect::sceneWithTitle(s_testArray[_currentUISceneId]); - - - case kUITextTest_TTF: - return UITextTest_TTF::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUITextTest_IgnoreConentSize: - return UITextTest_IgnoreConentSize::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUITextFieldTest: - return UITextFieldTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextFieldTest_MaxLength: - return UITextFieldTest_MaxLength::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextFieldTest_Password: - return UITextFieldTest_Password::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextFieldTest_LineWrap: - return UITextFieldTest_LineWrap::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUITextFieldTest_TrueTypeFont: - return UITextFieldTest_TrueTypeFont::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUITextFieldTest_PlaceHolderColor: - return UITextFieldTest_PlaceHolderColor::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUILayoutTest: - return UILayoutTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Color: - return UILayoutTest_Color::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Gradient: - return UILayoutTest_Gradient::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_BackGroundImage: - return UILayoutTest_BackGroundImage::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_BackGroundImage_Scale9: - return UILayoutTest_BackGroundImage_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Linear_Vertical: - return UILayoutTest_Layout_Linear_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Linear_Horizontal: - return UILayoutTest_Layout_Linear_Horizontal::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Relative_Align_Parent: - return UILayoutTest_Layout_Relative_Align_Parent::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Relative_Location: - return UILayoutTest_Layout_Relative_Location::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutComponent_Berth_Test: - return UILayoutComponent_Berth_Test::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutComponent_Berth_Stretch_Test: - return UILayoutComponent_Berth_Stretch_Test::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Vertical: - return UIScrollViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Horizontal: - return UIScrollViewTest_Horizontal::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Both: - return UIScrollViewTest_Both::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_ScrollToPercentBothDirection: - return UIScrollViewTest_ScrollToPercentBothDirection::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_ScrollToPercentBothDirection_Bounce: - return UIScrollViewTest_ScrollToPercentBothDirection_Bounce::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIScrollViewNestTest: - return UIScrollViewNestTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIScrollViewRotated: - return UIScrollViewRotated::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIPageViewTest: - return UIPageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIPageViewButtonTest: - return UIPageViewButtonTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIPageViewCustomScrollThreshold: - return UIPageViewCustomScrollThreshold::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIPageViewTouchPropagationTest: - return UIPageViewTouchPropagationTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIPageViewDynamicAddAndRemoveTest: - return UIPageViewDynamicAddAndRemoveTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIListViewTest_Vertical: - return UIListViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIListViewTest_Horizontal: - return UIListViewTest_Horizontal::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIWidgetAddNodeTest: - return UIWidgetAddNodeTest::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIRichTextTest: - return UIRichTextTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case KUIFocusTest_HBox: - return UIFocusTestHorizontal::sceneWithTitle(s_testArray[_currentUISceneId]); - case KUIFocusTest_VBox: - return UIFocusTestVertical::sceneWithTitle(s_testArray[_currentUISceneId]); - case KUIFocusTest_NestedLayout1: - return UIFocusTestNestedLayout1::sceneWithTitle(s_testArray[_currentUISceneId]); - case KUIFocusTest_NestedLayout2: - return UIFocusTestNestedLayout2::sceneWithTitle(s_testArray[_currentUISceneId]); - case KUIFocusTest_NestedLayout3: - return UIFocusTestNestedLayout3::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIFocusTest_ListView: - return UIFocusTestListView::sceneWithTitle(s_testArray[_currentUISceneId]); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - case kUIVideoPlayerTest: - return VideoPlayerTest::sceneWithTitle(s_testArray[_currentUISceneId]); -#endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - case KWebViewTest: - return WebViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); -#endif - case kUIScale9SpriteTest: - return UIScale9SpriteTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIScale9SpriteHierarchialTest: - return UIScale9SpriteHierarchialTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIScale9SpriteTouchTest: - return UIScale9SpriteTouchTest::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9BatchNodeBasic: - return UIS9BatchNodeBasic::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheet: - return UIS9FrameNameSpriteSheet::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetRotated: - return UIS9FrameNameSpriteSheetRotated::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetCropped: - return UIS9FrameNameSpriteSheetCropped::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetCroppedRotated: - return UIS9FrameNameSpriteSheetCroppedRotated::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9BatchNodeScaledNoInsets: - return UIS9BatchNodeScaledNoInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetScaledNoInsets: - return UIS9FrameNameSpriteSheetScaledNoInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetRotatedScaledNoInsets: - return UIS9FrameNameSpriteSheetRotatedScaledNoInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9BatchNodeScaleWithCapInsets: - return UIS9BatchNodeScaleWithCapInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetInsets: - return UIS9FrameNameSpriteSheetInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetInsetsScaled: - return UIS9FrameNameSpriteSheetInsetsScaled::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetRotatedInsets: - return UIS9FrameNameSpriteSheetRotatedInsets::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9_TexturePacker: - return UIS9_TexturePacker::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetRotatedInsetsScaled: - return UIS9FrameNameSpriteSheetRotatedInsetsScaled::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9FrameNameSpriteSheetRotatedSetCapInsetLater: - return UIS9FrameNameSpriteSheetRotatedSetCapInsetLater::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9CascadeOpacityAndColor: - return UIS9CascadeOpacityAndColor::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9ZOrder: - return UIS9ZOrder::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9Flip: - return UIS9Flip::sceneWithTitle(s_testArray[_currentUISceneId]); - case kUIS9ChangeAnchorPoint: - return UIS9ChangeAnchorPoint::sceneWithTitle(s_testArray[_currentUISceneId]); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - case kUIEditBoxTest: - return UIEditBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]); -#endif - - } - return nullptr; -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 52df15c65d..b1d52e4242 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -25,150 +25,4 @@ #ifndef __TestCpp__UISceneManager__ #define __TestCpp__UISceneManager__ -#include "cocos2d.h" - -USING_NS_CC; - -enum -{ - kUIButtonTest = 0, - kUIButtonTest_Scale9, - kUIButtonTest_Scale9_State_Change, - kUIButtonTest_PressedAction, - kUIButtonTest_Title, - kUIButtonTest_RemoveSelf, - kUIButtonTestSwitchScale9, - kUIButtonTestZoomScale, - kUIButtonTextOnly, - kUIButtonIgnoreContentSizeTest, - kUIButtonTitleEffectTest, - kUIButtonFlipTest, - kUIButtonNormalDefaultTest, - kUIButtonDisableDefaultTest, -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - kUIEditBoxTest, -#endif - kUICheckBoxTest, - kUICheckBoxDefaultBehaviorTest, - kUISliderTest, - kUISliderTest_Scale9, - kUISliderTest_Scale9_State_Change, - kUISliderNormalDefaultTest, - kUISliderDisabledDefaultTest, - kUIImageViewTest, - kUIImageViewTest_Scale9, - kUIImageViewTest_Scale9_State_Change, - kUIImageViewTest_ContentSize, - kUIImageViewFlipTest, - - kUILoadingBarTest_Left, - kUILoadingBarTest_Right, - kUILoadingBarTest_Scale9_State_Change, - kUILoadingBarTest_Left_Scale9, - kUILoadingBarTest_Right_Scale9, - kUILoadingBarReloadTexture, - kUITextAtlasTest, - kUITextTest, - kUITextTest_LineWrap, - kUILabelTest_Effect, - kUITextTest_TTF, - kUITextTest_IgnoreConentSize, - - kUITextBMFontTest, - kUITextFieldTest, - kUITextFieldTest_MaxLength, - kUITextFieldTest_Password, - kUITextFieldTest_LineWrap, - kUITextFieldTest_TrueTypeFont, - kUITextFieldTest_PlaceHolderColor, - kUILayoutTest, - kUILayoutTest_Color, - kUILayoutTest_Gradient, - kUILayoutTest_BackGroundImage, - kUILayoutTest_BackGroundImage_Scale9, - kUILayoutTest_Layout_Linear_Vertical, - kUILayoutTest_Layout_Linear_Horizontal, - kUILayoutTest_Layout_Relative_Align_Parent, - kUILayoutTest_Layout_Relative_Location, - kUILayoutComponent_Berth_Test, - kUILayoutComponent_Berth_Stretch_Test, - kUIScrollViewTest_Vertical, - kUIScrollViewTest_Horizontal, - kUIScrollViewTest_Both, - kUIScrollViewTest_ScrollToPercentBothDirection, - kUIScrollViewTest_ScrollToPercentBothDirection_Bounce, - kUIScrollViewNestTest, - kUIScrollViewRotated, - - kUIPageViewTest, - kUIPageViewButtonTest, - kUIPageViewCustomScrollThreshold, - kUIPageViewTouchPropagationTest, - kUIPageViewDynamicAddAndRemoveTest, - kUIListViewTest_Vertical, - kUIListViewTest_Horizontal, - kUIWidgetAddNodeTest, - kUIRichTextTest, - KUIFocusTest_HBox, - KUIFocusTest_VBox, - KUIFocusTest_NestedLayout1, - KUIFocusTest_NestedLayout2, - KUIFocusTest_NestedLayout3, - kUIFocusTest_ListView, -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - kUIVideoPlayerTest, -#endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - KWebViewTest, -#endif - kUIScale9SpriteTest, - kUIScale9SpriteHierarchialTest, - kUIScale9SpriteTouchTest, - kUIS9BatchNodeBasic, - kUIS9FrameNameSpriteSheet, - kUIS9FrameNameSpriteSheetRotated, - kUIS9FrameNameSpriteSheetCropped, - kUIS9FrameNameSpriteSheetCroppedRotated, - kUIS9BatchNodeScaledNoInsets, - kUIS9FrameNameSpriteSheetScaledNoInsets, - kUIS9FrameNameSpriteSheetRotatedScaledNoInsets, - kUIS9BatchNodeScaleWithCapInsets, - kUIS9FrameNameSpriteSheetInsets, - kUIS9FrameNameSpriteSheetInsetsScaled, - kUIS9FrameNameSpriteSheetRotatedInsets, - kUIS9_TexturePacker, - kUIS9FrameNameSpriteSheetRotatedInsetsScaled, - kUIS9FrameNameSpriteSheetRotatedSetCapInsetLater, - kUIS9CascadeOpacityAndColor, - kUIS9ZOrder, - kUIS9Flip, - kUIS9ChangeAnchorPoint, - kUITestMax -}; - -class UISceneManager : public Ref -{ -public: - UISceneManager(); - ~UISceneManager(); - /** Returns the singleton of the ui scene manager. */ - static UISceneManager * sharedUISceneManager(); - static void purgeUISceneManager(); - - /** Returns the next ui scene. */ - cocos2d::Scene *nextUIScene(); - - /** Returns the previous ui scene. */ - cocos2d::Scene *previousUIScene(); - - /** Returns the current control scene. */ - cocos2d::Scene *currentUIScene(); - - /** UI scene id. */ - CC_SYNTHESIZE(int, _currentUISceneId, CurrentUISceneId) - - CC_SYNTHESIZE(int, _minUISceneId, MinUISceneId) - CC_SYNTHESIZE(int, _maxUISceneId, MaxUISceneId) -}; - #endif /* defined(__TestCpp__UISceneManager__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp index b0106a96c3..e69de29bb2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.cpp @@ -1,194 +0,0 @@ - - -#include "UISceneManager_Editor.h" -#include "UIButtonTest/UIButtonTest_Editor.h" -#include "UICheckBoxTest/UICheckBoxTest_Editor.h" -#include "UIImageViewTest/UIImageViewTest_Editor.h" -#include "UITextAtlasTest/UITextAtlasTest_Editor.h" -#include "UITextBMFontTest/UITextBMFontTest_Editor.h" -#include "UITextTest/UITextTest_Editor.h" -#include "UILoadingBarTest/UILoadingBarTest_Editor.h" -#include "UISliderTest/UISliderTest_Editor.h" -#include "UITextFieldTest/UITextFieldTest_Editor.h" -#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h" -#include "UILayoutTest/UILayoutTest_Editor.h" -#include "UIListViewTest/UIListViewTest_Editor.h" -#include "UIPageViewTest/UIPageViewTest_Editor.h" -#include "UIScrollViewTest/UIScrollViewTest_Editor.h" - - -USING_NS_CC; - -static const char* s_testArray[] = -{ - "UIButtonTest_Editor", - "UICheckBoxTest_Editor", - "UIImageViewTest_Editor", - "UITextAtlasTest_Editor", - "UITextBMFontTest_Editor", - "UITextTest_Editor", - "UILoadingBarTest_Editor", - "UISliderTest_Editor", - "UITextFieldTest_Editor", - "UIWidgetAddNodeTest_Editor", - "UILayoutTest_Editor", - "UILayoutTest_Color_Editor", - "UILayoutTest_Gradient_Editor", - "UILayoutTest_BackGroundImage_Editor", - "UILayoutTest_BackGroundImage_Scale9_Editor", - "UILayoutComponentTest_Editor", - - /* - "UILayoutTest_Layout_Linear_Vertical_Editor", - "UILayoutTest_Layout_Linear_Horizontal_Editor", - "UILayoutTest_Layout_Relative_Align_Parent_Editor", - "UILayoutTest_Layout_Relative_Location_Editor", - */ - - "UIListViewTest_Vertical_Editor", - "UIListViewTest_Horizontal_Editor", - "UIPageViewTest_Editor", - "UIScrollViewTest_Vertical_Editor", - "UIScrollViewTest_Horizontal_Editor", - "UIScrollViewTest_Both_Editor", -}; - -static UISceneManager_Editor* sharedInstance = nullptr; - -UISceneManager_Editor::UISceneManager_Editor() -{ - _currentUISceneId = kUIButtonTest_Editor; -} - -UISceneManager_Editor::~UISceneManager_Editor() -{ - -} - -UISceneManager_Editor* UISceneManager_Editor::sharedUISceneManager_Editor() -{ - if (sharedInstance == nullptr) - { - sharedInstance = new (std::nothrow) UISceneManager_Editor(); - } - return sharedInstance; -} - -void UISceneManager_Editor::purge() -{ - CC_SAFE_DELETE(sharedInstance); -} - -Scene* UISceneManager_Editor::nextUIScene() -{ - _currentUISceneId = _currentUISceneId + 1; - if (_currentUISceneId > _maxUISceneId) - { - _currentUISceneId = _minUISceneId; - } - - return currentUIScene(); -} - -Scene* UISceneManager_Editor::previousUIScene() -{ - _currentUISceneId = _currentUISceneId - 1; - if (_currentUISceneId < _minUISceneId) - { - _currentUISceneId = _maxUISceneId; - } - - return currentUIScene(); -} - -Scene* UISceneManager_Editor::currentUIScene() -{ - switch (_currentUISceneId) - { - case kUIButtonTest_Editor: - return UIButtonTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - break; - - case kUICheckBoxTest_Editor: - return UICheckBoxTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - break; - - case kUIImageViewTest_Editor: - return UIImageViewTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextAtlasTest_Editor: - return UITextAtlasTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextBMFontTest_Editor: - return UITextBMFontTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextTest_Editor: - return UITextTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILoadingBarTest_Editor: - return UILoadingBarTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUISliderTest_Editor: - return UISliderTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUITextFieldTest_Editor: - return UITextFieldTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIWidgetAddNodeTest_Editor: - return UIWidgetAddNodeTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Editor: - return UILayoutTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Color_Editor: - return UILayoutTest_Color_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Gradient_Editor: - return UILayoutTest_Gradient_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_BackGroundImage_Editor: - return UILayoutTest_BackGroundImage_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_BackGroundImage_Scale9_Editor: - return UILayoutTest_BackGroundImage_Scale9_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutComponentTest_Editor: - return UILayoutComponentTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - /* - case kUILayoutTest_Layout_Linear_Vertical_Editor: - return UILayoutTest_Layout_Linear_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Linear_Horizontal_Editor: - return UILayoutTest_Layout_Linear_Horizontal_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Relative_Align_Parent_Editor: - return UILayoutTest_Layout_Relative_Align_Parent_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUILayoutTest_Layout_Relative_Location_Editor: - return UILayoutTest_Layout_Relative_Location_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - */ - - case kUIListViewTest_Vertical_Editor: - return UIListViewTest_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIListViewTest_Horizontal_Editor: - return UIListViewTest_Horizontal_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIPageViewTest_Editor: - return UIPageViewTest_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Vertical_Editor: - return UIScrollViewTest_Vertical_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Horizontal_Editor: - return UIScrollViewTest_Horizontal_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - case kUIScrollViewTest_Both_Editor: - return UIScrollViewTest_Both_Editor::sceneWithTitle(s_testArray[_currentUISceneId]); - - default: - break; - } - - return nullptr; -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h index a754cc2e2b..6a82ca72e5 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager_Editor.h @@ -25,69 +25,4 @@ #ifndef __TestCpp__UISceneManager_Editor__ #define __TestCpp__UISceneManager_Editor__ -#include "cocos2d.h" - -USING_NS_CC; - -enum -{ - kUIButtonTest_Editor = 0, - kUICheckBoxTest_Editor, - kUIImageViewTest_Editor, - kUITextAtlasTest_Editor, - kUITextBMFontTest_Editor, - kUITextTest_Editor, - kUILoadingBarTest_Editor, - kUISliderTest_Editor, - kUITextFieldTest_Editor, - kUIWidgetAddNodeTest_Editor, - kUILayoutTest_Editor, - kUILayoutTest_Color_Editor, - kUILayoutTest_Gradient_Editor, - kUILayoutTest_BackGroundImage_Editor, - kUILayoutTest_BackGroundImage_Scale9_Editor, - kUILayoutComponentTest_Editor, - - /* - kUILayoutTest_Layout_Linear_Vertical_Editor, - kUILayoutTest_Layout_Linear_Horizontal_Editor, - kUILayoutTest_Layout_Relative_Align_Parent_Editor, - kUILayoutTest_Layout_Relative_Location_Editor, - */ - - kUIListViewTest_Vertical_Editor, - kUIListViewTest_Horizontal_Editor, - kUIPageViewTest_Editor, - kUIScrollViewTest_Vertical_Editor, - kUIScrollViewTest_Horizontal_Editor, - kUIScrollViewTest_Both_Editor, - kUITestMax_Editor, -}; - -class UISceneManager_Editor : public Ref -{ -public: - UISceneManager_Editor(); - ~UISceneManager_Editor(); - - /** Returns the singleton of the ui scene manager. */ - static UISceneManager_Editor* sharedUISceneManager_Editor(); - static void purge(); - - /** Returns the next ui scene. */ - virtual Scene* nextUIScene(); - - /** Returns the previous ui scene. */ - virtual Scene* previousUIScene(); - - /** Returns the current control scene. */ - virtual Scene* currentUIScene(); - - /** UI scene id. */ - CC_SYNTHESIZE(int, _currentUISceneId, CurrentUISceneId) - - CC_SYNTHESIZE(int, _minUISceneId, MinUISceneId) - CC_SYNTHESIZE(int, _maxUISceneId, MaxUISceneId) -}; - #endif /* defined(__TestCpp__UISceneManager_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp index 8f0dcb94e6..5c80565ece 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp @@ -1,5 +1,3 @@ - - #include "UIScene_Editor.h" #include "GUIEditorTest.h" #include "ui/CocosGUI.h" @@ -7,9 +5,9 @@ UIScene_Editor::UIScene_Editor() -: _sceneTitle(nullptr) -, _touchGroup(nullptr) +: _touchGroup(nullptr) , _layout(nullptr) +, _sceneTitle(nullptr) { } @@ -19,49 +17,12 @@ UIScene_Editor::~UIScene_Editor() } -void UIScene_Editor::onExit() -{ - cocostudio::destroyCocosStudio(); - - Layer::onExit(); -} - bool UIScene_Editor::init() { - if (CCLayer::init()) + if (TestCase::init()) { _touchGroup = Layer::create(); - addChild(_touchGroup); - - //add switch - MenuItem* pLoadJsonItem = MenuItemFont::create("Switch to Windows Json Load"); - MenuItem* pLoadBinaryItem = MenuItemFont::create("Switch to Windows Binary Load"); - MenuItem* pLoadJsonItemCrossPlatForm = MenuItemFont::create("Switch to Cross PlatForm Json Load"); - MenuItem* pLoadBinaryItemCrossPlatForm = MenuItemFont::create("Switch to Cross PlatForm Binary Load"); - - pLoadJsonItem->setTag(1); - pLoadBinaryItem->setTag(2); - pLoadJsonItemCrossPlatForm->setTag(3); - pLoadBinaryItemCrossPlatForm->setTag(4); - - - Vector array;; - array.pushBack(pLoadBinaryItem); - array.pushBack(pLoadJsonItemCrossPlatForm); - array.pushBack(pLoadBinaryItemCrossPlatForm); - array.pushBack(pLoadJsonItem); - - MenuItemToggle *pToggleItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(UIScene_Editor::switchLoadMethod,this), array); - - pToggleItem->setTag(1); - - MenuItem* selectedItem = pToggleItem->getSelectedItem(); - pToggleItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y - selectedItem->getContentSize().height * 3.75f)); - - Menu* pMenu =Menu::create(pToggleItem, nullptr); - pMenu->setPosition( Vec2::ZERO ); - -// addChild(pMenu, 1, 1); + addChild(_touchGroup); return true; } @@ -69,52 +30,36 @@ bool UIScene_Editor::init() return false; } -void UIScene_Editor::switchLoadMethod(cocos2d::Ref *pSender) +void UIScene_Editor::onEnter() { - //subclass should override this method -} + TestCase::onEnter(); -void UIScene_Editor::previousCallback(Ref* sender, Widget::TouchEventType event) -{ - switch (event) + if (_sceneTitle) { - case Widget::TouchEventType::ENDED: - CCDirector::getInstance()->replaceScene(UISceneManager_Editor::sharedUISceneManager_Editor()->previousUIScene()); - break; - - default: - break; + _sceneTitle->setString(getTestCaseName()); } } -void UIScene_Editor::nextCallback(Ref* sender, Widget::TouchEventType event) +void UIScene_Editor::onExit() { - switch (event) - { - case Widget::TouchEventType::ENDED: - CCDirector::getInstance()->replaceScene(UISceneManager_Editor::sharedUISceneManager_Editor()->nextUIScene()); - break; - - default: - break; - } + cocostudio::destroyCocosStudio(); + + TestCase::onExit(); } -void UIScene_Editor::toGUIEditorTestScene(Ref* sender, Widget::TouchEventType event) +void UIScene_Editor::configureGUIScene() { - switch (event) + if (_touchGroup) { - case Widget::TouchEventType::ENDED: - { - UISceneManager_Editor::sharedUISceneManager_Editor()->purge(); - - GUIEditorTestScene* pScene = new (std::nothrow) GUIEditorTestScene(); - pScene->runThisTest(); - pScene->release(); - } - break; - - default: - break; + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); } -} + + if (_layout) + { + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + } +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h index a650d5f1e7..939dc8dd0a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h @@ -29,53 +29,27 @@ #include "extensions/cocos-ext.h" #include "ui/CocosGUI.h" #include "cocostudio/CocoStudio.h" +#include "BaseTest.h" USING_NS_CC; USING_NS_CC_EXT; using namespace ui; -#define UI_SCENE_EDITOR_CREATE_FUNC(UIScene_Editor) \ -public: \ -static Scene* sceneWithTitle(const char * title) \ -{ \ - Scene* pScene = Scene::create(); \ - UIScene_Editor* uiLayer = new (std::nothrow) UIScene_Editor(); \ - if (uiLayer && uiLayer->init()) \ - { \ - uiLayer->autorelease(); \ - uiLayer->getSceneTitle()->setString(title); \ - pScene->addChild(uiLayer); \ - } \ - else \ - { \ - CC_SAFE_DELETE(uiLayer); \ - } \ - return pScene; \ -} - -class UIScene_Editor : public Layer +class UIScene_Editor : public TestCase { public: UIScene_Editor(); ~UIScene_Editor(); + virtual bool init() override; + virtual void onEnter() override; virtual void onExit() override; - - bool init(); - virtual void previousCallback(Ref* sender, Widget::TouchEventType event); - virtual void nextCallback(Ref* sender, Widget::TouchEventType event); - - void toGUIEditorTestScene(Ref* sender, Widget::TouchEventType event); - - /** Title label of the scene.*/ - CC_SYNTHESIZE_READONLY(Text*, _sceneTitle, SceneTitle) - - UI_SCENE_EDITOR_CREATE_FUNC(UIScene_Editor); - virtual void switchLoadMethod(Ref* pSender); + virtual void configureGUIScene(); protected: Layer* _touchGroup; Layout* _layout; + Text* _sceneTitle; }; #endif /* defined(__TestCpp__UIScene_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 1c57acae30..1afc066159 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -1,8 +1,15 @@ - - #include "UIScrollViewTest.h" - +UIScrollViewTests::UIScrollViewTests() +{ + ADD_TEST_CASE(UIScrollViewTest_Vertical); + ADD_TEST_CASE(UIScrollViewTest_Horizontal); + ADD_TEST_CASE(UIScrollViewTest_Both); + ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection); + ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection_Bounce); + ADD_TEST_CASE(UIScrollViewNestTest); + ADD_TEST_CASE(UIScrollViewRotated); +} // UIScrollViewTest_Vertical UIScrollViewTest_Vertical::UIScrollViewTest_Vertical() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.h index 766a11002b..9436de66d4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.h @@ -27,87 +27,103 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIScrollViewTests); + class UIScrollViewTest_Vertical : public UIScene { public: + CREATE_FUNC(UIScrollViewTest_Vertical); + UIScrollViewTest_Vertical(); ~UIScrollViewTest_Vertical(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewTest_Vertical) + Text* _displayValueLabel; }; class UIScrollViewTest_Horizontal : public UIScene { public: + CREATE_FUNC(UIScrollViewTest_Horizontal); + UIScrollViewTest_Horizontal(); ~UIScrollViewTest_Horizontal(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewTest_Horizontal) + Text* _displayValueLabel; }; class UIScrollViewTest_Both : public UIScene { public: + CREATE_FUNC(UIScrollViewTest_Both); + UIScrollViewTest_Both(); ~UIScrollViewTest_Both(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewTest_Both) + Text* _displayValueLabel; }; class UIScrollViewTest_ScrollToPercentBothDirection : public UIScene { public: + CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection); + UIScrollViewTest_ScrollToPercentBothDirection(); ~UIScrollViewTest_ScrollToPercentBothDirection(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection) + Text* _displayValueLabel; }; class UIScrollViewTest_ScrollToPercentBothDirection_Bounce : public UIScene { public: + CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Bounce); + UIScrollViewTest_ScrollToPercentBothDirection_Bounce(); ~UIScrollViewTest_ScrollToPercentBothDirection_Bounce(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Bounce) + Text* _displayValueLabel; }; class UIScrollViewNestTest : public UIScene { public: + CREATE_FUNC(UIScrollViewNestTest); + UIScrollViewNestTest(); ~UIScrollViewNestTest(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewNestTest) + Text* _displayValueLabel; }; class UIScrollViewRotated : public UIScene { public: + CREATE_FUNC(UIScrollViewRotated); + UIScrollViewRotated(); ~UIScrollViewRotated(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UIScrollViewRotated) + Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp index 38d8fdf0ed..c6ddbd5568 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp @@ -1,8 +1,14 @@ - - #include "UIScrollViewTest_Editor.h" #include "VisibleRect.h" +UIScrollViewEditorTests::UIScrollViewEditorTests() +{ + ADD_TEST_CASE(UIScrollViewTest_Vertical_Editor); + ADD_TEST_CASE(UIScrollViewTest_Horizontal_Editor); + ADD_TEST_CASE(UIScrollViewTest_Both_Editor); + ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection_Editor); + ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor); +} // UIScrollViewTest_Vertical_Editor @@ -16,107 +22,6 @@ UIScrollViewTest_Vertical_Editor::~UIScrollViewTest_Vertical_Editor() } -void UIScrollViewTest_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView/Vertical/windows_ui_scrollview_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView/Vertical/windows_ui_scrollview_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Vertical/crossplatform_UIScrollView_Vertical_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Vertical/crossplatform_UIScrollView_Vertical_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIScrollViewTest_Vertical_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - -} - bool UIScrollViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) @@ -129,13 +34,6 @@ bool UIScrollViewTest_Vertical_Editor::init() this->configureGUIScene(); - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - return true; } @@ -153,108 +51,6 @@ UIScrollViewTest_Horizontal_Editor::UIScrollViewTest_Horizontal_Editor() UIScrollViewTest_Horizontal_Editor::~UIScrollViewTest_Horizontal_Editor() { -} - -void UIScrollViewTest_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView/Horizontal/windows_ui_scrollview_horizontal_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView/Horizontal/windows_ui_scrollview_horizontal_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Horizontal/crossplatform_UIScrollView_Horizontal_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Horizontal/crossplatform_UIScrollView_Horizontal_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIScrollViewTest_Horizontal_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - - } bool UIScrollViewTest_Horizontal_Editor::init() @@ -268,14 +64,7 @@ bool UIScrollViewTest_Horizontal_Editor::init() _touchGroup->addChild(_layout); this->configureGUIScene(); - - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - + return true; } @@ -295,106 +84,6 @@ UIScrollViewTest_Both_Editor::~UIScrollViewTest_Both_Editor() } -void UIScrollViewTest_Both_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView/Both/windows_ui_scrollview_both_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView/Both/windows_ui_scrollview_both_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Both/crossplatform_UIScrollView_Both_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIScrollView/Both/crossplatform_UIScrollView_Both_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UIScrollViewTest_Both_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); -} - bool UIScrollViewTest_Both_Editor::init() { if (UIScene_Editor::init()) @@ -406,14 +95,7 @@ bool UIScrollViewTest_Both_Editor::init() _touchGroup->addChild(_layout); this->configureGUIScene(); - - /* - Menu* menu = static_cast(getChildByTag(1)); - MenuItemToggle* menuItemToggle = static_cast(menu->getChildByTag(1)); - MenuItem* selectedItem = menuItemToggle->getSelectedItem(); - menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 3.75f)); - */ - + return true; } @@ -438,30 +120,12 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UITest/UITest.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getContentSize(); _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = static_cast(Helper::seekWidgetByName(root, "left_Button")); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - - Button* middle_button = static_cast(Helper::seekWidgetByName(root, "middle_Button")); - middle_button->setVisible(false); - - Button* right_button = static_cast(Helper::seekWidgetByName(root, "right_Button")); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - return true; } @@ -485,30 +149,12 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UITest/UITest.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getContentSize(); _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = static_cast(Helper::seekWidgetByName(root, "left_Button")); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - - Button* middle_button = static_cast(Helper::seekWidgetByName(root, "middle_Button")); - middle_button->setVisible(false); - - Button* right_button = static_cast(Helper::seekWidgetByName(root, "right_Button")); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h index 627d5df685..940148d296 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h @@ -27,16 +27,18 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UIScrollViewEditorTests); + class UIScrollViewTest_Vertical_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIScrollViewTest_Vertical_Editor); + UIScrollViewTest_Vertical_Editor(); ~UIScrollViewTest_Vertical_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Vertical_Editor) Text* _displayValueLabel; }; @@ -44,13 +46,13 @@ protected: class UIScrollViewTest_Horizontal_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIScrollViewTest_Horizontal_Editor); + UIScrollViewTest_Horizontal_Editor(); ~UIScrollViewTest_Horizontal_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Horizontal_Editor) Text* _displayValueLabel; }; @@ -58,13 +60,13 @@ protected: class UIScrollViewTest_Both_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIScrollViewTest_Both_Editor); + UIScrollViewTest_Both_Editor(); ~UIScrollViewTest_Both_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Both_Editor) Text* _displayValueLabel; }; @@ -72,12 +74,14 @@ protected: class UIScrollViewTest_ScrollToPercentBothDirection_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Editor); + UIScrollViewTest_ScrollToPercentBothDirection_Editor(); ~UIScrollViewTest_ScrollToPercentBothDirection_Editor(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Editor) Text* _displayValueLabel; }; @@ -85,12 +89,14 @@ protected: class UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor); + UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor(); ~UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor(); - bool init(); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index 7ba93aea87..ccb43ac3da 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -1,7 +1,13 @@ - - #include "UISliderTest.h" +UISliderTests::UISliderTests() +{ + ADD_TEST_CASE(UISliderTest); + ADD_TEST_CASE(UISliderTest_Scale9); + ADD_TEST_CASE(UISliderTest_Scale9_State_Change); + ADD_TEST_CASE(UISliderNormalDefaultTest); + ADD_TEST_CASE(UISliderDisabledDefaultTest); +} // UISliderTest diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h index 0d9f4865c5..ce08319aa2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h @@ -27,67 +27,74 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UISliderTests); + class UISliderTest : public UIScene { public: + CREATE_FUNC(UISliderTest); + UISliderTest(); ~UISliderTest(); - bool init(); + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); protected: - UI_SCENE_CREATE_FUNC(UISliderTest) Text* _displayValueLabel; }; class UISliderTest_Scale9 : public UIScene { public: + CREATE_FUNC(UISliderTest_Scale9); + UISliderTest_Scale9(); ~UISliderTest_Scale9(); - bool init(); + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); protected: - UI_SCENE_CREATE_FUNC(UISliderTest_Scale9) Text* _displayValueLabel; }; class UISliderTest_Scale9_State_Change : public UIScene { public: + CREATE_FUNC(UISliderTest_Scale9_State_Change); + UISliderTest_Scale9_State_Change(); ~UISliderTest_Scale9_State_Change(); - bool init(); + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); protected: - UI_SCENE_CREATE_FUNC(UISliderTest_Scale9_State_Change) - Text* _displayValueLabel; + Text* _displayValueLabel; }; class UISliderNormalDefaultTest : public UIScene { public: + CREATE_FUNC(UISliderNormalDefaultTest); + UISliderNormalDefaultTest(); ~UISliderNormalDefaultTest(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UISliderNormalDefaultTest) Text* _displayValueLabel; }; class UISliderDisabledDefaultTest : public UIScene { public: + CREATE_FUNC(UISliderDisabledDefaultTest); + UISliderDisabledDefaultTest(); ~UISliderDisabledDefaultTest(); - bool init(); + virtual bool init() override; protected: - UI_SCENE_CREATE_FUNC(UISliderDisabledDefaultTest) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp index ea07f70408..2d41345626 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp @@ -1,8 +1,9 @@ - - #include "UISliderTest_Editor.h" - +UISliderEditorTests::UISliderEditorTests() +{ + ADD_TEST_CASE(UISliderTest_Editor); +} // UISliderTest_Editor UISliderTest_Editor::UISliderTest_Editor() @@ -16,88 +17,12 @@ UISliderTest_Editor::~UISliderTest_Editor() } -void UISliderTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider/windows_ui_slider_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UISlider/windows_ui_slider_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UISlider/crossplatform_UISlider_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UISlider/crossplatform_UISlider_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UISliderTest_Editor::configureGUIScene() { - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); + UIScene_Editor::configureGUIScene(); Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - + Slider* slider = static_cast(Helper::seekWidgetByName(root, "Slider_738")); slider->addEventListener(CC_CALLBACK_2(UISliderTest_Editor::sliderEvent, this)); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h index ff7dc3ec40..a2e805ef66 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h @@ -5,18 +5,21 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UISliderEditorTests); + class UISliderTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UISliderTest_Editor); + UISliderTest_Editor(); ~UISliderTest_Editor(); - bool init(); + + virtual bool init() override; void sliderEvent(Ref* pSender, Slider::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + virtual void configureGUIScene() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UISliderTest_Editor) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp index f30001b2f4..fd92ccd8c8 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp @@ -1,8 +1,9 @@ - - #include "UITextAtlasTest.h" - +UITextAtlasTests::UITextAtlasTests() +{ + ADD_TEST_CASE(UITextAtlasTest); +} // UITextAtlasTest bool UITextAtlasTest::init() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.h index b96ae3aeba..2eef8b80c0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.h @@ -5,13 +5,14 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UITextAtlasTests); + class UITextAtlasTest : public UIScene { -public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UITextAtlasTest) +public: + CREATE_FUNC(UITextAtlasTest); + + virtual bool init() override; }; #endif /* defined(__TestCpp__UITextAtlasTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp index 26b37b4359..ad9bf7df87 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp @@ -1,88 +1,8 @@ - - #include "UITextAtlasTest_Editor.h" -// UITextAtlasTest_Editor -void UITextAtlasTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +UITextAtlasEditorTests::UITextAtlasEditorTests() { - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas/windows_ui_labelatlas_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelAtlas/windows_ui_labelatlas_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabelAtlas/crossplatform_UILabelAtlas_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabelAtlas/crossplatform_UILabelAtlas_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UITextAtlasTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + ADD_TEST_CASE(UITextAtlasTest_Editor); } bool UITextAtlasTest_Editor::init() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h index e0a170acec..ae3a809023 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h @@ -27,14 +27,14 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UITextAtlasEditorTests); + class UITextAtlasTest_Editor : public UIScene_Editor { public: - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UITextAtlasTest_Editor) + CREATE_FUNC(UITextAtlasTest_Editor); + + virtual bool init() override; }; #endif /* defined(__TestCpp__UITextAtlasTest_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp index 1769523560..aa38ef015b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp @@ -1,8 +1,9 @@ - - #include "UITextBMFontTest.h" - +UITextBMFontTests::UITextBMFontTests() +{ + ADD_TEST_CASE(UITextBMFontTest); +} // UITextBMFontTest bool UITextBMFontTest::init() diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h index c4e2fc53fb..c3a228a695 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h @@ -27,13 +27,14 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UITextBMFontTests); + class UITextBMFontTest : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UITextBMFontTest) + CREATE_FUNC(UITextBMFontTest) + + virtual bool init() override; }; #endif /* defined(__TestCpp__UITextBMFontTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp index 5c472985a6..888d3f03c4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp @@ -1,90 +1,11 @@ - - #include "UITextBMFontTest_Editor.h" +UITextBMFontEditorTest::UITextBMFontEditorTest() +{ + ADD_TEST_CASE(UITextBMFontTest_Editor); +} // UITextBMFontTest_Editor -void UITextBMFontTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont/windows_ui_labelbmfont_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelBMFont/windows_ui_labelbmfont_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabelBMFont/crossplatform_UILabelBMFont_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabelBMFont/crossplatform_UILabelBMFont_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UITextBMFontTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); -} bool UITextBMFontTest_Editor::init() { diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h index 8ff7eccdab..c3ae1887e6 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h @@ -27,14 +27,14 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UITextBMFontEditorTest); class UITextBMFontTest_Editor : public UIScene_Editor { public: - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + CREATE_FUNC(UITextBMFontTest_Editor); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UITextBMFontTest_Editor) }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index ac030cc8d0..ef8d14fc79 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -1,7 +1,15 @@ - - #include "UITextFieldTest.h" +UITextFieldTests::UITextFieldTests() +{ + ADD_TEST_CASE(UITextFieldTest); + ADD_TEST_CASE(UITextFieldTest_MaxLength); + ADD_TEST_CASE(UITextFieldTest_Password); + ADD_TEST_CASE(UITextFieldTest_LineWrap); + ADD_TEST_CASE(UITextFieldTest_TrueTypeFont); + ADD_TEST_CASE(UITextFieldTest_PlaceHolderColor); +} + // UITextFieldTest UITextFieldTest::UITextFieldTest() : _displayValueLabel(nullptr) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h index 6c62bc14d2..fcaf7fa6d4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h @@ -27,81 +27,95 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UITextFieldTests); + class UITextFieldTest : public UIScene { public: + CREATE_FUNC(UITextFieldTest); + UITextFieldTest(); ~UITextFieldTest(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, ui::TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest) + Text* _displayValueLabel; }; class UITextFieldTest_MaxLength : public UIScene { public: + CREATE_FUNC(UITextFieldTest_MaxLength); + UITextFieldTest_MaxLength(); ~UITextFieldTest_MaxLength(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest_MaxLength) + Text* _displayValueLabel; }; class UITextFieldTest_Password : public UIScene { public: + CREATE_FUNC(UITextFieldTest_Password); + UITextFieldTest_Password(); ~UITextFieldTest_Password(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest_Password) + Text* _displayValueLabel; }; class UITextFieldTest_LineWrap : public UIScene { public: + CREATE_FUNC(UITextFieldTest_LineWrap); + UITextFieldTest_LineWrap(); ~UITextFieldTest_LineWrap(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest_LineWrap) + Text* _displayValueLabel; }; class UITextFieldTest_TrueTypeFont : public UIScene { public: + CREATE_FUNC(UITextFieldTest_TrueTypeFont); + UITextFieldTest_TrueTypeFont(); ~UITextFieldTest_TrueTypeFont(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest_TrueTypeFont) + Text* _displayValueLabel; }; class UITextFieldTest_PlaceHolderColor : public UIScene { public: + CREATE_FUNC(UITextFieldTest_PlaceHolderColor); + UITextFieldTest_PlaceHolderColor(); ~UITextFieldTest_PlaceHolderColor(); - bool init(); + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); protected: - UI_SCENE_CREATE_FUNC(UITextFieldTest_PlaceHolderColor) + Text* _displayValueLabel; }; #endif /* defined(__TestCpp__UITextFieldTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp index 834902c484..da8877a417 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp @@ -1,8 +1,9 @@ - - #include "UITextFieldTest_Editor.h" - +UITextFieldEditorTests::UITextFieldEditorTests() +{ + ADD_TEST_CASE(UITextFieldTest_Editor); +} // UITextFieldTest_Editor UITextFieldTest_Editor::UITextFieldTest_Editor() @@ -16,87 +17,9 @@ UITextFieldTest_Editor::~UITextFieldTest_Editor() } -void UITextFieldTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField/windows_ui_textfield_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UITextField/windows_ui_textfield_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UITextField/crossplatform_UITextField_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UITextField/crossplatform_UITextField_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UITextFieldTest_Editor::configureGUIScene() { - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - TextField* textField_normal = static_cast(Helper::seekWidgetByName(root, "TextField_1109")); textField_normal->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h index 1621d68d10..8393f7b690 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h @@ -27,17 +27,20 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UITextFieldEditorTests); + class UITextFieldTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UITextFieldTest_Editor); + UITextFieldTest_Editor(); ~UITextFieldTest_Editor(); - bool init(); + + virtual bool init() override; void textFieldEvent(Ref* pSender, TextField::EventType type); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + virtual void configureGUIScene() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UITextFieldTest_Editor) Text* _displayValueLabel; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp index 68934c79ba..14e8118b81 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -1,7 +1,13 @@ - - #include "UITextTest.h" +UITextTests::UITextTests() +{ + ADD_TEST_CASE(UITextTest); + ADD_TEST_CASE(UITextTest_LineWrap); + ADD_TEST_CASE(UILabelTest_Effect); + ADD_TEST_CASE(UITextTest_TTF); + ADD_TEST_CASE(UITextTest_IgnoreConentSize); +} // UITextTest diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.h index 9b7f2fb3c8..081b4ab94e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.h @@ -27,50 +27,48 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UITextTests); + class UITextTest : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UITextTest) + CREATE_FUNC(UITextTest); + + virtual bool init() override; }; class UITextTest_LineWrap : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UITextTest_LineWrap) + CREATE_FUNC(UITextTest_LineWrap); + + virtual bool init() override; }; class UILabelTest_Effect : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UILabelTest_Effect) + CREATE_FUNC(UILabelTest_Effect); + + virtual bool init() override; }; class UITextTest_TTF : public UIScene { public: - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UITextTest_TTF) + CREATE_FUNC(UITextTest_TTF); + + virtual bool init() override; }; class UITextTest_IgnoreConentSize : public UIScene { public: - bool init(); -protected: - UI_SCENE_CREATE_FUNC(UITextTest_IgnoreConentSize) + CREATE_FUNC(UITextTest_IgnoreConentSize); + + virtual bool init() override; }; #endif /* defined(__TestCpp__UITextTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp index cefea36a2f..f731aa2d24 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp @@ -1,95 +1,13 @@ - - #include "UITextTest_Editor.h" #include "ui/CocosGUI.h" - +UITextEditorTests::UITextEditorTests() +{ + ADD_TEST_CASE(UITextTest_Editor); +} // UITextTest_Editor using namespace ui; -void UITextTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel/windows_ui_label_editor_1.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabel/windows_ui_label_editor_1.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabel/crossplatform_UILabel_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UILabel/crossplatform_UILabel_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - -void UITextTest_Editor::configureGUIScene() -{ - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - -} - bool UITextTest_Editor::init() { if (UIScene_Editor::init()) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h index 54c83d2315..9a71e2d5e5 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h @@ -27,14 +27,14 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UITextEditorTests); class UITextTest_Editor : public UIScene_Editor { public: - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); + CREATE_FUNC(UITextTest_Editor); + + virtual bool init() override; protected: - UI_SCENE_EDITOR_CREATE_FUNC(UITextTest_Editor) }; #endif /* defined(__TestCpp__UILabelTest_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 33ec256f67..6d08dd19ca 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -3,6 +3,11 @@ USING_NS_CC; using namespace cocos2d::experimental::ui; +VideoPlayerTests::VideoPlayerTests() +{ + ADD_TEST_CASE(VideoPlayerTest); +} + bool VideoPlayerTest::init() { if ( !UIScene::init() ) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h index fb97f017ba..5eac79a57f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h @@ -5,10 +5,12 @@ USING_NS_CC; +DEFINE_TEST_SUITE(VideoPlayerTests); + class VideoPlayerTest : public UIScene { public: - UI_SCENE_CREATE_FUNC(VideoPlayerTest); + CREATE_FUNC(VideoPlayerTest); virtual bool init() override; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp index e8d3e834a1..55991964fd 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp @@ -24,14 +24,9 @@ #include "UIWebViewTest.h" -WebViewTest::WebViewTest() +WebViewTests::WebViewTests() { - -} - -WebViewTest::~WebViewTest() -{ - + ADD_TEST_CASE(WebViewTest); } bool WebViewTest::init() @@ -160,12 +155,10 @@ bool WebViewTest::onWebViewShouldStartLoading(experimental::ui::WebView *sender, void WebViewTest::onWebViewDidFinishLoading(experimental::ui::WebView *sender, const std::string &url) { CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str()); - } void WebViewTest::onWebViewDidFailLoading(experimental::ui::WebView *sender, const std::string &url) { CCLOG("onWebViewDidFailLoading, url is %s", url.c_str()); - } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h index e1b67da06b..472ebe0194 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h @@ -29,12 +29,12 @@ USING_NS_CC; +DEFINE_TEST_SUITE(WebViewTests); + class WebViewTest : public UIScene { public: - WebViewTest(); - virtual ~WebViewTest(); - UI_SCENE_CREATE_FUNC(WebViewTest); + CREATE_FUNC(WebViewTest); virtual bool init() override; bool onWebViewShouldStartLoading(experimental::ui::WebView *sender, const std::string &url); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp index 3774666c37..06af710ea1 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp @@ -1,7 +1,9 @@ - - #include "UIWidgetAddNodeTest.h" +UIWidgetAddNodeTests::UIWidgetAddNodeTests() +{ + ADD_TEST_CASE(UIWidgetAddNodeTest); +} // UIWidgetAddNodeTest diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.h index 354c160918..930b69ebcc 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.h @@ -27,15 +27,17 @@ #include "../UIScene.h" +DEFINE_TEST_SUITE(UIWidgetAddNodeTests); + class UIWidgetAddNodeTest : public UIScene { public: + CREATE_FUNC(UIWidgetAddNodeTest); + UIWidgetAddNodeTest(); ~UIWidgetAddNodeTest(); - bool init(); - -protected: - UI_SCENE_CREATE_FUNC(UIWidgetAddNodeTest) + + virtual bool init() override; }; #endif /* defined(__TestCpp__UINodeContainerTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp index ef41ec4e3e..5672729bb9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp @@ -1,7 +1,9 @@ - - #include "UIWidgetAddNodeTest_Editor.h" +UIWidgetAddNodeEditorTests::UIWidgetAddNodeEditorTests() +{ + ADD_TEST_CASE(UIWidgetAddNodeTest_Editor); +} // UIWidgetAddNodeTest_Editor @@ -15,88 +17,12 @@ UIWidgetAddNodeTest_Editor::~UIWidgetAddNodeTest_Editor() } -void UIWidgetAddNodeTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) -{ - MenuItemToggle *item = (MenuItemToggle*)pSender; - - switch (item->getSelectedIndex()) - { - case 0: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode/windows_ui_widget_add_node_editor.json")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 1: - { - _layout->removeFromParentAndCleanup(true); - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIWidgetAddNode/windows_ui_widget_add_node_editor.csb")); - - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 2: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIWidgetAddNode/crossplatform_UIWidgetAddNode_Editor_1.ExportJson"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - case 3: - { - _layout->removeFromParentAndCleanup(true); - - Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIWidgetAddNode/crossplatform_UIWidgetAddNode_Editor_1.csb"); - Node* child = node->getChildByTag(5); - child->removeFromParent(); - _layout = static_cast(child); - _touchGroup->addChild(_layout); - - this->configureGUIScene(); - - break; - } - - default: - break; - } -} - void UIWidgetAddNodeTest_Editor::configureGUIScene() { - Size screenSize = CCDirector::getInstance()->getWinSize(); + UIScene_Editor::configureGUIScene(); + Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - + // Create the ui widget Widget* widget = Widget::create(); widget->setPosition(Vec2(rootSize.width / 2.0f, rootSize.height / 2.0f)); @@ -105,8 +31,6 @@ void UIWidgetAddNodeTest_Editor::configureGUIScene() Sprite* sprite = Sprite::create("cocosui/ccicon.png"); widget->addChild(sprite); - - } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h index 11d4c36097..57bfe10f0f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h @@ -27,16 +27,17 @@ #include "../UIScene_Editor.h" +DEFINE_TEST_SUITE(UIWidgetAddNodeEditorTests); class UIWidgetAddNodeTest_Editor : public UIScene_Editor { public: + CREATE_FUNC(UIWidgetAddNodeTest_Editor); + UIWidgetAddNodeTest_Editor(); ~UIWidgetAddNodeTest_Editor(); - bool init(); - virtual void switchLoadMethod(Ref* pSender); - void configureGUIScene(); -protected: - UI_SCENE_EDITOR_CREATE_FUNC(UIWidgetAddNodeTest_Editor) + + virtual bool init() override; + virtual void configureGUIScene() override; }; #endif /* defined(__TestCpp__UIWidgetAddNodeTest_Editor__) */ diff --git a/tests/cpp-tests/Classes/UITest/UITest.cpp b/tests/cpp-tests/Classes/UITest/UITest.cpp index 22fc8998f8..0f9a959587 100644 --- a/tests/cpp-tests/Classes/UITest/UITest.cpp +++ b/tests/cpp-tests/Classes/UITest/UITest.cpp @@ -1,8 +1,19 @@ #include "UITest.h" -#include "CocoStudioGUITest/CocoStudioGUITest.h" +#include "cocostudio/CCArmatureDataManager.h" +#include "CocoStudioGUITest/CocosGUIScene.h" +#include "CocoStudioGUITest/GUIEditorTest.h" +#include "CocoStudioGUITest/CustomGUIScene.h" +#include "CocoStudioGUITest/CocostudioParserTest.h" -void UITestScene::runThisTest() +UITests::UITests() { - CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene(); - pScene->runThisTest(); + addTest("GUI Dynamic Create Test", [](){ return new (std::nothrow) GUIDynamicCreateTests; }); + addTest("GUI Editor Test", [](){ return new (std::nothrow) GUIEditorTests; }); + addTest("Custom GUI Test", [](){ return new (std::nothrow) CustomGUITests; }); + addTest("Cocostudio Parser Test", [](){ return new (std::nothrow) CocostudioParserTests; }); +} + +UITests::~UITests() +{ + cocostudio::ArmatureDataManager::destroyInstance(); } diff --git a/tests/cpp-tests/Classes/UITest/UITest.h b/tests/cpp-tests/Classes/UITest/UITest.h index eb5b555789..27df8a3a60 100644 --- a/tests/cpp-tests/Classes/UITest/UITest.h +++ b/tests/cpp-tests/Classes/UITest/UITest.h @@ -1,13 +1,17 @@ #ifndef __cocos2d_tests__UITest__ #define __cocos2d_tests__UITest__ -#include "../testBasic.h" #include "../BaseTest.h" -class UITestScene : public TestScene +class UITests : public TestList { public: - virtual void runThisTest() override; + UITests(); + ~UITests(); + +private: + }; + #endif /* defined(__cocos2d_tests__UITest__) */ diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp index ac45999f67..3f19b8eed9 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp @@ -34,97 +34,23 @@ // For ' < o > ' multiply test scene. -static std::function createFunctions[] = { - CL(TemplateVectorTest), - CL(TemplateMapTest), - CL(ValueTest), - CL(RefPtrTest), - CL(UTFConversionTest), +UnitTests::UnitTests() +{ + ADD_TEST_CASE(TemplateVectorTest); + ADD_TEST_CASE(TemplateMapTest); + ADD_TEST_CASE(ValueTest); + ADD_TEST_CASE(RefPtrTest); + ADD_TEST_CASE(UTFConversionTest); #ifdef UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL - CL(MathUtilTest) + ADD_TEST_CASE(MathUtilTest); #endif }; -static int sceneIdx = -1; -static const int MAX_LAYER = (sizeof(createFunctions) / sizeof(createFunctions[0])); - -static Layer* nextAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void UnitTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(nextAction()); - Director::getInstance()->replaceScene(this); -} - -void UnitTestDemo::onEnter() -{ - BaseTest::onEnter(); -} - -void UnitTestDemo::onExit() -{ - BaseTest::onExit(); -} - std::string UnitTestDemo::title() const { return "UnitTest"; } -std::string UnitTestDemo::subtitle() const -{ - return ""; -} - -void UnitTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) UnitTestScene(); - s->addChild( restartAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void UnitTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) UnitTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void UnitTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) UnitTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - //--------------------------------------------------------------- void TemplateVectorTest::onEnter() diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.h b/tests/cpp-tests/Classes/UnitTest/UnitTest.h index e35be42097..13265e57bc 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.h +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.h @@ -1,27 +1,14 @@ #ifndef __UNIT_TEST__ #define __UNIT_TEST__ -#include "../testBasic.h" #include "../BaseTest.h" -class UnitTestScene : public TestScene +DEFINE_TEST_SUITE(UnitTests); + +class UnitTestDemo : public TestCase { public: - virtual void runThisTest() override; -}; - -class UnitTestDemo : public BaseTest -{ -public: - virtual void onEnter() override; - virtual void onExit() override; - virtual std::string title() const override; - virtual std::string subtitle() const override; - - virtual void restartCallback(Ref* sender) override; - virtual void nextCallback(Ref* sender) override; - virtual void backCallback(Ref* sender) override; }; //------------------------------------- diff --git a/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.cpp b/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.cpp index bed0346033..9a952e17bd 100644 --- a/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.cpp +++ b/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.cpp @@ -5,6 +5,11 @@ // enable log #define COCOS2D_DEBUG 1 +UserDefaultTests::UserDefaultTests() +{ + ADD_TEST_CASE(UserDefaultTest); +} + UserDefaultTest::UserDefaultTest() { auto s = Director::getInstance()->getWinSize(); @@ -94,12 +99,3 @@ void UserDefaultTest::doTest() UserDefaultTest::~UserDefaultTest() { } - -void UserDefaultTestScene::runThisTest() -{ - auto layer = new (std::nothrow) UserDefaultTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.h b/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.h index 8a25e30889..bec4560638 100644 --- a/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.h +++ b/tests/cpp-tests/Classes/UserDefaultTest/UserDefaultTest.h @@ -2,11 +2,14 @@ #define _USERDEFAULT_TEST_H_ #include "cocos2d.h" -#include "../testBasic.h" +#include "../BaseTest.h" -class UserDefaultTest : public Layer +DEFINE_TEST_SUITE(UserDefaultTests); + +class UserDefaultTest : public TestCase { public: + CREATE_FUNC(UserDefaultTest); UserDefaultTest(); ~UserDefaultTest(); @@ -14,10 +17,4 @@ private: void doTest(); }; -class UserDefaultTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - #endif // _USERDEFAULT_TEST_H_ diff --git a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp index 0870ea68f9..d5dc19f1ba 100644 --- a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp +++ b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.cpp @@ -1,95 +1,9 @@ #include "ZwoptexTest.h" #include "../testResource.h" -#define MAX_LAYER 1 - -static int sceneIdx = -1; - -Layer* nextZwoptexTest(); -Layer* backZwoptexTest(); -Layer* restartZwoptexTest(); - -Layer* createZwoptexLayer(int nIndex) +ZwoptexTests::ZwoptexTests() { - switch(nIndex) - { - case 0: return new ZwoptexGenericTest(); - } - - return nullptr; -} - -Layer* nextZwoptexTest() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = createZwoptexLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* backZwoptexTest() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = createZwoptexLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -Layer* restartZwoptexTest() -{ - auto layer = createZwoptexLayer(sceneIdx); - layer->autorelease(); - - return layer; -} - -//------------------------------------------------------------------ -// -// ZwoptexTest -// -//------------------------------------------------------------------ -void ZwoptexTest::onEnter() -{ - BaseTest::onEnter(); -} - -void ZwoptexTest::restartCallback(Ref* sender) -{ - auto s = ZwoptexTestScene::create(); - s->addChild(restartZwoptexTest()); - Director::getInstance()->replaceScene(s); -} - -void ZwoptexTest::nextCallback(Ref* sender) -{ - auto s = ZwoptexTestScene::create(); - s->addChild(nextZwoptexTest()); - Director::getInstance()->replaceScene(s); -} - -void ZwoptexTest::backCallback(Ref* sender) -{ - auto s = ZwoptexTestScene::create(); - s->addChild(backZwoptexTest()); - Director::getInstance()->replaceScene(s); -} - -std::string ZwoptexTest::title() const -{ - return "No title"; -} - -std::string ZwoptexTest::subtitle() const -{ - return ""; + ADD_TEST_CASE(ZwoptexGenericTest); } //------------------------------------------------------------------ @@ -207,11 +121,3 @@ std::string ZwoptexGenericTest::subtitle() const { return "Coordinate Formats, Rotation, Trimming, flipX/Y"; } - -void ZwoptexTestScene::runThisTest() -{ - auto layer = nextZwoptexTest(); - addChild(layer); - - Director::getInstance()->replaceScene(this); -} diff --git a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.h b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.h index e31b201e5a..a9c191f1e3 100644 --- a/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.h +++ b/tests/cpp-tests/Classes/ZwoptexTest/ZwoptexTest.h @@ -1,26 +1,22 @@ #ifndef __ZWOPTEX_TEST_H__ #define __ZWOPTEX_TEST_H__ -#include "../testBasic.h" #include "../BaseTest.h" -class ZwoptexTest : public BaseTest +DEFINE_TEST_SUITE(ZwoptexTests); + +class ZwoptexTest : public TestCase { public: - virtual void onEnter() override; - - void restartCallback(Ref* sender) override; - void nextCallback(Ref* sender) override; - void backCallback(Ref* sender) override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; }; class ZwoptexGenericTest : public ZwoptexTest { public: - ~ZwoptexGenericTest(); + CREATE_FUNC(ZwoptexGenericTest); + + virtual ~ZwoptexGenericTest(); + virtual void onEnter() override; void flipSprites(float dt); void startIn05Secs(float dt); @@ -34,12 +30,4 @@ protected: int counter; }; -class ZwoptexTestScene : public TestScene -{ -public: - virtual void runThisTest(); - - CREATE_FUNC(ZwoptexTestScene); -}; - #endif // __ZWOPTEX_TEST_H__