Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszkax86 committed Apr 17, 2024
1 parent e67f252 commit 0e6130d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
14 changes: 14 additions & 0 deletions colobot-base/src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ bool CApplication::Create()
{
GetLogger()->Info("Creating CApplication");

m_baseTimeStamp = TimeUtils::GetCurrentTimeStamp();
m_lastTimeStamp = m_baseTimeStamp;
m_curTimeStamp = m_baseTimeStamp;

m_errorMessage = m_pathManager->VerifyPaths();
if (!m_errorMessage.empty())
{
Expand Down Expand Up @@ -1620,6 +1624,16 @@ float CApplication::GetSimulationSpeed() const
return m_simulationSpeed;
}

TimeUtils::TimeStamp CApplication::GetBaseTimeStamp() const
{
return m_baseTimeStamp;
}

TimeUtils::TimeStamp CApplication::GetLastTimeStamp() const
{
return m_lastTimeStamp;
}

float CApplication::GetAbsTime() const
{
return m_absTime;
Expand Down
5 changes: 5 additions & 0 deletions colobot-base/src/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class CApplication : public CSingleton<CApplication>
float GetSimulationSpeed() const;
//@}

//! Returns base timestamp
TimeUtils::TimeStamp GetBaseTimeStamp() const;
//! Returns last timestamp
TimeUtils::TimeStamp GetLastTimeStamp() const;

//! Returns the absolute time counter [seconds]
float GetAbsTime() const;
//! Returns the exact absolute time counter [nanoseconds]
Expand Down
33 changes: 19 additions & 14 deletions test/src/app/app_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,26 @@ class CApplicationWrapper : public CApplication
class CApplicationUT : public testing::Test
{
protected:
CApplicationUT() :
m_systemUtils(nullptr),
m_currentTime(0)
{}
CApplicationUT() = default;

~CApplicationUT() noexcept
{}
~CApplicationUT() = default;

void SetUp() override;
void TearDown() override;

void NextInstant(long long diff);

TimeStamp GetCurrentTimeStamp();

void TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact,
float relTime, float absTime,
long long relTimeReal, long long absTimeReal);

protected:
std::unique_ptr<CApplicationWrapper> m_app;
MockRepository m_mocks;
CSystemUtils* m_systemUtils;

private:
long long m_currentTime;
CSystemUtils* m_systemUtils = nullptr;
TimeStamp m_currentTime;
};

void CApplicationUT::SetUp()
Expand All @@ -90,6 +86,8 @@ void CApplicationUT::SetUp()
m_mocks.OnCall(m_systemUtils, CSystemUtils::GetSaveDir).Return("");

m_app = std::make_unique<CApplicationWrapper>(m_systemUtils);

m_currentTime = m_app->GetBaseTimeStamp();
}

void CApplicationUT::TearDown()
Expand All @@ -99,14 +97,19 @@ void CApplicationUT::TearDown()

void CApplicationUT::NextInstant(long long diff)
{
m_currentTime += diff;
m_currentTime += std::chrono::nanoseconds{diff};
}

TimeStamp CApplicationUT::GetCurrentTimeStamp()
{
return m_currentTime;
}

void CApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact,
float relTime, float absTime,
long long relTimeReal, long long absTimeReal)
{
TimeStamp now = TimeUtils::GetCurrentTimeStamp();
TimeStamp now = GetCurrentTimeStamp();
Event event = m_app->CreateUpdateEvent(now);
EXPECT_EQ(EVENT_FRAME, event.type);
EXPECT_FLOAT_EQ(relTime, event.rTime);
Expand All @@ -123,7 +126,7 @@ TEST_F(CApplicationUT, UpdateEventTimeCalculation_SimulationSuspended)
{
m_app->SuspendSimulation();

Event event = m_app->CreateUpdateEvent(TimeUtils::GetCurrentTimeStamp());
Event event = m_app->CreateUpdateEvent(GetCurrentTimeStamp());

EXPECT_EQ(EVENT_NULL, event.type);
}
Expand Down Expand Up @@ -176,7 +179,7 @@ TEST_F(CApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation)

NextInstant(-1111);

Event event = m_app->CreateUpdateEvent(TimeUtils::GetCurrentTimeStamp());
Event event = m_app->CreateUpdateEvent(GetCurrentTimeStamp());
EXPECT_EQ(EVENT_NULL, event.type);
}

Expand Down Expand Up @@ -266,6 +269,8 @@ TEST_F(CApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulatio

m_app->ResumeSimulation();

m_currentTime = m_app->GetBaseTimeStamp();

relTimeReal = 200;
absTimeReal += relTimeReal;
relTimeExact = relTimeReal;
Expand Down

0 comments on commit 0e6130d

Please sign in to comment.