diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-06-24 21:37:15 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-06-24 21:37:15 +0200 |
commit | 7c2e955e1552a9c4e412ea2c936be61fc78ba010 (patch) | |
tree | ee506dfbec54f998d10c385bde3a1c3fa04e66b2 /test | |
parent | e218dcfdf2c58f8841e7ebd220527d08e870a6d5 (diff) | |
parent | b376486fd74fa02b0297ceef6d0f977b32358e5e (diff) | |
download | colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.gz colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.bz2 colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.zip |
Colobot Gold 0.1.0-alpha
Diffstat (limited to 'test')
-rw-r--r-- | test/envs/opengl/CMakeLists.txt | 8 | ||||
-rw-r--r-- | test/unit/CMakeLists.txt | 28 | ||||
-rw-r--r-- | test/unit/app/app_test.cpp | 3 | ||||
-rw-r--r-- | test/unit/graphics/core/device_mock.h | 1 | ||||
-rw-r--r-- | test/unit/graphics/engine/modelfile_test.cpp | 235 | ||||
-rw-r--r-- | test/unit/main.cpp | 6 | ||||
-rw-r--r-- | test/unit/math/func_test.cpp | 39 | ||||
-rw-r--r-- | test/unit/math/geometry_test.cpp | 18 | ||||
-rw-r--r-- | test/unit/math/matrix_test.cpp | 18 | ||||
-rw-r--r-- | test/unit/math/vector_test.cpp | 18 | ||||
-rw-r--r-- | test/unit/ui/CMakeLists.txt | 12 | ||||
-rw-r--r-- | test/unit/ui/edit_test.cpp | 7 | ||||
-rw-r--r-- | test/unit/ui/stubs/app_stub.cpp | 6 | ||||
-rw-r--r-- | test/unit/ui/stubs/robotmain_stub.cpp | 2 |
14 files changed, 325 insertions, 76 deletions
diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt index 0bcb43d..2855318 100644 --- a/test/envs/opengl/CMakeLists.txt +++ b/test/envs/opengl/CMakeLists.txt @@ -3,15 +3,16 @@ set(SRC_DIR ${colobot_SOURCE_DIR}/src) configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) # Platform-dependent implementation of system.h -if (${PLATFORM_WINDOWS}) +if(PLATFORM_WINDOWS) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${PLATFORM_LINUX}) +elseif(PLATFORM_LINUX) set(SYSTEM_CPP_MODULE "system_linux.cpp") else() set(SYSTEM_CPP_MODULE "system_other.cpp") endif() set(TEXTURE_SOURCES +${SRC_DIR}/graphics/core/color.cpp ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp @@ -19,6 +20,7 @@ texture_test.cpp ) set(MODEL_SOURCES +${SRC_DIR}/graphics/core/color.cpp ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/graphics/engine/modelfile.cpp ${SRC_DIR}/common/logger.cpp @@ -30,6 +32,7 @@ model_test.cpp ) set(TRANSFORM_SOURCES +${SRC_DIR}/graphics/core/color.cpp ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp @@ -39,6 +42,7 @@ transform_test.cpp ) set(LIGHT_SOURCES +${SRC_DIR}/graphics/core/color.cpp ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 3d8a38c..95cf1b1 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,14 +1,14 @@ set(SRC_DIR ${colobot_SOURCE_DIR}/src) # Additional libraries per platform -if (${MXE}) # MXE requires special treatment +if(MXE) # MXE requires special treatment set(PLATFORM_LIBS ${MXE_LIBS}) -elseif (${PLATFORM_WINDOWS}) +elseif(PLATFORM_WINDOWS) # because it isn't included in standard linking libraries set(PLATFORM_LIBS "-lintl") -elseif(${PLATFORM_LINUX}) +elseif(PLATFORM_LINUX) # for clock_gettime - set(PLATFORM_LIBS "-lrt") + set(PLATFORM_LIBS "-lrt -lX11") endif() @@ -16,9 +16,9 @@ endif() configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) # Platform-dependent implementation of system.h -if (${PLATFORM_WINDOWS}) +if(PLATFORM_WINDOWS) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${PLATFORM_LINUX}) +elseif(PLATFORM_LINUX) set(SYSTEM_CPP_MODULE "system_linux.cpp") else() set(SYSTEM_CPP_MODULE "system_other.cpp") @@ -89,7 +89,9 @@ ${SRC_DIR}/object/motion/motionspider.cpp ${SRC_DIR}/object/motion/motiontoto.cpp ${SRC_DIR}/object/motion/motionvehicle.cpp ${SRC_DIR}/object/motion/motionworm.cpp +${SRC_DIR}/object/motion/motiondummy.cpp ${SRC_DIR}/object/object.cpp +${SRC_DIR}/object/objman.cpp ${SRC_DIR}/object/robotmain.cpp ${SRC_DIR}/object/task/task.cpp ${SRC_DIR}/object/task/taskadvance.cpp @@ -116,6 +118,7 @@ ${SRC_DIR}/physics/physics.cpp ${SRC_DIR}/script/cbottoken.cpp ${SRC_DIR}/script/cmdtoken.cpp ${SRC_DIR}/script/script.cpp +${SRC_DIR}/sound/sound.cpp ${SRC_DIR}/ui/button.cpp ${SRC_DIR}/ui/check.cpp ${SRC_DIR}/ui/color.cpp @@ -146,7 +149,7 @@ ${SRC_DIR}/ui/window.cpp set(OPENAL_SOURCES "") -if (${OPENAL_SOUND}) +if(OPENAL_SOUND) set(OPENAL_SOURCES ${SRC_DIR}/sound/oalsound/alsound.cpp ${SRC_DIR}/sound/oalsound/buffer.cpp @@ -157,16 +160,16 @@ endif() # Optional libraries set(OPTIONAL_LIBS "") -if (${OPENAL_SOUND}) +if(OPENAL_SOUND) set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) endif() # Platform-dependent tests -if (${PLATFORM_WINDOWS}) +if(PLATFORM_WINDOWS) set(PLATFORM_TESTS app/system_windows_test.cpp) -elseif(${PLATFORM_LINUX}) +elseif(PLATFORM_LINUX) set(PLATFORM_TESTS app/system_linux_test.cpp) endif() @@ -175,6 +178,7 @@ set(UT_SOURCES main.cpp app/app_test.cpp graphics/engine/lightman_test.cpp +math/func_test.cpp math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp @@ -203,12 +207,16 @@ ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} ${OPTIONAL_INCLUDE_DIRS} ${LIBSNDFILE_INCLUDE_DIR} +${CLIPBOARD_INCLUDE_DIR} +${LOCALENAME_INCLUDE_DIR} ) set(LIBS gtest gmock CBot +clipboard +localename ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} diff --git a/test/unit/app/app_test.cpp b/test/unit/app/app_test.cpp index 8c1e899..b517d7d 100644 --- a/test/unit/app/app_test.cpp +++ b/test/unit/app/app_test.cpp @@ -10,8 +10,6 @@ #include "app/system_mock.h" -#include "common/logger.h" - #include <gtest/gtest.h> using testing::_; @@ -57,7 +55,6 @@ protected: long long relTimeReal, long long absTimeReal); protected: - CLogger logger; CApplicationWrapper* app; CSystemUtilsMock* systemUtils; diff --git a/test/unit/graphics/core/device_mock.h b/test/unit/graphics/core/device_mock.h index 80e214f..9e75daf 100644 --- a/test/unit/graphics/core/device_mock.h +++ b/test/unit/graphics/core/device_mock.h @@ -10,6 +10,7 @@ public: CDeviceMock() {} MOCK_METHOD0(DebugHook, void()); + MOCK_METHOD0(DebugLights, void()); MOCK_METHOD0(Create, bool()); MOCK_METHOD0(Destroy, void()); diff --git a/test/unit/graphics/engine/modelfile_test.cpp b/test/unit/graphics/engine/modelfile_test.cpp new file mode 100644 index 0000000..0598e84 --- /dev/null +++ b/test/unit/graphics/engine/modelfile_test.cpp @@ -0,0 +1,235 @@ +#include "graphics/engine/modelfile.h" + +#include "math/func.h" + +#include <gtest/gtest.h> + +#include <cassert> +#include <sstream> + +/* Test model file (new text format) */ +const char* const TEXT_MODEL = +"# Colobot text model\n" +"\n" +"### HEAD\n" +"version 1\n" +"total_triangles 2\n" +"\n" +"### TRIANGLES\n" +"p1 c -12.4099 10.0016 -2.54558 n 1 -0 1.87319e-07 t1 0.970703 0.751953 t2 0 0\n" +"p2 c -12.4099 10.0016 2.54558 n 1 -0 1.87319e-07 t1 0.998047 0.751953 t2 0 0\n" +"p3 c -12.4099 4.00165 -2.54558 n 1 -0 1.87319e-07 t1 0.970703 0.998047 t2 0 0\n" +"mat dif 1 1 1 0 amb 0.5 0.5 0.5 0 spc 0 0 0 0\n" +"tex1 lemt.png\n" +"tex2\n" +"var_tex2 N\n" +"lod_level 0\n" +"state 1024\n" +"\n" +"p1 c -19 -1 4 n -1 0 0 t1 0.248047 0.123047 t2 0.905224 0.52067\n" +"p2 c -19 4 4 n -1 0 0 t1 0.248047 0.00195312 t2 0.905224 0.614223\n" +"p3 c -19 4 -4 n -1 0 0 t1 0.00195312 0.00195312 t2 0.0947756 0.614223\n" +"mat dif 1 1 1 0 amb 0.5 0.5 0.5 0 spc 0 0 0 0\n" +"tex1 derrick.png\n" +"tex2\n" +"var_tex2 Y\n" +"lod_level 1\n" +"state 0\n" +""; + +// Triangles as defined in model file +Gfx::ModelTriangle TRIANGLE_1; +Gfx::ModelTriangle TRIANGLE_2; + +// Sets triangle data +void Init() +{ + + TRIANGLE_1.p1 = Gfx::VertexTex2(Math::Vector(-12.4099, 10.0016, -2.54558), + Math::Vector(1, 0, 1.87319e-07), + Math::Point(0.970703, 0.751953), + Math::Point(0, 0)); + TRIANGLE_1.p2 = Gfx::VertexTex2(Math::Vector(-12.4099, 10.0016, 2.54558), + Math::Vector(1, 0, 1.87319e-07), + Math::Point(0.998047, 0.751953), + Math::Point(0, 0)); + TRIANGLE_1.p3 = Gfx::VertexTex2(Math::Vector(-12.4099, 4.00165, -2.54558), + Math::Vector(1, 0, 1.87319e-07), + Math::Point(0.970703, 0.998047), + Math::Point(0, 0)); + TRIANGLE_1.material.diffuse = Gfx::Color(1, 1, 1, 0); + TRIANGLE_1.material.ambient = Gfx::Color(0.5, 0.5, 0.5, 0); + TRIANGLE_1.material.specular = Gfx::Color(0, 0, 0, 0); + TRIANGLE_1.tex1Name = "lemt.png"; + TRIANGLE_1.variableTex2 = false; + TRIANGLE_1.lodLevel = Gfx::LOD_Constant; + TRIANGLE_1.state = 1024; + + TRIANGLE_2.p1 = Gfx::VertexTex2(Math::Vector(-19, -1, 4), + Math::Vector(-1, 0, 0), + Math::Point(0.248047, 0.123047), + Math::Point(0.905224, 0.52067)); + TRIANGLE_2.p2 = Gfx::VertexTex2(Math::Vector(-19, 4, 4), + Math::Vector(-1, 0, 0), + Math::Point(0.248047, 0.00195312), + Math::Point(0.905224, 0.614223)); + TRIANGLE_2.p3 = Gfx::VertexTex2(Math::Vector(-19, 4, -4), + Math::Vector(-1, 0, 0), + Math::Point(0.00195312, 0.00195312), + Math::Point(0.0947756, 0.614223)); + TRIANGLE_2.material.diffuse = Gfx::Color(1, 1, 1, 0); + TRIANGLE_2.material.ambient = Gfx::Color(0.5, 0.5, 0.5, 0); + TRIANGLE_2.material.specular = Gfx::Color(0, 0, 0, 0); + TRIANGLE_2.tex1Name = "derrick.png"; + TRIANGLE_2.variableTex2 = true; + TRIANGLE_2.lodLevel = Gfx::LOD_Low; + TRIANGLE_2.state = 0; +} + + +// Compares vertices (within Math::TOLERANCE) +bool CompareVertices(const Gfx::VertexTex2& v1, const Gfx::VertexTex2& v2) +{ + if ( !( Math::IsEqual(v1.coord.x, v2.coord.x) && + Math::IsEqual(v1.coord.y, v2.coord.y) && + Math::IsEqual(v1.coord.z, v2.coord.z) ) ) + return false; + + if ( !( Math::IsEqual(v1.normal.x, v2.normal.x) && + Math::IsEqual(v1.normal.y, v2.normal.y) && + Math::IsEqual(v1.normal.z, v2.normal.z) ) ) + return false; + + if ( !( Math::IsEqual(v1.texCoord.x, v2.texCoord.x) && + Math::IsEqual(v1.texCoord.y, v2.texCoord.y) ) ) + return false; + + if ( !( Math::IsEqual(v1.texCoord2.x, v2.texCoord2.x) && + Math::IsEqual(v1.texCoord2.y, v2.texCoord2.y) ) ) + return false; + + return true; +} + +// Compares colors (within Math::TOLERANCE) +bool CompareColors(const Gfx::Color& c1, const Gfx::Color& c2) +{ + return Math::IsEqual(c1.r, c2.r) && + Math::IsEqual(c1.g, c2.g) && + Math::IsEqual(c1.b, c2.b) && + Math::IsEqual(c1.a, c2.a); +} + +// Compares model triangles (within Math::TOLERANCE) +bool CompareTriangles(const Gfx::ModelTriangle& t1, const Gfx::ModelTriangle& t2) +{ + if (! CompareVertices(t1.p1, t2.p1)) + return false; + + if (! CompareVertices(t1.p2, t2.p2)) + return false; + + if (! CompareVertices(t1.p3, t2.p3)) + return false; + + if (! CompareColors(t1.material.diffuse, t2.material.diffuse)) + return false; + + if (! CompareColors(t1.material.ambient, t2.material.ambient)) + return false; + + if (! CompareColors(t1.material.specular, t2.material.specular)) + return false; + + if (t1.tex1Name != t2.tex1Name) + return false; + + if (t1.tex2Name != t2.tex2Name) + return false; + + if (t1.variableTex2 != t2.variableTex2) + return false; + + if (t1.lodLevel != t2.lodLevel) + return false; + + if (t1.state != t2.state) + return false; + + return true; +} + +// Tests reading/writing new text model file +TEST(ModelFileTest, RWTxtModel) +{ + std::stringstream str; + str.str(TEXT_MODEL); + + Gfx::CModelFile modelFile; + + EXPECT_TRUE(modelFile.ReadTextModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); + + str.str(""); + + EXPECT_TRUE(modelFile.WriteTextModel(str)); + str.seekg(0); + EXPECT_TRUE(modelFile.ReadTextModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); +} + +// Tests reading/writing new binary model +TEST(ModelFileTest, RWBinModel) +{ + std::stringstream str; + str.str(TEXT_MODEL); + + Gfx::CModelFile modelFile; + + EXPECT_TRUE(modelFile.ReadTextModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); + + str.str(""); + + EXPECT_TRUE(modelFile.WriteBinaryModel(str)); + str.seekg(0); + EXPECT_TRUE(modelFile.ReadBinaryModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); +} + +// Tests reading/writing old model file +TEST(ModelFileTest, RWOldModel) +{ + std::stringstream str; + str.str(TEXT_MODEL); + + Gfx::CModelFile modelFile; + + EXPECT_TRUE(modelFile.ReadTextModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); + + str.str(""); + + EXPECT_TRUE(modelFile.WriteModel(str)); + str.seekg(0); + EXPECT_TRUE(modelFile.ReadModel(str)); + + EXPECT_EQ(modelFile.GetTriangleCount(), 2); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); + EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); +} diff --git a/test/unit/main.cpp b/test/unit/main.cpp index e978630..7d08f58 100644 --- a/test/unit/main.cpp +++ b/test/unit/main.cpp @@ -14,10 +14,14 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -#include "gtest/gtest.h" +#include "common/logger.h" + +#include <gtest/gtest.h> int main(int argc, char* argv[]) { + CLogger logger; + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/unit/math/func_test.cpp b/test/unit/math/func_test.cpp new file mode 100644 index 0000000..57f1347 --- /dev/null +++ b/test/unit/math/func_test.cpp @@ -0,0 +1,39 @@ +/* + Unit tests for math functions. + */ + +#include "math/func.h" + +#include <gtest/gtest.h> + + +TEST(IsPowerOfTwo, TestDifferentValues) +{ + EXPECT_FALSE(Math::IsPowerOfTwo(0)); + EXPECT_TRUE(Math::IsPowerOfTwo(1)); + EXPECT_TRUE(Math::IsPowerOfTwo(2)); + EXPECT_FALSE(Math::IsPowerOfTwo(3)); + EXPECT_TRUE(Math::IsPowerOfTwo(4)); + + EXPECT_FALSE(Math::IsPowerOfTwo(31)); + EXPECT_TRUE(Math::IsPowerOfTwo(32)); + EXPECT_FALSE(Math::IsPowerOfTwo(33)); + + EXPECT_FALSE(Math::IsPowerOfTwo(1234)); +} + +TEST(NextPowerOfTwo, TestDifferentValues) +{ + EXPECT_EQ(2, Math::NextPowerOfTwo(2)); + EXPECT_EQ(4, Math::NextPowerOfTwo(3)); + EXPECT_EQ(4, Math::NextPowerOfTwo(4)); + EXPECT_EQ(8, Math::NextPowerOfTwo(5)); + + EXPECT_EQ(8, Math::NextPowerOfTwo(7)); + EXPECT_EQ(8, Math::NextPowerOfTwo(8)); + EXPECT_EQ(16, Math::NextPowerOfTwo(9)); + + EXPECT_EQ(32, Math::NextPowerOfTwo(31)); + EXPECT_EQ(32, Math::NextPowerOfTwo(32)); + EXPECT_EQ(64, Math::NextPowerOfTwo(33)); +} diff --git a/test/unit/math/geometry_test.cpp b/test/unit/math/geometry_test.cpp index 7c3e26a..581ef89 100644 --- a/test/unit/math/geometry_test.cpp +++ b/test/unit/math/geometry_test.cpp @@ -1,25 +1,9 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - /* Unit tests for functions in geometry.h */ #include "math/func.h" #include "math/geometry.h" -#include "gtest/gtest.h" +#include <gtest/gtest.h> const float TEST_TOLERANCE = 1e-5; diff --git a/test/unit/math/matrix_test.cpp b/test/unit/math/matrix_test.cpp index 5f5c3af..7693a85 100644 --- a/test/unit/math/matrix_test.cpp +++ b/test/unit/math/matrix_test.cpp @@ -1,19 +1,3 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - /* Unit tests for Matrix struct @@ -24,7 +8,7 @@ #include "math/func.h" #include "math/matrix.h" -#include "gtest/gtest.h" +#include <gtest/gtest.h> const float TEST_TOLERANCE = 1e-6; diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp index 41bac74..6fe30be 100644 --- a/test/unit/math/vector_test.cpp +++ b/test/unit/math/vector_test.cpp @@ -1,19 +1,3 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - /* Unit tests for Vector struct @@ -24,7 +8,7 @@ #include "math/func.h" #include "math/vector.h" -#include "gtest/gtest.h" +#include <gtest/gtest.h> const float TEST_TOLERANCE = 1e-6; diff --git a/test/unit/ui/CMakeLists.txt b/test/unit/ui/CMakeLists.txt index c899834..c18af87 100644 --- a/test/unit/ui/CMakeLists.txt +++ b/test/unit/ui/CMakeLists.txt @@ -5,15 +5,18 @@ include_directories( ${SRC_DIR} ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} +${CLIPBOARD_INCLUDE_DIR} ) # Platform-dependent implementation of CSystemUtils -if (${PLATFORM_WINDOWS}) +if(PLATFORM_WINDOWS) set(SYSTEM_CPP_MODULE "system_windows.cpp") -elseif(${PLATFORM_LINUX}) +elseif(PLATFORM_LINUX) set(SYSTEM_CPP_MODULE "system_linux.cpp") + set(ADDITIONAL_LIB "-lX11") else() set(SYSTEM_CPP_MODULE "system_other.cpp") + set(ADDITIONAL_LIB "-lX11") endif() add_executable(edit_test @@ -36,6 +39,9 @@ stubs/particle_stub.cpp stubs/restext_stub.cpp stubs/robotmain_stub.cpp edit_test.cpp) -target_link_libraries(edit_test gtest gmock ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES}) + +target_link_libraries(edit_test gtest gmock clipboard ${SDL_LIBRARY} ${SDLTTF_LIBRARY} ${Boost_LIBRARIES} ${ADDITIONAL_LIB}) + + add_test(edit_test ./edit_test) diff --git a/test/unit/ui/edit_test.cpp b/test/unit/ui/edit_test.cpp index 428b66a..21af00f 100644 --- a/test/unit/ui/edit_test.cpp +++ b/test/unit/ui/edit_test.cpp @@ -1,10 +1,13 @@ #include "app/app.h" + #include "ui/edit.h" + #include "mocks/text_mock.h" +#include <fstream> + #include <gtest/gtest.h> #include <gmock/gmock.h> -#include <fstream> class CEditTest : public testing::Test { @@ -17,7 +20,7 @@ public: virtual void SetUp() { - m_robotMain = new CRobotMain(&m_app); + m_robotMain = new CRobotMain(&m_app, false); m_engine = new Gfx::CEngine(nullptr); diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp index 9b33e5e..960972f 100644 --- a/test/unit/ui/stubs/app_stub.cpp +++ b/test/unit/ui/stubs/app_stub.cpp @@ -21,7 +21,7 @@ CApplication::~CApplication() { } -std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) +std::string CApplication::GetDataFilePath(DataDir /* dataDir */, const std::string& subpath) const { return subpath; } @@ -36,7 +36,7 @@ CEventQueue* CApplication::GetEventQueue() return nullptr; } -std::string CApplication::GetDataDirPath() +std::string CApplication::GetDataDirPath() const { return ""; } @@ -46,7 +46,7 @@ Event CApplication::CreateUpdateEvent() return Event(EVENT_NULL); } -char CApplication::GetLanguageChar() +char CApplication::GetLanguageChar() const { return 'E'; } diff --git a/test/unit/ui/stubs/robotmain_stub.cpp b/test/unit/ui/stubs/robotmain_stub.cpp index 7988e9d..692f67f 100644 --- a/test/unit/ui/stubs/robotmain_stub.cpp +++ b/test/unit/ui/stubs/robotmain_stub.cpp @@ -3,7 +3,7 @@ template<> CRobotMain* CSingleton<CRobotMain>::m_instance = nullptr; -CRobotMain::CRobotMain(CApplication* app) +CRobotMain::CRobotMain(CApplication* app, bool loadProfile) { } |