diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/envs/opengl/CMakeLists.txt | 11 | ||||
-rw-r--r-- | test/unit/CMakeLists.txt | 22 | ||||
-rw-r--r-- | test/unit/app/system_linux_test.cpp | 51 |
3 files changed, 84 insertions, 0 deletions
diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt index 3de5466..d6c3a37 100644 --- a/test/envs/opengl/CMakeLists.txt +++ b/test/envs/opengl/CMakeLists.txt @@ -2,6 +2,14 @@ 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 (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() set(TEXTURE_SOURCES ${SRC_DIR}/graphics/opengl/gldevice.cpp @@ -17,6 +25,7 @@ ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/common/stringutils.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} model_test.cpp ) @@ -25,6 +34,7 @@ ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} transform_test.cpp ) @@ -33,6 +43,7 @@ ${SRC_DIR}/graphics/opengl/gldevice.cpp ${SRC_DIR}/common/logger.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} light_test.cpp ) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 575f5c0..34027b8 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,10 +15,20 @@ endif() # Configure file configure_file(${SRC_DIR}/common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) +# Platform-dependent implementation of system.h +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(SYSTEM_CPP_MODULE "system_windows.cpp") +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(SYSTEM_CPP_MODULE "system_linux.cpp") +else() + set(SYSTEM_CPP_MODULE "system_other.cpp") +endif() + # Code sources set(COLOBOT_SOURCES ${SRC_DIR}/app/app.cpp ${SRC_DIR}/app/system.cpp +${SRC_DIR}/app/${SYSTEM_CPP_MODULE} ${SRC_DIR}/common/event.cpp ${SRC_DIR}/common/image.cpp ${SRC_DIR}/common/iman.cpp @@ -159,12 +169,24 @@ if (${OPENAL_SOUND}) endif() endif() + +# Platform-dependent tests +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + #TODO: set(PLATFORM_TESTS app/system_windows_test.cpp) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(PLATFORM_TESTS app/system_linux_test.cpp) +else() + #TODO: set(PLATFORM_TESTS app/system_other_test.cpp) +endif() + +# Tests set(UT_SOURCES main.cpp graphics/engine/lightman_test.cpp math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp +${PLATFORM_TESTS} ) include_directories( diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp new file mode 100644 index 0000000..fe89399 --- /dev/null +++ b/test/unit/app/system_linux_test.cpp @@ -0,0 +1,51 @@ +#include "app/system.h" +#include "app/system_linux.h" + +#include <gtest/gtest.h> + +TEST(SystemLinuxTest, TimeStampDiff) +{ + const long long SEC = 1000000000; + + SystemTimeStamp before, after; + + before.clockTime.tv_sec = 1; + before.clockTime.tv_nsec = 100; + + after.clockTime.tv_sec = 1; + after.clockTime.tv_nsec = 900; + + long long tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( 800, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-800, tDiff); + + // ------- + + before.clockTime.tv_sec = 2; + before.clockTime.tv_nsec = 200; + + after.clockTime.tv_sec = 3; + after.clockTime.tv_nsec = 500; + + tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( SEC + 300, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-SEC - 300, tDiff); + + // ------- + + before.clockTime.tv_sec = 3; + before.clockTime.tv_nsec = 200; + + after.clockTime.tv_sec = 4; + after.clockTime.tv_nsec = 100; + + tDiff = TimeStampExactDiff_Linux(&before, &after); + EXPECT_EQ( SEC - 100, tDiff); + + tDiff = TimeStampExactDiff_Linux(&after, &before); + EXPECT_EQ(-SEC + 100, tDiff); +} |