summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/test/TestStopwatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/utils/test/TestStopwatch.cpp')
-rw-r--r--xbmc/utils/test/TestStopwatch.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/xbmc/utils/test/TestStopwatch.cpp b/xbmc/utils/test/TestStopwatch.cpp
new file mode 100644
index 0000000..966afc5
--- /dev/null
+++ b/xbmc/utils/test/TestStopwatch.cpp
@@ -0,0 +1,64 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#include "threads/Thread.h"
10#include "utils/Stopwatch.h"
11
12#include <gtest/gtest.h>
13
14class CTestStopWatchThread : public CThread
15{
16public:
17 CTestStopWatchThread() :
18 CThread("TestStopWatch"){}
19};
20
21TEST(TestStopWatch, Initialization)
22{
23 CStopWatch a;
24 EXPECT_FALSE(a.IsRunning());
25 EXPECT_EQ(0.0f, a.GetElapsedSeconds());
26 EXPECT_EQ(0.0f, a.GetElapsedMilliseconds());
27}
28
29TEST(TestStopWatch, Start)
30{
31 CStopWatch a;
32 a.Start();
33 EXPECT_TRUE(a.IsRunning());
34}
35
36TEST(TestStopWatch, Stop)
37{
38 CStopWatch a;
39 a.Start();
40 a.Stop();
41 EXPECT_FALSE(a.IsRunning());
42}
43
44TEST(TestStopWatch, ElapsedTime)
45{
46 CStopWatch a;
47 CTestStopWatchThread thread;
48 a.Start();
49 thread.Sleep(1);
50 EXPECT_GT(a.GetElapsedSeconds(), 0.0f);
51 EXPECT_GT(a.GetElapsedMilliseconds(), 0.0f);
52}
53
54TEST(TestStopWatch, Reset)
55{
56 CStopWatch a;
57 CTestStopWatchThread thread;
58 a.StartZero();
59 thread.Sleep(2);
60 EXPECT_GT(a.GetElapsedMilliseconds(), 1);
61 thread.Sleep(3);
62 a.Reset();
63 EXPECT_LT(a.GetElapsedMilliseconds(), 5);
64}