summaryrefslogtreecommitdiffstats
path: root/test/unit/common
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/common')
-rw-r--r--test/unit/common/CMakeLists.txt16
-rw-r--r--test/unit/common/colobot.ini15
-rw-r--r--test/unit/common/image_test.cpp57
-rw-r--r--test/unit/common/profile_test.cpp43
4 files changed, 131 insertions, 0 deletions
diff --git a/test/unit/common/CMakeLists.txt b/test/unit/common/CMakeLists.txt
new file mode 100644
index 0000000..a34c708
--- /dev/null
+++ b/test/unit/common/CMakeLists.txt
@@ -0,0 +1,16 @@
+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})
+
+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)
+target_link_libraries(profile_test gtest ${Boost_LIBRARIES})
+
+add_test(profile_test ./profile_test)
diff --git a/test/unit/common/colobot.ini b/test/unit/common/colobot.ini
new file mode 100644
index 0000000..2ca37ee
--- /dev/null
+++ b/test/unit/common/colobot.ini
@@ -0,0 +1,15 @@
+[test_float]
+float_value=1.5
+
+[test_string]
+string_value=Hello world
+
+[test_int]
+int_value=42
+
+[test_multi]
+entry1=1
+entry2=2
+entry3=3
+entry4=4
+entry5=5
diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp
new file mode 100644
index 0000000..2a8d5e4
--- /dev/null
+++ b/test/unit/common/image_test.cpp
@@ -0,0 +1,57 @@
+#include "common/image.h"
+
+#include <SDL/SDL.h>
+#include <stdio.h>
+
+/* 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
new file mode 100644
index 0000000..e7b64d5
--- /dev/null
+++ b/test/unit/common/profile_test.cpp
@@ -0,0 +1,43 @@
+#include "common/profile.h"
+#include "common/logger.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <gtest/gtest.h>
+
+
+class CProfileTest : public testing::Test
+{
+protected:
+ CLogger m_logger;
+ CProfile m_profile;
+
+};
+
+TEST_F(CProfileTest, ReadTest)
+{
+ ASSERT_TRUE(m_profile.InitCurrentDirectory()); // load colobot.ini file
+
+ std::string result;
+ ASSERT_TRUE(m_profile.GetLocalProfileString("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_EQ(42, int_value);
+
+ float float_value;
+ ASSERT_TRUE(m_profile.GetLocalProfileFloat("test_float", "float_value", float_value));
+ ASSERT_FLOAT_EQ(1.5, float_value);
+
+ std::vector<std::string> list;
+ 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();
+}