2
0
Эх сурвалжийг харах

- Renaming the tests dir
- StringList additions
- Other

Panagiotis Christopoulos Charitos 14 жил өмнө
parent
commit
a00726731e

+ 3 - 3
CMakeLists.txt

@@ -154,9 +154,9 @@ ADD_SUBDIRECTORY(anki)
 #
 # Unit tests
 #
-OPTION(BUILD_UNIT_TESTS "Build Unit Tests" OFF)
+OPTION(BUILD_TESTS "Build Unit Tests" OFF)
 
-IF(BUILD_UNIT_TESTS)
+IF(BUILD_TESTS)
 	ENABLE_TESTING()
 	
 	SET(GTEST_INCLUDE_DIR "/usr/include" CACHE PATH "The directory that contains the gtest directory")
@@ -164,7 +164,7 @@ IF(BUILD_UNIT_TESTS)
 
 	ANKI_ADD_LIB(${GTEST_INCLUDE_DIR} ${GTEST_LIBRARY_DIR} ${GTEST_INCLUDE_DIR}/gtest/gtest.h)
 	
-	ADD_SUBDIRECTORY(unit-tests)
+	ADD_SUBDIRECTORY(tests)
 ENDIF()
 
 #

+ 2 - 6
anki/resource/Material.h

@@ -6,7 +6,6 @@
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/StringList.h"
 #include "anki/math/Math.h"
-#include "anki/util/Variant.h"
 #include <GL/glew.h>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/array.hpp>
@@ -24,17 +23,14 @@ class ShaderProgram;
 class ShaderProgramUniformVariable;
 
 
-typedef Variant<float, Vec2, Vec3, Vec4, Mat3,
-	Mat4, TextureResourcePointer> MaterialVariableVariant;
-
-
 /// Holds the shader variables. Its a container for shader program variables
 /// that share the same name
 class MaterialVariable: public boost::noncopyable
 {
 public:
 	/// The data union (limited to a few types at the moment)
-	typedef MaterialVariableVariant Variant;
+	typedef boost::variant<float, Vec2, Vec3, Vec4, Mat3,
+		Mat4, TextureResourcePointer> Variant;
 
 	/// Given a pair of pass and level it returns a pointer to a
 	/// shader program uniform variable. The pointer may be null

+ 12 - 5
anki/resource/PassLevelKey.h

@@ -20,14 +20,22 @@ struct PassLevelKey
 	PassLevelKey(uint pass_, uint level_)
 		: pass(pass_), level(level_)
 	{}
+};
+
 
-	/// Create hash
+/// Create hash functor
+struct PassLevelKeyCreateHash
+{
 	size_t operator()(const PassLevelKey& b) const
 	{
-		return pass * 1000 + level;
+		return b.pass * 1000 + b.level;
 	}
+};
 
-	/// Values comparisons
+
+/// Values comparisons functor
+struct PassLevelKeyComparision
+{
 	bool operator()(const PassLevelKey& a,
 		const PassLevelKey& b) const
 	{
@@ -41,11 +49,10 @@ template<typename T>
 struct PassLevelHashMap
 {
 	typedef boost::unordered_map<PassLevelKey, T,
-		PassLevelKey, PassLevelKey> Type;
+		PassLevelKeyCreateHash, PassLevelKeyComparision> Type;
 };
 
 
-
 } // end namespace
 
 

+ 1 - 1
anki/resource/ResourceManager.inl.h

@@ -103,7 +103,7 @@ void ResourceManager<Type>::unload(const Hook& hook)
 			hook.uuid + "\")");
 	}
 
-	assert(*it == hook);
+	ANKI_ASSERT(*it == hook);
 
 	--it->referenceCounter;
 

+ 1 - 1
anki/resource/ResourcePointer.h

