Procházet zdrojové kódy

Unit testing of ScriptingEngine

Panagiotis Christopoulos Charitos před 15 roky
rodič
revize
7e64a51afa

+ 5 - 5
src/Scripting/Math/Vec3.bpi.cpp

@@ -5,11 +5,7 @@
 WRAP(Vec3)
 {
 	class_<Vec3>("Vec3")
-		/// @todo correct
-		/*.def_readwrite("x", &Vec3::x)
-		.def_readwrite("y", &Vec3::y)
-		.def_readwrite("z", &Vec3::z)*/
-		// constructors
+		// Constructors
 		.def(init<>())
 		.def(init<float>())
 		.def(init<float, float, float>())
@@ -17,6 +13,10 @@ WRAP(Vec3)
 		.def(init<const Vec3&>())
 		.def(init<const Vec4&>())
 		.def(init<const Quat&>())
+		// Accessors
+		BP_PROPERTY_MATH(Vec3, x)
+		BP_PROPERTY_MATH(Vec3, y)
+		BP_PROPERTY_MATH(Vec3, z)
 		// ops with self
 		.def(self + self) // +
 		.def(self += self) // +=

+ 5 - 5
src/Scripting/Math/Vec4.bpi.cpp

@@ -5,11 +5,6 @@
 WRAP(Vec4)
 {
 	class_<Vec4>("Vec4")
-		/// @todo Correct this
-		/*.def_readwrite("x", &Vec4::x)
-		.def_readwrite("y", &Vec4::y)
-		.def_readwrite("z", &Vec4::z)
-		.def_readwrite("w", &Vec4::w)*/
 		// constructors
 		.def(init<>())
 		.def(init<float>())
@@ -18,6 +13,11 @@ WRAP(Vec4)
 		.def(init<const Vec3&, float>())
 		.def(init<const Vec4&>())
 		.def(init<const Quat&>())
+		// Accessors
+		BP_PROPERTY_MATH(Vec4, x)
+		BP_PROPERTY_MATH(Vec4, y)
+		BP_PROPERTY_MATH(Vec4, z)
+		BP_PROPERTY_MATH(Vec4, w)
 		// ops with self
 		.def(self + self) // +
 		.def(self += self) // +=

+ 1 - 4
src/Scripting/ScriptingEngine.cpp

@@ -7,9 +7,6 @@
 extern "C" void initAnki(); /// Defined in BoostPythonInterfaces.cpp
 
 
-ScriptingEngine* ScriptingEngine::instance = NULL;
-
-
 //======================================================================================================================
 // init                                                                                                                =
 //======================================================================================================================
@@ -38,7 +35,7 @@ void ScriptingEngine::execScript(const char* script, const char* scriptName)
 	}
 	catch(boost::python::error_already_set)
 	{
-		//PyErr_Print();
+		PyErr_Print();
 		throw EXCEPTION("Script \"" + scriptName + "\" failed with error");
 	}
 }

+ 0 - 1
src/Scripting/ScriptingEngine.h

@@ -23,7 +23,6 @@ class ScriptingEngine
 		void exposeVar(const char* varName, Type* var);
 
 	private:
-		static ScriptingEngine* instance;
 		boost::python::object mainModule;
 		boost::python::object ankiModule;
 		boost::python::object mainNamespace;

+ 22 - 0
unit-tests/Scripting/ScriptingEngine.ut.cpp

@@ -0,0 +1,22 @@
+#include <gtest/gtest.h>
+#include "ScriptingEngine.h"
+#include "Math.h"
+#include "Logger.h"
+
+
+TEST(ScriptingTests, ScriptingEngine)
+{
+	Vec4 v;
+	ScriptingEngineSingleton::getInstance().exposeVar<Vec4>("v", &v);
+	
+	const char* src =
+		"from Anki import *\n" 
+		"v.x = 1.0\n"
+		"v.y = 2.0\n"
+		"v.z = 3.0\n"
+		"v.w = 4.0\n"
+		"v += Vec4(1.0)\n";
+		
+	EXPECT_NO_THROW(ScriptingEngineSingleton::getInstance().execScript(src));
+	EXPECT_EQ(v, Vec4(2.0, 3.0, 4.0, 5.0));
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 1
unit-tests/build/Makefile


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů