From be933ef2241d79558f91796cc5b3a161f72ebf9c Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 19 Oct 2020 00:52:24 +0200 Subject: sync with upstream --- xbmc/utils/test/TestStopwatch.cpp | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 xbmc/utils/test/TestStopwatch.cpp (limited to 'xbmc/utils/test/TestStopwatch.cpp') 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 @@ +/* + * Copyright (C) 2005-2018 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/Thread.h" +#include "utils/Stopwatch.h" + +#include + +class CTestStopWatchThread : public CThread +{ +public: + CTestStopWatchThread() : + CThread("TestStopWatch"){} +}; + +TEST(TestStopWatch, Initialization) +{ + CStopWatch a; + EXPECT_FALSE(a.IsRunning()); + EXPECT_EQ(0.0f, a.GetElapsedSeconds()); + EXPECT_EQ(0.0f, a.GetElapsedMilliseconds()); +} + +TEST(TestStopWatch, Start) +{ + CStopWatch a; + a.Start(); + EXPECT_TRUE(a.IsRunning()); +} + +TEST(TestStopWatch, Stop) +{ + CStopWatch a; + a.Start(); + a.Stop(); + EXPECT_FALSE(a.IsRunning()); +} + +TEST(TestStopWatch, ElapsedTime) +{ + CStopWatch a; + CTestStopWatchThread thread; + a.Start(); + thread.Sleep(1); + EXPECT_GT(a.GetElapsedSeconds(), 0.0f); + EXPECT_GT(a.GetElapsedMilliseconds(), 0.0f); +} + +TEST(TestStopWatch, Reset) +{ + CStopWatch a; + CTestStopWatchThread thread; + a.StartZero(); + thread.Sleep(2); + EXPECT_GT(a.GetElapsedMilliseconds(), 1); + thread.Sleep(3); + a.Reset(); + EXPECT_LT(a.GetElapsedMilliseconds(), 5); +} -- cgit v1.2.3