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 
14 class CTestStopWatchThread : public CThread
15 {
16 public:
CTestStopWatchThread()17   CTestStopWatchThread() :
18     CThread("TestStopWatch"){}
19 };
20 
TEST(TestStopWatch,Initialization)21 TEST(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 
TEST(TestStopWatch,Start)29 TEST(TestStopWatch, Start)
30 {
31   CStopWatch a;
32   a.Start();
33   EXPECT_TRUE(a.IsRunning());
34 }
35 
TEST(TestStopWatch,Stop)36 TEST(TestStopWatch, Stop)
37 {
38   CStopWatch a;
39   a.Start();
40   a.Stop();
41   EXPECT_FALSE(a.IsRunning());
42 }
43 
TEST(TestStopWatch,ElapsedTime)44 TEST(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 
TEST(TestStopWatch,Reset)54 TEST(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 }
65