tests/watchdog: Cleanup our use of durations
We have lots of unnecessary constructors and forced duration casts.
This change makes all of that logic simpler.
Change-Id: Icfc6d51d75dfb67b3b4c252fbc32beeeded299ca
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/watchdog_test.cpp b/test/watchdog_test.cpp
index 8a62cf2..90ec161 100644
--- a/test/watchdog_test.cpp
+++ b/test/watchdog_test.cpp
@@ -100,13 +100,12 @@
EXPECT_TRUE(wdog->enabled(true));
// Sleep for 5 seconds
- auto sleepTime = seconds(5s);
+ auto sleepTime = 5s;
std::this_thread::sleep_for(sleepTime);
// Get the remaining time again and expectation is that we get 25s
auto remaining = milliseconds(wdog->timeRemaining());
- auto expected = defaultInterval -
- duration_cast<milliseconds>(sleepTime);
+ auto expected = defaultInterval - sleepTime;
// Its possible that we are off by few msecs depending on
// how we get scheduled. So checking a range here.
@@ -129,9 +128,9 @@
std::this_thread::sleep_for(1s);
// Next timer will expire in 5 seconds from now.
- auto expireTime = seconds(5s);
- auto newTime = duration_cast<milliseconds>(expireTime);
- wdog->timeRemaining(newTime.count());
+ auto expireTime = 5s;
+ auto expireTimeMs = milliseconds(expireTime).count();
+ EXPECT_EQ(expireTimeMs, wdog->timeRemaining(expireTimeMs));
// Waiting for expiration
EXPECT_EQ(expireTime - 1s, waitForWatchdog(expireTime));
@@ -146,12 +145,12 @@
*/
TEST_F(WdogTest, verifyIntervalUpdateReceived)
{
- auto expireTime = seconds(5s);
- auto newTime = duration_cast<milliseconds>(expireTime);
- wdog->interval(newTime.count());
+ auto expireTime = 5s;
+ auto expireTimeMs = milliseconds(expireTime).count();
+ EXPECT_EQ(expireTimeMs, wdog->interval(expireTimeMs));
// Expect an update in the Interval
- EXPECT_EQ(newTime.count(), wdog->interval());
+ EXPECT_EQ(expireTimeMs, wdog->interval());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -161,8 +160,7 @@
{
// Enable and then verify
EXPECT_TRUE(wdog->enabled(true));
- auto expireTime = duration_cast<seconds>(
- milliseconds(defaultInterval));
+ auto expireTime = duration_cast<seconds>(defaultInterval);
// Waiting default expiration
EXPECT_EQ(expireTime - 1s, waitForWatchdog(expireTime));