1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* 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>
using namespace std::chrono_literals;
namespace
{
template<typename T = std::chrono::milliseconds>
void CommonTests(XbmcThreads::EndTime<T>& endTime)
{
EXPECT_EQ(100ms, endTime.GetInitialTimeoutValue());
EXPECT_LT(T::zero(), endTime.GetStartTime().time_since_epoch());
EXPECT_FALSE(endTime.IsTimePast());
EXPECT_LT(T::zero(), endTime.GetTimeLeft());
std::this_thread::sleep_for(100ms);
EXPECT_TRUE(endTime.IsTimePast());
EXPECT_EQ(T::zero(), endTime.GetTimeLeft());
endTime.SetInfinite();
EXPECT_GE(T::max(), endTime.GetInitialTimeoutValue());
EXPECT_EQ(XbmcThreads::EndTime<T>::Max(), endTime.GetInitialTimeoutValue());
endTime.SetExpired();
EXPECT_EQ(T::zero(), endTime.GetInitialTimeoutValue());
}
} // namespace
TEST(TestEndTime, DefaultConstructor)
{
XbmcThreads::EndTime<> endTime;
endTime.Set(100ms);
CommonTests(endTime);
}
TEST(TestEndTime, ExplicitConstructor)
{
XbmcThreads::EndTime<> endTime(100ms);
CommonTests(endTime);
}
TEST(TestEndTime, DoubleMicroSeconds)
{
XbmcThreads::EndTime<std::chrono::duration<double, std::micro>> endTime(100ms);
CommonTests(endTime);
}
TEST(TestEndTime, SteadyClockDuration)
{
XbmcThreads::EndTime<std::chrono::steady_clock::duration> endTime(100ms);
CommonTests(endTime);
endTime.SetInfinite();
EXPECT_EQ(std::chrono::steady_clock::duration::max(), endTime.GetInitialTimeoutValue());
endTime.SetExpired();
EXPECT_EQ(std::chrono::steady_clock::duration::zero(), endTime.GetInitialTimeoutValue());
endTime.Set(endTime.Max());
EXPECT_EQ(std::chrono::steady_clock::duration::max(), endTime.GetInitialTimeoutValue());
}
|