Skip to content

Commit

Permalink
[test] add test for EndTime class
Browse files Browse the repository at this point in the history
  • Loading branch information
lrusak committed Nov 11, 2020
1 parent e872c4b commit 62fb760
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xbmc/threads/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(SOURCES TestEvent.cpp
TestSharedSection.cpp)
TestSharedSection.cpp
TestEndTime.cpp)

set(HEADERS TestHelpers.h)

Expand Down
50 changes: 50 additions & 0 deletions xbmc/threads/test/TestEndTime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2005-2020 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#include "threads/SystemClock.h"

#include <gtest/gtest.h>

namespace
{

void CommonTests(XbmcThreads::EndTime& endTime)
{
EXPECT_EQ(static_cast<unsigned int>(100), endTime.GetInitialTimeoutValue());
EXPECT_LE(static_cast<unsigned int>(0), endTime.GetStartTime());

EXPECT_FALSE(endTime.IsTimePast());
EXPECT_LT(static_cast<unsigned int>(0), endTime.MillisLeft());

std::this_thread::sleep_for(std::chrono::milliseconds(100));

EXPECT_TRUE(endTime.IsTimePast());
EXPECT_EQ(static_cast<unsigned int>(0), endTime.MillisLeft());

endTime.SetInfinite();
EXPECT_EQ(std::numeric_limits<unsigned int>::max(), endTime.GetInitialTimeoutValue());
endTime.SetExpired();
EXPECT_EQ(static_cast<unsigned int>(0), endTime.GetInitialTimeoutValue());
}

} // namespace

TEST(TestEndTime, DefaultConstructor)
{
XbmcThreads::EndTime endTime;
endTime.Set(static_cast<unsigned int>(100));

CommonTests(endTime);
}

TEST(TestEndTime, ExplicitConstructor)
{
XbmcThreads::EndTime endTime(static_cast<unsigned int>(100));

CommonTests(endTime);
}

0 comments on commit 62fb760

Please sign in to comment.