test/watchdog: Use a unique_ptr for the watchdog

This lets us change out the watchdog with a watchdog constructed using
different parameters. Currently this functionality is not used, but it
is needed for a future change.

Change-Id: Ie1e7fbf2c7fc8bf2949237f2535177ecd46944a0
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/watchdog_test.cpp b/test/watchdog_test.cpp
index a76a914..f846532 100644
--- a/test/watchdog_test.cpp
+++ b/test/watchdog_test.cpp
@@ -5,27 +5,27 @@
 /** @brief Make sure that watchdog is started and not enabled */
 TEST_F(WdogTest, createWdogAndDontEnable)
 {
-    EXPECT_FALSE(wdog.enabled());
-    EXPECT_EQ(0, wdog.timeRemaining());
-    EXPECT_FALSE(wdog.timerExpired());
+    EXPECT_FALSE(wdog->enabled());
+    EXPECT_EQ(0, wdog->timeRemaining());
+    EXPECT_FALSE(wdog->timerExpired());
 }
 
 /** @brief Make sure that watchdog is started and enabled */
 TEST_F(WdogTest, createWdogAndEnable)
 {
     // Enable and then verify
-    EXPECT_TRUE(wdog.enabled(true));
-    EXPECT_FALSE(wdog.timerExpired());
+    EXPECT_TRUE(wdog->enabled(true));
+    EXPECT_FALSE(wdog->timerExpired());
 
     // Get the configured interval
-    auto remaining = milliseconds(wdog.timeRemaining());
+    auto remaining = milliseconds(wdog->timeRemaining());
 
     // Its possible that we are off by few msecs depending on
     // how we get scheduled. So checking a range here.
     EXPECT_TRUE((remaining >= defaultInterval - defaultDrift) &&
                 (remaining <= defaultInterval));
 
-    EXPECT_FALSE(wdog.timerExpired());
+    EXPECT_FALSE(wdog->timerExpired());
 }
 
 /** @brief Make sure that watchdog is started and enabled.
@@ -34,12 +34,12 @@
 TEST_F(WdogTest, createWdogAndEnableThenDisable)
 {
     // Enable and then verify
-    EXPECT_TRUE(wdog.enabled(true));
+    EXPECT_TRUE(wdog->enabled(true));
 
     // Disable and then verify
-    EXPECT_FALSE(wdog.enabled(false));
-    EXPECT_FALSE(wdog.enabled());
-    EXPECT_EQ(0, wdog.timeRemaining());
+    EXPECT_FALSE(wdog->enabled(false));
+    EXPECT_FALSE(wdog->enabled());
+    EXPECT_EQ(0, wdog->timeRemaining());
 }
 
 /** @brief Make sure that watchdog is started and enabled.
@@ -49,14 +49,14 @@
 TEST_F(WdogTest, enableWdogAndWait5Seconds)
 {
     // Enable and then verify
-    EXPECT_TRUE(wdog.enabled(true));
+    EXPECT_TRUE(wdog->enabled(true));
 
     // Sleep for 5 seconds
     auto sleepTime = seconds(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 remaining = milliseconds(wdog->timeRemaining());
     auto expected = defaultInterval -
                     duration_cast<milliseconds>(sleepTime);
 
@@ -64,7 +64,7 @@
     // how we get scheduled. So checking a range here.
     EXPECT_TRUE((remaining >= expected - defaultDrift) &&
                 (remaining <= expected));
-    EXPECT_FALSE(wdog.timerExpired());
+    EXPECT_FALSE(wdog->timerExpired());
 }
 
 /** @brief Make sure that watchdog is started and enabled.
@@ -74,7 +74,7 @@
 TEST_F(WdogTest, enableWdogAndResetTo5Seconds)
 {
     // Enable and then verify
-    EXPECT_TRUE(wdog.enabled(true));
+    EXPECT_TRUE(wdog->enabled(true));
 
     // Sleep for 1 second
     std::this_thread::sleep_for(1s);
@@ -82,11 +82,11 @@
     // Next timer will expire in 5 seconds from now.
     auto expireTime = seconds(5s);
     auto newTime = duration_cast<milliseconds>(expireTime);
-    wdog.timeRemaining(newTime.count());
+    wdog->timeRemaining(newTime.count());
 
     // Waiting for expiration
     int count = 0;
-    while(count < expireTime.count() && !wdog.timerExpired())
+    while(count < expireTime.count() && !wdog->timerExpired())
     {
         // Returns -0- on timeout and positive number on dispatch
         auto sleepTime = duration_cast<microseconds>(seconds(1s));
@@ -95,7 +95,7 @@
             count++;
         }
     }
-    EXPECT_TRUE(wdog.timerExpired());
+    EXPECT_TRUE(wdog->timerExpired());
     EXPECT_EQ(expireTime.count() - 1 , count);
 
     // Make sure secondary callback was not called.
@@ -108,10 +108,10 @@
 {
     auto expireTime = seconds(5s);
     auto newTime = duration_cast<milliseconds>(expireTime);
-    wdog.interval(newTime.count());
+    wdog->interval(newTime.count());
 
     // Expect an update in the Interval
-    EXPECT_EQ(newTime.count(), wdog.interval());
+    EXPECT_EQ(newTime.count(), wdog->interval());
 }
 
 /** @brief Make sure that watchdog is started and enabled.
@@ -120,13 +120,13 @@
 TEST_F(WdogTest, enableWdogAndWaitTillEnd)
 {
     // Enable and then verify
-    EXPECT_TRUE(wdog.enabled(true));
+    EXPECT_TRUE(wdog->enabled(true));
     auto expireTime = duration_cast<seconds>(
                         milliseconds(defaultInterval));
 
     // Waiting default expiration
     int count = 0;
-    while(count < expireTime.count() && !wdog.timerExpired())
+    while(count < expireTime.count() && !wdog->timerExpired())
     {
         // Returns -0- on timeout and positive number on dispatch
         auto sleepTime = duration_cast<microseconds>(seconds(1s));
@@ -135,8 +135,8 @@
             count++;
         }
     }
-    EXPECT_TRUE(wdog.enabled());
-    EXPECT_EQ(0, wdog.timeRemaining());
-    EXPECT_TRUE(wdog.timerExpired());
+    EXPECT_TRUE(wdog->enabled());
+    EXPECT_EQ(0, wdog->timeRemaining());
+    EXPECT_TRUE(wdog->timerExpired());
     EXPECT_EQ(expireTime.count() - 1, count);
 }
diff --git a/test/watchdog_test.hpp b/test/watchdog_test.hpp
index e332260..beeda66 100644
--- a/test/watchdog_test.hpp
+++ b/test/watchdog_test.hpp
@@ -1,5 +1,6 @@
 #include <timer_test.hpp>
 #include <chrono>
+#include <memory>
 #include <watchdog.hpp>
 
 using namespace std::chrono;
@@ -12,8 +13,9 @@
         // Gets called as part of each TEST_F construction
         WdogTest()
             : bus(sdbusplus::bus::new_default()),
-              wdog(bus, TEST_PATH, eventP),
-              defaultInterval(milliseconds(wdog.interval())),
+              wdog(std::make_unique<phosphor::watchdog::Watchdog>(
+                      bus, TEST_PATH, eventP)),
+              defaultInterval(milliseconds(wdog->interval())),
               defaultDrift(30)
         {
             // Check for successful creation of
@@ -21,14 +23,14 @@
             EXPECT_GE(rc, 0);
 
             // Initially the watchdog would be disabled
-            EXPECT_FALSE(wdog.enabled());
+            EXPECT_FALSE(wdog->enabled());
         }
 
         //sdbusplus handle
         sdbusplus::bus::bus bus;
 
         // Watchdog object
-        phosphor::watchdog::Watchdog wdog;
+        std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
 
         // This is the default interval as given in Interface definition
         milliseconds defaultInterval;