2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "threads/SystemClock.h"
11 #include <gtest/gtest.h>
13 using namespace std::chrono_literals
;
18 template<typename T
= std::chrono::milliseconds
>
19 void CommonTests(XbmcThreads::EndTime
<T
>& endTime
)
21 EXPECT_EQ(100ms
, endTime
.GetInitialTimeoutValue());
22 EXPECT_LT(T::zero(), endTime
.GetStartTime().time_since_epoch());
24 EXPECT_FALSE(endTime
.IsTimePast());
25 EXPECT_LT(T::zero(), endTime
.GetTimeLeft());
27 std::this_thread::sleep_for(100ms
);
29 EXPECT_TRUE(endTime
.IsTimePast());
30 EXPECT_EQ(T::zero(), endTime
.GetTimeLeft());
32 endTime
.SetInfinite();
33 EXPECT_GE(T::max(), endTime
.GetInitialTimeoutValue());
34 EXPECT_EQ(XbmcThreads::EndTime
<T
>::Max(), endTime
.GetInitialTimeoutValue());
36 EXPECT_EQ(T::zero(), endTime
.GetInitialTimeoutValue());
41 TEST(TestEndTime
, DefaultConstructor
)
43 XbmcThreads::EndTime
<> endTime
;
49 TEST(TestEndTime
, ExplicitConstructor
)
51 XbmcThreads::EndTime
<> endTime(100ms
);
56 TEST(TestEndTime
, DoubleMicroSeconds
)
58 XbmcThreads::EndTime
<std::chrono::duration
<double, std::micro
>> endTime(100ms
);
63 TEST(TestEndTime
, SteadyClockDuration
)
65 XbmcThreads::EndTime
<std::chrono::steady_clock::duration
> endTime(100ms
);
69 endTime
.SetInfinite();
70 EXPECT_EQ(std::chrono::steady_clock::duration::max(), endTime
.GetInitialTimeoutValue());
73 EXPECT_EQ(std::chrono::steady_clock::duration::zero(), endTime
.GetInitialTimeoutValue());
75 endTime
.Set(endTime
.Max());
76 EXPECT_EQ(std::chrono::steady_clock::duration::max(), endTime
.GetInitialTimeoutValue());