From 9946459c0cd65c3b66719a2aefc42c7ab2a29c04 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 9 Aug 2012 23:04:29 +0200 Subject: * changed 0, NULL to nullptr * changed profile.cpp to use SimpleIni to load config files * added new CProfile singleton class for loading config * added SimpleIni to lib/ dir * added config loading tests --- src/common/test/CMakeLists.txt | 10 ++++++++-- src/common/test/colobot.ini | 8 ++++++++ src/common/test/profile_test.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/common/test/colobot.ini create mode 100644 src/common/test/profile_test.cpp (limited to 'src/common/test') diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index 680116c..3adca4e 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -1,6 +1,12 @@ cmake_minimum_required(VERSION 2.8) set(CMAKE_BUILD_TYPE debug) -set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0") +set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0 -std=c++11") -add_executable(image_test ../image.cpp image_test.cpp) +include_directories("../../") +include_directories("../../../") + +#add_executable(image_test ../image.cpp image_test.cpp) +add_executable(profile_test ../profile.cpp profile_test.cpp) + +add_test(profile_test ./profile_test) diff --git a/src/common/test/colobot.ini b/src/common/test/colobot.ini new file mode 100644 index 0000000..c4d2162 --- /dev/null +++ b/src/common/test/colobot.ini @@ -0,0 +1,8 @@ +[test_float] +float_value=1.5 + +[test_string] +string_value=Hello world + +[test_int] +int_value=42 diff --git a/src/common/test/profile_test.cpp b/src/common/test/profile_test.cpp new file mode 100644 index 0000000..3ba0fad --- /dev/null +++ b/src/common/test/profile_test.cpp @@ -0,0 +1,35 @@ +#include "../profile.h" + +#include +#include + +using namespace std; + +int main() +{ + CProfile profile; + profile.InitCurrentDirectory(); // load colobot.ini file + + string result; + profile.GetLocalProfileString("test_string", "string_value", result); + if (result != "Hello world") { + cout << "GetLocalProfileString failed!" << endl; + return 1; + } + + int int_value; + profile.GetLocalProfileInt("test_int", "int_value", int_value); + if (int_value != 42) { + cout << "GetLocalProfileInt failed!" << endl; + return 1; + } + + float float_value; + profile.GetLocalProfileFloat("test_float", "float_value", float_value); + if (float_value != 1.5) { + cout << "GetLocalProfileFloat failed!" << endl; + return 1; + } + + return 0; +} -- cgit v1.2.3-1-g7c22