summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-03-24 00:03:37 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-03-24 12:00:12 +0100
commit195d6cded05f7ef5bde695ee047b341a0265eab3 (patch)
treeaf6ffa3622ae9bf7f2f5f065e269e86a019af854 /test
parentc211b001d2a4c9b36034a812650f1a2ac693ee54 (diff)
downloadcolobot-195d6cded05f7ef5bde695ee047b341a0265eab3.tar.gz
colobot-195d6cded05f7ef5bde695ee047b341a0265eab3.tar.bz2
colobot-195d6cded05f7ef5bde695ee047b341a0265eab3.zip
Fixed timer functions on win32
* changed win32 implementation to QueryPerformaceTimer system function * refactored system utils code * proper tests for time utils and update event creation in application * should fix issue #134
Diffstat (limited to 'test')
-rw-r--r--test/envs/opengl/CMakeLists.txt4
-rw-r--r--test/envs/opengl/light_test.cpp18
-rw-r--r--test/envs/opengl/model_test.cpp18
-rw-r--r--test/envs/opengl/transform_test.cpp18
-rw-r--r--test/unit/CMakeLists.txt13
-rw-r--r--test/unit/app/app_test.cpp320
-rw-r--r--test/unit/app/system_linux_test.cpp29
-rw-r--r--test/unit/app/system_mock.h48
-rw-r--r--test/unit/app/system_windows_test.cpp62
-rw-r--r--test/unit/graphics/engine/lightman_test.cpp6
-rw-r--r--test/unit/ui/stubs/app_stub.cpp5
11 files changed, 496 insertions, 45 deletions
diff --git a/test/envs/opengl/CMakeLists.txt b/test/envs/opengl/CMakeLists.txt
index d6c3a37..0bcb43d 100644
--- a/test/envs/opengl/CMakeLists.txt
+++ b/test/envs/opengl/CMakeLists.txt
@@ -3,9 +3,9 @@ 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")
+if (${PLATFORM_WINDOWS})
set(SYSTEM_CPP_MODULE "system_windows.cpp")
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+elseif(${PLATFORM_LINUX})
set(SYSTEM_CPP_MODULE "system_linux.cpp")
else()
set(SYSTEM_CPP_MODULE "system_other.cpp")
diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp
index d4635cc..0baf6d3 100644
--- a/test/envs/opengl/light_test.cpp
+++ b/test/envs/opengl/light_test.cpp
@@ -258,9 +258,9 @@ void Update()
{
const float TRANS_SPEED = 6.0f; // units / sec
- GetCurrentTimeStamp(CURR_TIME);
- float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
- CopyTimeStamp(PREV_TIME, CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
+ float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
+ GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME);
CUBE_ORBIT += timeDiff * (Math::PI / 4.0f);
@@ -365,11 +365,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger;
- PREV_TIME = CreateTimeStamp();
- CURR_TIME = CreateTimeStamp();
+ PREV_TIME = GetSystemUtils()->CreateTimeStamp();
+ CURR_TIME = GetSystemUtils()->CreateTimeStamp();
- GetCurrentTimeStamp(PREV_TIME);
- GetCurrentTimeStamp(CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
// Without any error checking, for simplicity
@@ -459,8 +459,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
SDL_Quit();
- DestroyTimeStamp(PREV_TIME);
- DestroyTimeStamp(CURR_TIME);
+ GetSystemUtils()->DestroyTimeStamp(PREV_TIME);
+ GetSystemUtils()->DestroyTimeStamp(CURR_TIME);
return 0;
}
diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp
index 168eb32..1dda69c 100644
--- a/test/envs/opengl/model_test.cpp
+++ b/test/envs/opengl/model_test.cpp
@@ -153,9 +153,9 @@ void Update()
const float ROT_SPEED = 80.0f * Math::DEG_TO_RAD; // rad / sec
const float TRANS_SPEED = 3.0f; // units / sec
- GetCurrentTimeStamp(CURR_TIME);
- float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
- CopyTimeStamp(PREV_TIME, CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
+ float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
+ GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME);
if (KEYMAP[K_RotYLeft])
ROTATION.y -= ROT_SPEED * timeDiff;
@@ -265,11 +265,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger;
- PREV_TIME = CreateTimeStamp();
- CURR_TIME = CreateTimeStamp();
+ PREV_TIME = GetSystemUtils()->CreateTimeStamp();
+ CURR_TIME = GetSystemUtils()->CreateTimeStamp();
- GetCurrentTimeStamp(PREV_TIME);
- GetCurrentTimeStamp(CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
if (argc != 3)
{
@@ -377,8 +377,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
SDL_Quit();
- DestroyTimeStamp(PREV_TIME);
- DestroyTimeStamp(CURR_TIME);
+ GetSystemUtils()->DestroyTimeStamp(PREV_TIME);
+ GetSystemUtils()->DestroyTimeStamp(CURR_TIME);
return 0;
}
diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp
index 02f9d83..1d5ccf1 100644
--- a/test/envs/opengl/transform_test.cpp
+++ b/test/envs/opengl/transform_test.cpp
@@ -138,9 +138,9 @@ void Update()
{
const float TRANS_SPEED = 6.0f; // units / sec
- GetCurrentTimeStamp(CURR_TIME);
- float timeDiff = TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
- CopyTimeStamp(PREV_TIME, CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
+ float timeDiff = GetSystemUtils()->TimeStampDiff(PREV_TIME, CURR_TIME, STU_SEC);
+ GetSystemUtils()->CopyTimeStamp(PREV_TIME, CURR_TIME);
Math::Vector incTrans;
@@ -243,11 +243,11 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger;
- PREV_TIME = CreateTimeStamp();
- CURR_TIME = CreateTimeStamp();
+ PREV_TIME = GetSystemUtils()->CreateTimeStamp();
+ CURR_TIME = GetSystemUtils()->CreateTimeStamp();
- GetCurrentTimeStamp(PREV_TIME);
- GetCurrentTimeStamp(CURR_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME);
+ GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME);
// Without any error checking, for simplicity
@@ -337,8 +337,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
SDL_Quit();
- DestroyTimeStamp(PREV_TIME);
- DestroyTimeStamp(CURR_TIME);
+ GetSystemUtils()->DestroyTimeStamp(PREV_TIME);
+ GetSystemUtils()->DestroyTimeStamp(CURR_TIME);
return 0;
}
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index f3be01d..3d8a38c 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -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 (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+if (${PLATFORM_WINDOWS})
set(SYSTEM_CPP_MODULE "system_windows.cpp")
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+elseif(${PLATFORM_LINUX})
set(SYSTEM_CPP_MODULE "system_linux.cpp")
else()
set(SYSTEM_CPP_MODULE "system_other.cpp")
@@ -164,17 +164,16 @@ 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")
+if (${PLATFORM_WINDOWS})
+ set(PLATFORM_TESTS app/system_windows_test.cpp)
+elseif(${PLATFORM_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
+app/app_test.cpp
graphics/engine/lightman_test.cpp
math/geometry_test.cpp
math/matrix_test.cpp
diff --git a/test/unit/app/app_test.cpp b/test/unit/app/app_test.cpp
new file mode 100644
index 0000000..8c1e899
--- /dev/null
+++ b/test/unit/app/app_test.cpp
@@ -0,0 +1,320 @@
+#include "app/app.h"
+
+#if defined(PLATFORM_WINDOWS)
+ #include "app/system_windows.h"
+#elif defined(PLATFORM_LINUX)
+ #include "app/system_linux.h"
+#else
+ #include "app/system_other.h"
+#endif
+
+#include "app/system_mock.h"
+
+#include "common/logger.h"
+
+#include <gtest/gtest.h>
+
+using testing::_;
+using testing::InSequence;
+using testing::Return;
+
+struct FakeSystemTimeStamp : public SystemTimeStamp
+{
+ FakeSystemTimeStamp(int uid) : uid(uid), time(0) {}
+
+ int uid;
+ long long time;
+};
+
+
+class CApplicationWrapper : public CApplication
+{
+public:
+ virtual Event CreateUpdateEvent() override
+ {
+ return CApplication::CreateUpdateEvent();
+ }
+};
+
+class ApplicationUT : public testing::Test
+{
+protected:
+ ApplicationUT();
+
+ virtual void SetUp() override;
+ virtual void TearDown() override;
+
+ void NextInstant(long long diff);
+
+ SystemTimeStamp* CreateTimeStamp();
+ void DestroyTimeStamp(SystemTimeStamp *stamp);
+ void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src);
+ void GetCurrentTimeStamp(SystemTimeStamp *stamp);
+ long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after);
+
+ void TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact,
+ float relTime, float absTime,
+ long long relTimeReal, long long absTimeReal);
+
+protected:
+ CLogger logger;
+ CApplicationWrapper* app;
+ CSystemUtilsMock* systemUtils;
+
+private:
+ int m_stampUid;
+ long long m_currentTime;
+};
+
+ApplicationUT::ApplicationUT()
+ : m_stampUid(0)
+ , m_currentTime(0)
+{}
+
+void ApplicationUT::SetUp()
+{
+ systemUtils = new CSystemUtilsMock();
+
+ ON_CALL(*systemUtils, CreateTimeStamp()).WillByDefault(Invoke(this, &ApplicationUT::CreateTimeStamp));
+ ON_CALL(*systemUtils, DestroyTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::DestroyTimeStamp));
+ ON_CALL(*systemUtils, CopyTimeStamp(_, _)).WillByDefault(Invoke(this, &ApplicationUT::CopyTimeStamp));
+ ON_CALL(*systemUtils, GetCurrentTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::GetCurrentTimeStamp));
+ ON_CALL(*systemUtils, TimeStampExactDiff(_, _)).WillByDefault(Invoke(this, &ApplicationUT::TimeStampExactDiff));
+
+ EXPECT_CALL(*systemUtils, CreateTimeStamp()).Times(3 + PCNT_MAX*2);
+ app = new CApplicationWrapper();
+}
+
+void ApplicationUT::TearDown()
+{
+ EXPECT_CALL(*systemUtils, DestroyTimeStamp(_)).Times(3 + PCNT_MAX*2);
+ delete app;
+ app = nullptr;
+
+ delete systemUtils;
+ systemUtils = nullptr;
+}
+
+SystemTimeStamp* ApplicationUT::CreateTimeStamp()
+{
+ return new FakeSystemTimeStamp(++m_stampUid);
+}
+
+void ApplicationUT::DestroyTimeStamp(SystemTimeStamp *stamp)
+{
+ delete static_cast<FakeSystemTimeStamp*>(stamp);
+}
+
+void ApplicationUT::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
+{
+ *static_cast<FakeSystemTimeStamp*>(dst) = *static_cast<FakeSystemTimeStamp*>(src);
+}
+
+void ApplicationUT::GetCurrentTimeStamp(SystemTimeStamp *stamp)
+{
+ static_cast<FakeSystemTimeStamp*>(stamp)->time = m_currentTime;
+}
+
+long long ApplicationUT::TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after)
+{
+ return static_cast<FakeSystemTimeStamp*>(after)->time - static_cast<FakeSystemTimeStamp*>(before)->time;
+}
+
+void ApplicationUT::NextInstant(long long diff)
+{
+ m_currentTime += diff;
+}
+
+void ApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact,
+ float relTime, float absTime,
+ long long relTimeReal, long long absTimeReal)
+{
+ {
+ InSequence seq;
+ EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _));
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2);
+ }
+
+ Event event = app->CreateUpdateEvent();
+ EXPECT_EQ(EVENT_FRAME, event.type);
+ EXPECT_FLOAT_EQ(relTime, event.rTime);
+ EXPECT_FLOAT_EQ(relTime, app->GetRelTime());
+ EXPECT_FLOAT_EQ(absTime, app->GetAbsTime());
+ EXPECT_EQ(relTimeExact, app->GetExactRelTime());
+ EXPECT_EQ(absTimeExact, app->GetExactAbsTime());
+ EXPECT_EQ(relTimeReal, app->GetRealRelTime());
+ EXPECT_EQ(absTimeReal, app->GetRealAbsTime());
+}
+
+
+TEST_F(ApplicationUT, UpdateEventTimeCalculation_SimulationSuspended)
+{
+ app->SuspendSimulation();
+ Event event = app->CreateUpdateEvent();
+ EXPECT_EQ(EVENT_NULL, event.type);
+}
+
+TEST_F(ApplicationUT, UpdateEventTimeCalculation_NormalOperation)
+{
+ // 1st update
+
+ long long relTimeExact = 1111;
+ long long absTimeExact = relTimeExact;
+ float relTime = relTimeExact / 1e9f;
+ float absTime = absTimeExact / 1e9f;
+ long long relTimeReal = relTimeExact;
+ long long absTimeReal = absTimeExact;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 2nd update
+
+ relTimeExact = 2222;
+ absTimeExact += relTimeExact;
+ relTime = relTimeExact / 1e9f;
+ absTime = absTimeExact / 1e9f;
+ relTimeReal = relTimeExact;
+ absTimeReal = absTimeExact;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+}
+
+TEST_F(ApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation)
+{
+ // 1st update
+
+ long long relTimeExact = 2222;
+ long long absTimeExact = relTimeExact;
+ float relTime = relTimeExact / 1e9f;
+ float absTime = absTimeExact / 1e9f;
+ long long relTimeReal = relTimeExact;
+ long long absTimeReal = absTimeExact;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 2nd update
+
+ NextInstant(-1111);
+
+ {
+ InSequence seq;
+ EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _));
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2);
+ }
+ Event event = app->CreateUpdateEvent();
+ EXPECT_EQ(EVENT_NULL, event.type);
+}
+
+TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed)
+{
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ app->SetSimulationSpeed(2.0f);
+
+ // 1st update -- speed 2x
+
+ long long relTimeReal = 100;
+ long long absTimeReal = relTimeReal;
+ long long relTimeExact = relTimeReal*2;
+ long long absTimeExact = absTimeReal*2;
+ float relTime = relTimeExact / 1e9f;
+ float absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 2nd update -- speed 2x
+
+ relTimeReal = 200;
+ absTimeReal += relTimeReal;
+ relTimeExact = relTimeReal*2;
+ absTimeExact += relTimeReal*2;
+ relTime = relTimeExact / 1e9f;
+ absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 3rd update -- speed 4x
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ app->SetSimulationSpeed(4.0f);
+
+ relTimeReal = 300;
+ absTimeReal += relTimeReal;
+ relTimeExact = relTimeReal*4;
+ absTimeExact += relTimeReal*4;
+ relTime = relTimeExact / 1e9f;
+ absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 4th update -- speed 1x
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ app->SetSimulationSpeed(1.0f);
+
+ relTimeReal = 400;
+ absTimeReal += relTimeReal;
+ relTimeExact = relTimeReal;
+ absTimeExact += relTimeReal;
+ relTime = relTimeExact / 1e9f;
+ absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+}
+
+TEST_F(ApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation)
+{
+ // 1st update -- simulation enabled
+
+ long long relTimeReal = 1000;
+ long long absTimeReal = relTimeReal;
+ long long relTimeExact = relTimeReal;
+ long long absTimeExact = absTimeReal;
+ float relTime = relTimeExact / 1e9f;
+ float absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+
+ // 2nd update -- simulation suspended
+
+ app->SuspendSimulation();
+
+ long long suspensionTime = 5000;
+
+ NextInstant(suspensionTime);
+
+ // 3rd update -- simulation resumed
+
+ {
+ InSequence seq;
+ EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_));
+ EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _));
+ }
+ app->ResumeSimulation();
+
+ relTimeReal = 200;
+ absTimeReal += relTimeReal;
+ relTimeExact = relTimeReal;
+ absTimeExact += relTimeReal;
+ relTime = relTimeExact / 1e9f;
+ absTime = absTimeExact / 1e9f;
+
+ NextInstant(relTimeReal);
+
+ TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal);
+}
diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp
index fe89399..b0a05ca 100644
--- a/test/unit/app/system_linux_test.cpp
+++ b/test/unit/app/system_linux_test.cpp
@@ -3,10 +3,23 @@
#include <gtest/gtest.h>
-TEST(SystemLinuxTest, TimeStampDiff)
+class CSystemUtilsLinuxWrapper : public CSystemUtilsLinux
{
- const long long SEC = 1000000000;
+public:
+ CSystemUtilsLinuxWrapper() {}
+};
+class SystemUtilsLinuxUT : public testing::Test
+{
+protected:
+ static const long long SEC = 1000000000;
+
+ CSystemUtilsLinuxWrapper systemUtils;
+};
+
+
+TEST_F(SystemUtilsLinuxUT, TimeStampDiff)
+{
SystemTimeStamp before, after;
before.clockTime.tv_sec = 1;
@@ -15,10 +28,10 @@ TEST(SystemLinuxTest, TimeStampDiff)
after.clockTime.tv_sec = 1;
after.clockTime.tv_nsec = 900;
- long long tDiff = TimeStampExactDiff_Linux(&before, &after);
+ long long tDiff = systemUtils.TimeStampExactDiff(&before, &after);
EXPECT_EQ( 800, tDiff);
- tDiff = TimeStampExactDiff_Linux(&after, &before);
+ tDiff = systemUtils.TimeStampExactDiff(&after, &before);
EXPECT_EQ(-800, tDiff);
// -------
@@ -29,10 +42,10 @@ TEST(SystemLinuxTest, TimeStampDiff)
after.clockTime.tv_sec = 3;
after.clockTime.tv_nsec = 500;
- tDiff = TimeStampExactDiff_Linux(&before, &after);
+ tDiff = systemUtils.TimeStampExactDiff(&before, &after);
EXPECT_EQ( SEC + 300, tDiff);
- tDiff = TimeStampExactDiff_Linux(&after, &before);
+ tDiff = systemUtils.TimeStampExactDiff(&after, &before);
EXPECT_EQ(-SEC - 300, tDiff);
// -------
@@ -43,9 +56,9 @@ TEST(SystemLinuxTest, TimeStampDiff)
after.clockTime.tv_sec = 4;
after.clockTime.tv_nsec = 100;
- tDiff = TimeStampExactDiff_Linux(&before, &after);
+ tDiff = systemUtils.TimeStampExactDiff(&before, &after);
EXPECT_EQ( SEC - 100, tDiff);
- tDiff = TimeStampExactDiff_Linux(&after, &before);
+ tDiff = systemUtils.TimeStampExactDiff(&after, &before);
EXPECT_EQ(-SEC + 100, tDiff);
}
diff --git a/test/unit/app/system_mock.h b/test/unit/app/system_mock.h
new file mode 100644
index 0000000..470a4e1
--- /dev/null
+++ b/test/unit/app/system_mock.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "app/system.h"
+
+#include <gmock/gmock.h>
+
+class CSystemUtilsMock : public CSystemUtils
+{
+public:
+ CSystemUtilsMock(bool defaultExpects = false)
+ {
+ if (defaultExpects)
+ SetDefaultExpects();
+ }
+
+ virtual ~CSystemUtilsMock() {}
+
+ void SetDefaultExpects()
+ {
+ using testing::_;
+ using testing::Return;
+ using testing::AnyNumber;
+
+ EXPECT_CALL(*this, CreateTimeStamp()).Times(AnyNumber()).WillRepeatedly(Return(nullptr));
+ EXPECT_CALL(*this, DestroyTimeStamp(_)).Times(AnyNumber());
+ EXPECT_CALL(*this, CopyTimeStamp(_, _)).Times(AnyNumber());
+ EXPECT_CALL(*this, GetCurrentTimeStamp(_)).Times(AnyNumber());
+
+ EXPECT_CALL(*this, GetTimeStampResolution(_)).Times(AnyNumber()).WillRepeatedly(Return(0.0f));
+ EXPECT_CALL(*this, GetTimeStampExactResolution()).Times(AnyNumber()).WillRepeatedly(Return(0ll));
+ EXPECT_CALL(*this, TimeStampDiff(_, _, _)).Times(AnyNumber()).WillRepeatedly(Return(0.0f));
+ EXPECT_CALL(*this, TimeStampExactDiff(_, _)).Times(AnyNumber()).WillRepeatedly(Return(0ll));
+ }
+
+ MOCK_METHOD0(Init, void());
+
+ MOCK_METHOD3(SystemDialog, SystemDialogResult(SystemDialogType, const std::string &title, const std::string &message));
+ MOCK_METHOD3(ConsoleSystemDialog, SystemDialogResult(SystemDialogType type, const std::string& title, const std::string& message));
+
+ MOCK_METHOD0(CreateTimeStamp, SystemTimeStamp*());
+ MOCK_METHOD1(DestroyTimeStamp, void (SystemTimeStamp *stamp));
+ MOCK_METHOD2(CopyTimeStamp, void (SystemTimeStamp *dst, SystemTimeStamp *src));
+ MOCK_METHOD1(GetCurrentTimeStamp, void (SystemTimeStamp *stamp));
+ MOCK_METHOD1(GetTimeStampResolution, float (SystemTimeUnit unit));
+ MOCK_METHOD0(GetTimeStampExactResolution, long long());
+ MOCK_METHOD3(TimeStampDiff, float(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit));
+ MOCK_METHOD2(TimeStampExactDiff, long long(SystemTimeStamp *before, SystemTimeStamp *after));
+};
diff --git a/test/unit/app/system_windows_test.cpp b/test/unit/app/system_windows_test.cpp
new file mode 100644
index 0000000..79f8c7f
--- /dev/null
+++ b/test/unit/app/system_windows_test.cpp
@@ -0,0 +1,62 @@
+#include "app/system.h"
+#include "app/system_windows.h"
+
+#include <gtest/gtest.h>
+
+class CSystemUtilsWindowsWrapper : public CSystemUtilsWindows
+{
+public:
+ CSystemUtilsWindowsWrapper() {}
+
+ void SetFrequency(long long counterFrequency)
+ {
+ m_counterFrequency = counterFrequency;
+ }
+};
+
+class SystemUtilsWindowsUT : public testing::Test
+{
+protected:
+ static const long long SEC = 1000000000;
+
+ CSystemUtilsWindowsWrapper systemUtils;
+};
+
+
+TEST_F(SystemUtilsWindowsUT, TimerResolution)
+{
+ systemUtils.SetFrequency(SEC);
+ EXPECT_EQ(1u, systemUtils.GetTimeStampExactResolution());
+
+ systemUtils.SetFrequency(SEC/3);
+ EXPECT_EQ(3u, systemUtils.GetTimeStampExactResolution());
+}
+
+TEST_F(SystemUtilsWindowsUT, TimeStampDiff)
+{
+ systemUtils.SetFrequency(SEC);
+
+ SystemTimeStamp before, after;
+
+ before.counterValue = 100;
+ after.counterValue = 200;
+
+ long long tDiff = systemUtils.TimeStampExactDiff(&before, &after);
+ EXPECT_EQ( 100, tDiff);
+
+ tDiff = systemUtils.TimeStampExactDiff(&after, &before);
+ EXPECT_EQ(-100, tDiff);
+
+ // -------
+
+ systemUtils.SetFrequency(SEC/3);
+
+ before.counterValue = 200;
+ after.counterValue = 400;
+
+ tDiff = systemUtils.TimeStampExactDiff(&before, &after);
+ EXPECT_EQ( 200*3, tDiff);
+
+ tDiff = systemUtils.TimeStampExactDiff(&after, &before);
+ EXPECT_EQ(-200*3, tDiff);
+}
diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp
index c955f0a..e2dc785 100644
--- a/test/unit/graphics/engine/lightman_test.cpp
+++ b/test/unit/graphics/engine/lightman_test.cpp
@@ -1,5 +1,7 @@
#include "graphics/engine/lightman.h"
+#include "app/system_mock.h"
+
#include "graphics/core/device_mock.h"
#include "graphics/engine/engine_mock.h"
@@ -15,7 +17,8 @@ class LightManagerUT : public testing::Test
{
protected:
LightManagerUT()
- : lightManager(&engine)
+ : systemUtils(true)
+ , lightManager(&engine)
{}
void PrepareLightTesting(int maxLights, Math::Vector eyePos);
@@ -25,6 +28,7 @@ protected:
Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType);
+ CSystemUtilsMock systemUtils;
CLightManager lightManager;
CEngineMock engine;
CDeviceMock device;
diff --git a/test/unit/ui/stubs/app_stub.cpp b/test/unit/ui/stubs/app_stub.cpp
index 3df7d42..c8e7bc6 100644
--- a/test/unit/ui/stubs/app_stub.cpp
+++ b/test/unit/ui/stubs/app_stub.cpp
@@ -40,3 +40,8 @@ std::string CApplication::GetDataDirPath()
{
return "";
}
+
+Event CApplication::CreateUpdateEvent()
+{
+ return Event(EVENT_NULL);
+}