@@ -15,7 +15,7 @@ class ResourcePointer
 {
 public:
 	typedef ResourcePointer<Type, ResourceManagerSingleton> Self;
-	typedef typename ResourceManagerSingleton::ValueType::Hook Hook;
+	typedef typename ResourceManagerSingleton::Value::Hook Hook;
 
 	/// Default constructor
 	ResourcePointer()

+ 2 - 0
anki/resource/Skin.cpp

@@ -7,6 +7,8 @@
 #include "anki/resource/SkelAnim.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/PassLevelKey.h"
+#include "anki/resource/Model.h"
+#include "anki/resource/Material.h"
 
 
 namespace anki {

+ 4 - 1
anki/scene/MaterialRuntime.cpp

@@ -58,8 +58,11 @@ MaterialRuntime::MaterialRuntime(const Material& mtl_)
 	me = he;
 
 	// Create vars
-	BOOST_FOREACH(const MaterialVariable& var, mtl.getVariables())
+	Material::VarsContainer::const_iterator it = mtl.getVariables().begin();
+	for(; it != mtl.getVariables().end(); ++it)
 	{
+		const MaterialVariable& var = *it;
+
 		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
 		vars.push_back(varr);
 		varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;

+ 9 - 8
anki/util/Singleton.h

@@ -10,15 +10,15 @@ namespace anki {
 
 
 /// This template makes a class singleton
-template<typename Type>
+template<typename T>
 class Singleton
 {
 public:
-	typedef Type ValueType;
+	typedef T Value;
 
-	static Type& get()
+	static Value& get()
 	{
-		return *(instance ? instance : (instance = new Type));
+		return *(instance ? instance : (instance = new Value));
 	}
 
 protected:
@@ -26,14 +26,15 @@ protected:
 	~Singleton();
 
 private:
-	static Type* instance;
-	Singleton(Singleton const&);
+	static Value* instance;
+
+	Singleton(const Singleton&);
 	Singleton& operator=(const Singleton&);
 };
 
 
-template <typename Type>
-Type* Singleton<Type>::instance = NULL;
+template <typename T>
+typename Singleton<T>::Value* Singleton<T>::instance = NULL;
 
 
 } // end namespace

+ 33 - 7
anki/util/StringList.cpp

@@ -7,9 +7,9 @@ namespace anki {
 
 
 //==============================================================================
-StringList::StringType StringList::join(const StringType& sep) const
+StringList::String StringList::join(const Char* sep) const
 {
-	StringType out;
+	String out;
 
 	Base::const_iterator it = begin();
 	for(; it != end(); it++)
@@ -26,22 +26,48 @@ StringList::StringType StringList::join(const StringType& sep) const
 
 
 //==============================================================================
-StringList StringList::splitString(const StringType& s, const char* seperators)
+int StringList::getIndexOf(const Char* value) const
 {
-	typedef boost::char_separator<char> Sep;
+	size_t pos = 0;
+
+	for(const_iterator it = begin(); it != end(); ++it)
+	{
+		if(*it == value)
+		{
+			break;
+		}
+		++ pos;
+	}
+
+	return (pos == size()) ? -1 : pos;
+}
+
+
+//==============================================================================
+StringList StringList::splitString(const Char* s, const Char* seperators)
+{
+	typedef boost::char_separator<Char> Sep;
 	typedef boost::tokenizer<Sep> Tok;
 
 	Sep sep(seperators);
 	StringList out;
-	Tok tok(s, sep);
+	Tok tok(String(s), sep);
 
-	BOOST_FOREACH(const std::string& s, tok)
+	BOOST_FOREACH(const String& s_, tok)
 	{
-		out.push_back(s);
+		out.push_back(s_);
 	}
 
 	return out;
 }
 
 
+//==============================================================================
+std::ostream& operator<<(std::ostream& s, const StringList& a)
+{
+	s << a.join(", ");
+	return s;
+}
+
+
 } // end namespace

+ 22 - 7
anki/util/StringList.h

@@ -8,20 +8,35 @@
 namespace anki {
 
 
-/// A simple convenience class
+/// @addtogroup util
+/// @{
+
+/// A simple convenience class for string lists
 class StringList: public std::vector<std::string>
 {
 public:
+	typedef StringList Self; ///< Self type
 	typedef std::vector<std::string> Base; ///< Its the vector of strings
-	typedef Base::value_type StringType; ///< Its string
+	typedef Base::value_type String; ///< Its string
+	typedef String::value_type Char; ///< Char type
+
+	/// Join all the elements into a single big string using a the
+	/// seperator @a sep
+	String join(const Char* sep) const;
+
+	/// Returns the index position of the last occurrence of @a value in
+	/// the list
+	/// @return -1 of not found
+	int getIndexOf(const Char* value) const;
 
-	/// Return the list as a single string
-	StringType join(const StringType& sep) const;
+	/// Split a string using a list of separators (@a sep) and return these
+	/// strings in a string list
+	static Self splitString(const Char* s, const Char* sep = " ");
 
-	/// XXX
-	static StringList splitString(const StringType& s,
-		const char* sep = " ");
+	/// Mainly for the unit tests
+	friend std::ostream& operator<<(std::ostream& s, const Self& a);
 };
+/// @}
 
 
 } // end namespace

+ 0 - 0
unit-tests/.cproject → tests/.cproject


+ 0 - 0
unit-tests/.project → tests/.project


+ 7 - 0
tests/CMakeLists.txt

@@ -0,0 +1,7 @@
+FILE(GLOB_RECURSE TESTS_SOURCES *.cpp)
+FILE(GLOB_RECURSE TESTS_HEADERS *.h)
+
+ADD_EXECUTABLE(tests ${TESTS_SOURCES} ${TESTS_HEADERS})
+TARGET_LINK_LIBRARIES(tests anki gtest)
+
+INSTALL(TARGETS tests DESTINATION "${CMAKE_INSTALL_PREFIX}/tests")

+ 0 - 0
unit-tests/Main.cpp → tests/Main.cpp


+ 0 - 0
unit-tests/Math/MathCommon.ut.h → tests/Math/MathCommon.ut.h


+ 0 - 0
unit-tests/Math/Matrices.ut.cpp → tests/Math/Matrices.ut.cpp


+ 0 - 0
unit-tests/Math/Vectors.ut.cpp → tests/Math/Vectors.ut.cpp


+ 0 - 0
unit-tests/Resources/Material.ut.cpp → tests/Resources/Material.ut.cpp


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


+ 0 - 0
unit-tests/Ui/UiFtFontLoader.ut.cpp → tests/Ui/UiFtFontLoader.ut.cpp


+ 0 - 0
unit-tests/Util/HighRezTimer.ut.cpp → tests/Util/HighRezTimer.ut.cpp


+ 0 - 0
unit-tests/Util/Scanner.ut.cpp → tests/Util/Scanner.ut.cpp


+ 0 - 0
unit-tests/data/bool_err.mtl → tests/data/bool_err.mtl


+ 0 - 0
unit-tests/data/complex.mtl → tests/data/complex.mtl


+ 0 - 0
unit-tests/data/custom_sprog.mtl → tests/data/custom_sprog.mtl


+ 0 - 0
unit-tests/data/custom_sprog_skinning.mtl → tests/data/custom_sprog_skinning.mtl


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 9
unit-tests/build/Makefile


+ 0 - 14
unit-tests/build/gen.cfg.py

@@ -1,14 +0,0 @@
-sourcePaths = walkDir("../../src", False)
-sourcePaths.extend(list(walkDir("../", True)))
-
-includePaths = ["./"]
-includePaths.extend(list(sourcePaths))
-includePaths.extend(["../../extern/include", "../../extern/include/bullet", "/usr/include/python2.6", "/usr/include/freetype2"])
-
-executableName = "anki-unit-tests"
-
-compiler = "g++"
-
-compilerFlags = "-DPLATFORM_LINUX -DMATH_INTEL_SIMD -DREVISION=\\\"`svnversion -c ../..`\\\" -c -msse4 -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -pipe -pg -fsingle-precision-constant"
-
-linkerFlags = "-rdynamic -pg -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread -lfreetype -lgtest"

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно