From 74312b0405d6fb5ed75c675ceed471e1e5086f00 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 20:03:56 +0200 Subject: Better CMake organization and unit test cleanups * created a static library containing most source modules to avoid compiling source modules twice in code and unit tests * moved profile_test to main unit tests executable * removed image_test and edit_test as not really useful --- test/unit/common/CMakeLists.txt | 21 --------------- test/unit/common/image_test.cpp | 57 --------------------------------------- test/unit/common/profile_test.cpp | 9 ++----- 3 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 test/unit/common/CMakeLists.txt delete mode 100644 test/unit/common/image_test.cpp (limited to 'test/unit/common') diff --git a/test/unit/common/CMakeLists.txt b/test/unit/common/CMakeLists.txt deleted file mode 100644 index cf37961..0000000 --- a/test/unit/common/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -set(SRC_DIR ${colobot_SOURCE_DIR}/src) - -include_directories( -${SRC_DIR} -${GTEST_INCLUDE_DIR} -) - -add_executable(image_test ${SRC_DIR}/common/image.cpp image_test.cpp) -target_link_libraries(image_test ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${PNG_LIBRARIES}) -add_test(NAME image_test - COMMAND ${CMAKE_BINARY_DIR}/image_test ${CMAKE_SOURCE_DIR}/test/envs/opengl/tex1.png ${CMAKE_BINARY_DIR}/tex1_test.png) - -file(COPY colobot.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - -add_executable(profile_test ${SRC_DIR}/common/profile.cpp ${SRC_DIR}/common/logger.cpp profile_test.cpp) -set_target_properties(profile_test PROPERTIES COMPILE_DEFINITIONS "DEV_BUILD=1") -target_link_libraries(profile_test gtest ${Boost_LIBRARIES}) - -add_test(NAME profile_test - COMMAND ${CMAKE_BINARY_DIR}/profile_test - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp deleted file mode 100644 index 2b20a17..0000000 --- a/test/unit/common/image_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "common/image.h" - -#include -#include - -/* For now, just a simple test: loading a file from image - * and saving it to another in PNG. */ - -int main(int argc, char *argv[]) -{ - if (argc != 3) - { - printf("Usage: %s in_image out_image\n", argv[0]); - return 0; - } - - CImage image; - - if (! image.Load(argv[1])) - { - std::string err = image.GetError(); - printf("Error loading '%s': %s\n", argv[1], err.c_str()); - return 1; - } - Gfx::Color color; - std::string str; - - color = image.GetPixel(Math::IntPoint(0, 0)); - str = color.ToString(); - printf("pixel @ (0,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(0, 1)); - str = color.ToString(); - printf("pixel @ (0,1): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 0)); - str = color.ToString(); - printf("pixel @ (1,0): %s\n", str.c_str()); - - color = image.GetPixel(Math::IntPoint(1, 1)); - str = color.ToString(); - printf("pixel @ (1,1): %s\n", str.c_str()); - - image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f)); - image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f)); - image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); - image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)); - - if (! image.SavePNG(argv[2])) - { - std::string err = image.GetError(); - printf("Error saving PNG '%s': %s\n", argv[2], err.c_str()); - return 2; - } - - return 0; -} diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp index dabcba6..1a4f239 100644 --- a/test/unit/common/profile_test.cpp +++ b/test/unit/common/profile_test.cpp @@ -11,13 +11,14 @@ class CProfileTest : public testing::Test { protected: - CLogger m_logger; CProfile m_profile; }; TEST_F(CProfileTest, ReadTest) { + m_profile.SetUseLocalDirectory(true); + ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file std::string result; @@ -36,9 +37,3 @@ TEST_F(CProfileTest, ReadTest) list = m_profile.GetLocalProfileSection("test_multi", "entry"); ASSERT_EQ(5u, list.size()); } - -int main(int argc, char *argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -- cgit v1.2.3-1-g7c22 From e4d52d9afbf6aeb090b225cc4852936dd3be5017 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 12 Aug 2014 21:24:33 +0200 Subject: CProfile refactoring --- test/unit/common/profile_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/unit/common') diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp index 1a4f239..2d21a90 100644 --- a/test/unit/common/profile_test.cpp +++ b/test/unit/common/profile_test.cpp @@ -17,23 +17,23 @@ protected: TEST_F(CProfileTest, ReadTest) { - m_profile.SetUseLocalDirectory(true); + m_profile.SetUseCurrentDirectory(true); - ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file + ASSERT_TRUE(m_profile.Init()); // load colobot.ini file std::string result; - ASSERT_TRUE(m_profile.GetLocalProfileString("test_string", "string_value", result)); + ASSERT_TRUE(m_profile.GetStringProperty("test_string", "string_value", result)); ASSERT_STREQ("Hello world", result.c_str()); int int_value; - ASSERT_TRUE(m_profile.GetLocalProfileInt("test_int", "int_value", int_value)); + ASSERT_TRUE(m_profile.GetIntProperty("test_int", "int_value", int_value)); ASSERT_EQ(42, int_value); float float_value; - ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value)); + ASSERT_TRUE(m_profile.GetFloatProperty("test_float", "float_value", float_value)); ASSERT_FLOAT_EQ(1.5, float_value); std::vector list; - list = m_profile.GetLocalProfileSection("test_multi", "entry"); + list = m_profile.GetSection("test_multi", "entry"); ASSERT_EQ(5u, list.size()); } -- cgit v1.2.3-1-g7c22