[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / threads / test / TestEndTime.cpp
blobfb1c6d8606cdf82ade2a90654ea18455d6f94ccd
1 /*
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.
7 */
9 #include "threads/SystemClock.h"
11 #include <gtest/gtest.h>
13 using namespace std::chrono_literals;
15 namespace
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());
35 endTime.SetExpired();
36 EXPECT_EQ(T::zero(), endTime.GetInitialTimeoutValue());
39 } // namespace
41 TEST(TestEndTime, DefaultConstructor)
43 XbmcThreads::EndTime<> endTime;
44 endTime.Set(100ms);
46 CommonTests(endTime);
49 TEST(TestEndTime, ExplicitConstructor)
51 XbmcThreads::EndTime<> endTime(100ms);
53 CommonTests(endTime);
56 TEST(TestEndTime, DoubleMicroSeconds)
58 XbmcThreads::EndTime<std::chrono::duration<double, std::micro>> endTime(100ms);
60 CommonTests(endTime);
63 TEST(TestEndTime, SteadyClockDuration)
65 XbmcThreads::EndTime<std::chrono::steady_clock::duration> endTime(100ms);
67 CommonTests(endTime);
69 endTime.SetInfinite();
70 EXPECT_EQ(std::chrono::steady_clock::duration::max(), endTime.GetInitialTimeoutValue());
72 endTime.SetExpired();
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());