Explorar o código

Added test case for scene object commit and restore

Marko Pintera %!s(int64=11) %!d(string=hai) anos
pai
achega
4867d3a4a3

+ 3 - 1
BansheeEditor/Include/BsEditorPrerequisites.h

@@ -75,6 +75,8 @@ namespace BansheeEngine
 		TID_DockManagerLayout = 40004,
 		TID_DockManagerLayoutEntry = 40005,
 		TID_EditorWidgetLayout = 40006,
-		TID_EditorWidgetLayoutEntry = 40007
+		TID_EditorWidgetLayoutEntry = 40007,
+		TID_TestComponentA = 40008,
+		TID_TestComponentB = 40009
 	};
 }

+ 56 - 1
BansheeEditor/Include/BsEditorTestSuite.h

@@ -2,10 +2,65 @@
 
 #include "BsEditorPrerequisites.h"
 #include "BsTestSuite.h"
+#include "BsComponent.h"
 
 namespace BansheeEngine
 {
-	class BS_ED_EXPORT EditorTestSuite : public TestSuite
+	class TestComponentA : public Component
+	{
+	public:
+		HSceneObject ref1;
+		HComponent ref2;
+
+		/************************************************************************/
+		/* 							COMPONENT OVERRIDES                    		*/
+		/************************************************************************/
+
+	protected:
+		friend class SceneObject;
+
+		TestComponentA(const HSceneObject& parent);
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class TestComponentARTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
+
+	protected:
+		TestComponentA() {} // Serialization only
+	};
+
+	class TestComponentB : public Component
+	{
+	public:
+		HSceneObject ref1;
+		String val1;
+
+		/************************************************************************/
+		/* 							COMPONENT OVERRIDES                    		*/
+		/************************************************************************/
+
+	protected:
+		friend class SceneObject;
+
+		TestComponentB(const HSceneObject& parent);
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class TestComponentBRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
+
+	protected:
+		TestComponentB() {} // Serialization only
+	};
+
+	class EditorTestSuite : public TestSuite
 	{
 	public:
 		EditorTestSuite();

+ 1 - 1
BansheeEditor/Source/BsCmdRecordSO.cpp

@@ -13,12 +13,12 @@ namespace BansheeEngine
 
 	CmdRecordSO::~CmdRecordSO()
 	{
+		mSceneObject = nullptr;
 		clear();
 	}
 
 	void CmdRecordSO::clear()
 	{
-		mSceneObject = nullptr;
 		mSerializedObjectSize = 0;
 		mSerializedObjectParentId = 0;
 

+ 137 - 1
BansheeEditor/Source/BsEditorTestSuite.cpp

@@ -1,7 +1,106 @@
 #include "BsEditorTestSuite.h"
+#include "BsSceneObject.h"
+#include "BsCmdRecordSO.h"
+#include "BsUndoRedo.h"
+#include "BsRTTIType.h"
+#include "BsGameObjectRTTI.h"
 
 namespace BansheeEngine
 {
+	class TestComponentARTTI : public RTTIType<TestComponentA, Component, TestComponentARTTI>
+	{
+	private:
+		HSceneObject& getRef1(TestComponentA* obj) { return obj->ref1; }
+		void setRef1(TestComponentA* obj, HSceneObject& val) { obj->ref1 = val; }
+
+		HComponent& getRef2(TestComponentA* obj) { return obj->ref2; }
+		void setRef2(TestComponentA* obj, HComponent& val) { obj->ref2 = val; }
+
+	public:
+		TestComponentARTTI()
+		{
+			addReflectableField("ref1", 0, &TestComponentARTTI::getRef1, &TestComponentARTTI::setRef1);
+			addReflectableField("ref2", 1, &TestComponentARTTI::getRef2, &TestComponentARTTI::setRef2);
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "TestComponentA";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_TestComponentA;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return GameObjectRTTI::createGameObject<TestComponentA>();
+		}
+	};
+
+	class TestComponentBRTTI : public RTTIType<TestComponentB, Component, TestComponentBRTTI>
+	{
+	private:
+		HSceneObject& getRef1(TestComponentB* obj) { return obj->ref1; }
+		void setRef1(TestComponentB* obj, HSceneObject& val) { obj->ref1 = val; }
+
+		String& getVal1(TestComponentB* obj) { return obj->val1; }
+		void setVal1(TestComponentB* obj, String& val) { obj->val1 = val; }
+
+	public:
+		TestComponentBRTTI()
+		{
+			addReflectableField("ref1", 0, &TestComponentBRTTI::getRef1, &TestComponentBRTTI::setRef1);
+			addPlainField("val1", 1, &TestComponentBRTTI::getVal1, &TestComponentBRTTI::setVal1);
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "TestComponentB";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_TestComponentB;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return GameObjectRTTI::createGameObject<TestComponentB>();
+		}
+	};
+
+	TestComponentA::TestComponentA(const HSceneObject& parent)
+		:Component(parent)
+	{}
+
+	RTTITypeBase* TestComponentA::getRTTIStatic()
+	{
+		return TestComponentARTTI::instance();
+	}
+
+	RTTITypeBase* TestComponentA::getRTTI() const
+	{
+		return TestComponentA::getRTTIStatic();
+	}
+
+	TestComponentB::TestComponentB(const HSceneObject& parent)
+		:Component(parent)
+	{}
+
+	RTTITypeBase* TestComponentB::getRTTIStatic()
+	{
+		return TestComponentBRTTI::instance();
+	}
+
+	RTTITypeBase* TestComponentB::getRTTI() const
+	{
+		return TestComponentB::getRTTIStatic();
+	}
+
 	EditorTestSuite::EditorTestSuite()
 	{
 		BS_ADD_TEST(EditorTestSuite::SceneObjectRecord_UndoRedo)
@@ -9,6 +108,43 @@ namespace BansheeEngine
 
 	void EditorTestSuite::SceneObjectRecord_UndoRedo()
 	{
-		BS_TEST_ASSERT_MSG(false, "SUP SUP");
+		HSceneObject so0_0 = SceneObject::create("so0_0");
+		HSceneObject so1_0 = SceneObject::create("so1_0");
+		HSceneObject so1_1 = SceneObject::create("so1_1");
+		HSceneObject so2_0 = SceneObject::create("so2_0");
+
+		so1_0->setParent(so0_0);
+		so1_1->setParent(so0_0);
+		so2_0->setParent(so1_0);
+
+		GameObjectHandle<TestComponentA> cmpA1_1 = so1_1->addComponent<TestComponentA>();
+		GameObjectHandle<TestComponentB> cmpB1_1 = so1_1->addComponent<TestComponentB>();
+
+		HSceneObject soExternal = SceneObject::create("soExternal");
+		GameObjectHandle<TestComponentA> cmpExternal = soExternal->addComponent<TestComponentA>();
+
+		cmpA1_1->ref1 = so2_0;
+		cmpA1_1->ref2 = cmpB1_1;
+		cmpB1_1->ref1 = soExternal;
+		cmpB1_1->val1 = "InitialValue";
+		cmpExternal->ref1 = so1_1;
+		cmpExternal->ref2 = cmpA1_1;
+
+		CmdRecordSO::execute(so0_0);
+		cmpB1_1->val1 = "ModifiedValue";
+		UndoRedo::instance().undo();
+
+		BS_TEST_ASSERT(!so0_0.isDestroyed());
+		BS_TEST_ASSERT(!so1_0.isDestroyed());
+		BS_TEST_ASSERT(!so1_1.isDestroyed());
+		BS_TEST_ASSERT(!so2_0.isDestroyed());
+		BS_TEST_ASSERT(!cmpA1_1.isDestroyed());
+		BS_TEST_ASSERT(!cmpB1_1.isDestroyed());
+		BS_TEST_ASSERT(!cmpA1_1->ref1.isDestroyed());
+		BS_TEST_ASSERT(!cmpA1_1->ref2.isDestroyed());
+		BS_TEST_ASSERT(!cmpB1_1->ref1.isDestroyed());
+		BS_TEST_ASSERT(!cmpExternal->ref1.isDestroyed());
+		BS_TEST_ASSERT(!cmpExternal->ref2.isDestroyed());
+		BS_TEST_ASSERT(cmpB1_1->val1 == "InitialValue");
 	}
 }

+ 0 - 15
BansheeUtility/Include/BsTestOutput.h

@@ -21,16 +21,6 @@ namespace BansheeEngine
 		 * @param	line		Line of code the unit test failed on.
 		 */
 		virtual void outputFail(const String& desc, const String& function, const String& file, long line) = 0;
-
-		/**
-		 * @brief	Triggered when a unit test succeeds.
-		 *
-		 * @param	desc		Optional message to add.
-		 * @param	function	Name of the function the test failed in.
-		 * @param	file		File the unit test failed in.
-		 * @param	line		Line of code the unit test failed on.
-		 */
-		virtual void outputSuccess(const String& desc, const String& function, const String& file, long line) = 0;
 	};
 
 	/**
@@ -43,10 +33,5 @@ namespace BansheeEngine
 		 * @copydoc	TestOutput::outputFail
 		 */
 		void outputFail(const String& desc, const String& function, const String& file, long line);
-
-		/**
-		 * @copydoc	TestOutput::outputSuccess
-		 */
-		void outputSuccess(const String& desc, const String& function, const String& file, long line);
 	};
 }

+ 0 - 5
BansheeUtility/Source/BsTestOutput.cpp

@@ -7,9 +7,4 @@ namespace BansheeEngine
 	{
 		throw UnitTestException(desc, function, file.c_str(), line);
 	}
-
-	void ExceptionTestOutput::outputSuccess(const String& desc, const String& function, const String& file, long line)
-	{
-		// Do nothing
-	}
 }

+ 1 - 3
BansheeUtility/Source/BsTestSuite.cpp

@@ -44,9 +44,7 @@ namespace BansheeEngine
 
 	void TestSuite::assertment(bool success, const String& desc, const String& file, long line)
 	{
-		if (success)
-			mOutput->outputSuccess(desc, mActiveTestName, file, line);
-		else
+		if (!success)
 			mOutput->outputFail(desc, mActiveTestName, file, line);
 	}
 }