Use time mode owner enums in dbus interface

Dbus interface defines time mode owners in xyz::openbmc_project::Time.
Use the enums from the interface instead of repo defined enums and use
the generated code to do convertions between strings and enums.

Update unit tests accordingly.

Change-Id: Ic304aa3b4137375d208bb1702e0f64df512fc5a0
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp
index f182de4..e268b9f 100644
--- a/test/TestBmcEpoch.cpp
+++ b/test/TestBmcEpoch.cpp
@@ -68,8 +68,8 @@
 TEST_F(TestBmcEpoch, empty)
 {
     // Default mode/owner is MANUAL/BOTH
-    EXPECT_EQ(Mode::MANUAL, getTimeMode());
-    EXPECT_EQ(Owner::BOTH, getTimeOwner());
+    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Owner::Both, getTimeOwner());
 }
 
 TEST_F(TestBmcEpoch, getElapsed)
@@ -90,8 +90,8 @@
     EXPECT_EQ(0, ret);
 
     // In Host owner, setting time is not allowed
-    setTimeMode(Mode::MANUAL);
-    setTimeOwner(Owner::HOST);
+    setTimeMode(Mode::Manual);
+    setTimeOwner(Owner::Host);
     ret = bmcEpoch->elapsed(epochNow);
     EXPECT_EQ(0, ret);
 }
diff --git a/test/TestEpochBase.cpp b/test/TestEpochBase.cpp
index e4a2b68..6c2ec88 100644
--- a/test/TestEpochBase.cpp
+++ b/test/TestEpochBase.cpp
@@ -37,8 +37,8 @@
     epochBase.onModeChanged(Mode::NTP);
     EXPECT_EQ(Mode::NTP, getMode());
 
-    epochBase.onModeChanged(Mode::MANUAL);
-    EXPECT_EQ(Mode::MANUAL, getMode());
+    epochBase.onModeChanged(Mode::Manual);
+    EXPECT_EQ(Mode::Manual, getMode());
 }
 
 TEST_F(TestEpochBase, onOwnerChange)
@@ -46,14 +46,14 @@
     epochBase.onOwnerChanged(Owner::BMC);
     EXPECT_EQ(Owner::BMC, getOwner());
 
-    epochBase.onOwnerChanged(Owner::HOST);
-    EXPECT_EQ(Owner::HOST, getOwner());
+    epochBase.onOwnerChanged(Owner::Host);
+    EXPECT_EQ(Owner::Host, getOwner());
 
-    epochBase.onOwnerChanged(Owner::SPLIT);
-    EXPECT_EQ(Owner::SPLIT, getOwner());
+    epochBase.onOwnerChanged(Owner::Split);
+    EXPECT_EQ(Owner::Split, getOwner());
 
-    epochBase.onOwnerChanged(Owner::BOTH);
-    EXPECT_EQ(Owner::BOTH, getOwner());
+    epochBase.onOwnerChanged(Owner::Both);
+    EXPECT_EQ(Owner::Both, getOwner());
 }
 
 }
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index 0e59745..a492b9a 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -138,8 +138,8 @@
 TEST_F(TestHostEpoch, empty)
 {
     // Default mode/owner is MANUAL/BOTH
-    EXPECT_EQ(Mode::MANUAL, getTimeMode());
-    EXPECT_EQ(Owner::BOTH, getTimeOwner());
+    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Owner::Both, getTimeOwner());
 }
 
 TEST_F(TestHostEpoch, readDataFileNotExist)
@@ -176,7 +176,7 @@
 {
     // Set time in NTP/HOST is not allowed
     setTimeMode(Mode::NTP);
-    setTimeOwner(Owner::HOST);
+    setTimeOwner(Owner::Host);
     checkSettingTimeNotAllowed();
 }
 
@@ -184,7 +184,7 @@
 {
     // Set time in NTP/SPLIT, offset will be set
     setTimeMode(Mode::NTP);
-    setTimeOwner(Owner::SPLIT);
+    setTimeOwner(Owner::Split);
 
     checkSetSplitTimeInFuture();
 
@@ -197,14 +197,14 @@
 {
     // Set time in NTP/BOTH is not allowed
     setTimeMode(Mode::NTP);
-    setTimeOwner(Owner::BOTH);
+    setTimeOwner(Owner::Both);
     checkSettingTimeNotAllowed();
 }
 
 TEST_F(TestHostEpoch, setElapsedInManualBmc)
 {
     // Set time in MANUAL/BMC is not allowed
-    setTimeMode(Mode::MANUAL);
+    setTimeMode(Mode::Manual);
     setTimeOwner(Owner::BMC);
     checkSettingTimeNotAllowed();
 }
@@ -214,15 +214,15 @@
     // Set time in MANUAL/HOST, time will be set to BMC
     // However it requies gmock to test this case
     // TODO: when gmock is ready, test this case.
-    setTimeMode(Mode::MANUAL);
-    setTimeOwner(Owner::HOST);
+    setTimeMode(Mode::Manual);
+    setTimeOwner(Owner::Host);
 }
 
 TEST_F(TestHostEpoch, setElapsedInManualSplit)
 {
     // Set to SPLIT owner so that offset will be set
-    setTimeMode(Mode::MANUAL);
-    setTimeOwner(Owner::SPLIT);
+    setTimeMode(Mode::Manual);
+    setTimeOwner(Owner::Split);
 
     checkSetSplitTimeInFuture();
 
@@ -236,14 +236,14 @@
     // Set time in MANUAL/BOTH, time will be set to BMC
     // However it requies gmock to test this case
     // TODO: when gmock is ready, test this case.
-    setTimeMode(Mode::MANUAL);
-    setTimeOwner(Owner::BOTH);
+    setTimeMode(Mode::Manual);
+    setTimeOwner(Owner::Both);
 }
 
 TEST_F(TestHostEpoch, setElapsedInSplitAndBmcTimeIsChanged)
 {
     // Set to SPLIT owner so that offset will be set
-    setTimeOwner(Owner::SPLIT);
+    setTimeOwner(Owner::Split);
 
     // Get current time, and set future +1min time
     auto t1 = hostEpoch.elapsed();
@@ -277,13 +277,13 @@
 {
     EXPECT_EQ(USEC_ZERO, getOffset());
 
-    setTimeOwner(Owner::SPLIT);
+    setTimeOwner(Owner::Split);
     hostEpoch.onBmcTimeChanged(microseconds(hostEpoch.elapsed()) + 1min);
 
     // Now offset shall be non zero
     EXPECT_NE(USEC_ZERO, getOffset());
 
-    setTimeOwner(Owner::BOTH);
+    setTimeOwner(Owner::Both);
 
     // Now owner is BOTH, the offset shall be cleared
     EXPECT_EQ(USEC_ZERO, getOffset());
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index 5c9c8c3..d87ca39 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -69,8 +69,8 @@
     EXPECT_EQ("", getRequestedOwner());
 
     // Default mode/owner is MANUAL/BOTH
-    EXPECT_EQ(Mode::MANUAL, getTimeMode());
-    EXPECT_EQ(Owner::BOTH, getTimeOwner());
+    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Owner::Both, getTimeOwner());
 }
 
 
@@ -88,13 +88,17 @@
     EXPECT_FALSE(hostOn());
 
     // Check mocked listeners shall receive notifications on property changed
-    EXPECT_CALL(listener1, onModeChanged(Mode::MANUAL)).Times(1);
-    EXPECT_CALL(listener1, onOwnerChanged(Owner::HOST)).Times(1);
-    EXPECT_CALL(listener2, onModeChanged(Mode::MANUAL)).Times(1);
-    EXPECT_CALL(listener2, onOwnerChanged(Owner::HOST)).Times(1);
+    EXPECT_CALL(listener1, onModeChanged(Mode::Manual)).Times(1);
+    EXPECT_CALL(listener1, onOwnerChanged(Owner::Host)).Times(1);
+    EXPECT_CALL(listener2, onModeChanged(Mode::Manual)).Times(1);
+    EXPECT_CALL(listener2, onOwnerChanged(Owner::Host)).Times(1);
 
-    notifyPropertyChanged("time_mode", "MANUAL");
-    notifyPropertyChanged("time_owner", "HOST");
+    notifyPropertyChanged(
+        "time_mode",
+        "xyz.openbmc_project.Time.Synchronization.Method.Manual");
+    notifyPropertyChanged(
+        "time_owner",
+        "xyz.openbmc_project.Time.Owner.Owners.Host");
 
     EXPECT_EQ("", getRequestedMode());
     EXPECT_EQ("", getRequestedOwner());
@@ -103,24 +107,30 @@
     notifyPgoodChanged(true);
 
     // Check mocked listeners shall not receive notifications
-    EXPECT_CALL(listener1, onModeChanged(Mode::MANUAL)).Times(0);
-    EXPECT_CALL(listener1, onOwnerChanged(Owner::HOST)).Times(0);
-    EXPECT_CALL(listener2, onModeChanged(Mode::MANUAL)).Times(0);
-    EXPECT_CALL(listener2, onOwnerChanged(Owner::HOST)).Times(0);
+    EXPECT_CALL(listener1, onModeChanged(Mode::Manual)).Times(0);
+    EXPECT_CALL(listener1, onOwnerChanged(Owner::Host)).Times(0);
+    EXPECT_CALL(listener2, onModeChanged(Mode::Manual)).Times(0);
+    EXPECT_CALL(listener2, onOwnerChanged(Owner::Host)).Times(0);
 
-    notifyPropertyChanged("time_mode", "NTP");
-    notifyPropertyChanged("time_owner", "SPLIT");
+    notifyPropertyChanged(
+        "time_mode",
+        "xyz.openbmc_project.Time.Synchronization.Method.NTP");
+    notifyPropertyChanged(
+        "time_owner",
+        "xyz.openbmc_project.Time.Owner.Owners.Split");
 
-    EXPECT_EQ("NTP", getRequestedMode());
-    EXPECT_EQ("SPLIT", getRequestedOwner());
+    EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
+              getRequestedMode());
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Split",
+              getRequestedOwner());
 
 
     // When host becomes off, the requested mode/owner shall be notified
     // to listners, and be cleared
     EXPECT_CALL(listener1, onModeChanged(Mode::NTP)).Times(1);
-    EXPECT_CALL(listener1, onOwnerChanged(Owner::SPLIT)).Times(1);
+    EXPECT_CALL(listener1, onOwnerChanged(Owner::Split)).Times(1);
     EXPECT_CALL(listener2, onModeChanged(Mode::NTP)).Times(1);
-    EXPECT_CALL(listener2, onOwnerChanged(Owner::SPLIT)).Times(1);
+    EXPECT_CALL(listener2, onOwnerChanged(Owner::Split)).Times(1);
 
     notifyPgoodChanged(false);
 
@@ -136,8 +146,12 @@
 TEST_F(TestManager, DISABLED_propertyChangedAndChangedbackWhenHostOn)
 {
     // Property is now MANUAL/HOST
-    notifyPropertyChanged("time_mode", "MANUAL");
-    notifyPropertyChanged("time_owner", "HOST");
+    notifyPropertyChanged(
+        "time_mode",
+        "xyz.openbmc_project.Time.Synchronization.Method.Manual");
+    notifyPropertyChanged(
+        "time_owner",
+        "xyz.openbmc_project.Time.Owner.Owners.Host");
 
     // Set host on
     notifyPgoodChanged(true);
@@ -148,20 +162,32 @@
     EXPECT_CALL(listener2, onModeChanged(_)).Times(0);
     EXPECT_CALL(listener2, onOwnerChanged(_)).Times(0);
 
-    notifyPropertyChanged("time_mode", "NTP");
-    notifyPropertyChanged("time_owner", "SPLIT");
+    notifyPropertyChanged(
+        "time_mode",
+        "xyz.openbmc_project.Time.Synchronization.Method.NTP");
+    notifyPropertyChanged(
+        "time_owner",
+        "xyz.openbmc_project.Time.Owner.Owners.Split");
 
     // Saved as requested mode/owner
-    EXPECT_EQ("NTP", getRequestedMode());
-    EXPECT_EQ("SPLIT", getRequestedOwner());
+    EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
+              getRequestedMode());
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Split",
+              getRequestedOwner());
 
     // Property changed back to MANUAL/HOST
-    notifyPropertyChanged("time_mode", "MANUAL");
-    notifyPropertyChanged("time_owner", "HOST");
+    notifyPropertyChanged(
+        "time_mode",
+        "xyz.openbmc_project.Time.Synchronization.Method.Manual");
+    notifyPropertyChanged(
+        "time_owner",
+        "xyz.openbmc_project.Time.Owner.Owners.Host");
 
     // Requested mode/owner shall be updated
-    EXPECT_EQ("MANUAL", getRequestedMode());
-    EXPECT_EQ("HOST", getRequestedOwner());
+    EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.Manual",
+              getRequestedMode());
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Host",
+              getRequestedOwner());
 
     // Because the latest mode/owner is the same as when host is off,
     // The listeners shall not be notified, and requested mode/owner
diff --git a/test/TestUtils.cpp b/test/TestUtils.cpp
index 16ccd9c..483e82a 100644
--- a/test/TestUtils.cpp
+++ b/test/TestUtils.cpp
@@ -10,52 +10,67 @@
 namespace utils
 {
 
-using InvalidArgument =
-    sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+using InvalidEnumString = sdbusplus::exception::InvalidEnumString;
 
 TEST(TestUtil, strToMode)
 {
-    EXPECT_EQ(Mode::NTP, strToMode("NTP"));
-    EXPECT_EQ(Mode::MANUAL, strToMode("MANUAL"));
+    EXPECT_EQ(
+        Mode::NTP,
+        strToMode("xyz.openbmc_project.Time.Synchronization.Method.NTP"));
+    EXPECT_EQ(
+        Mode::Manual,
+        strToMode("xyz.openbmc_project.Time.Synchronization.Method.Manual"));
 
-    // All unrecognized strings result in InvalidArgument exception
-    EXPECT_THROW(strToMode(""), InvalidArgument);
-    EXPECT_THROW(strToMode("Manual"), InvalidArgument);
-    EXPECT_THROW(strToMode("whatever"), InvalidArgument);
+    // All unrecognized strings result in InvalidEnumString exception
+    EXPECT_THROW(strToMode(""), InvalidEnumString);
+    EXPECT_THROW(
+        strToMode("xyz.openbmc_project.Time.Synchronization.Method.MANUAL"),
+        InvalidEnumString);
+    EXPECT_THROW(strToMode("whatever"), InvalidEnumString);
 }
 
 
 TEST(TestUtil, strToOwner)
 {
-    EXPECT_EQ(Owner::BMC, strToOwner("BMC"));
-    EXPECT_EQ(Owner::HOST, strToOwner("HOST"));
-    EXPECT_EQ(Owner::SPLIT, strToOwner("SPLIT"));
-    EXPECT_EQ(Owner::BOTH, strToOwner("BOTH"));
+    EXPECT_EQ(Owner::BMC,
+              strToOwner("xyz.openbmc_project.Time.Owner.Owners.BMC"));
+    EXPECT_EQ(Owner::Host,
+              strToOwner("xyz.openbmc_project.Time.Owner.Owners.Host"));
+    EXPECT_EQ(Owner::Split,
+              strToOwner("xyz.openbmc_project.Time.Owner.Owners.Split"));
+    EXPECT_EQ(Owner::Both,
+              strToOwner("xyz.openbmc_project.Time.Owner.Owners.Both"));
 
-    // All unrecognized strings result in InvalidArgument exception
-    EXPECT_THROW(strToOwner(""), InvalidArgument);
-    EXPECT_THROW(strToOwner("Split"), InvalidArgument);
-    EXPECT_THROW(strToOwner("xyz"), InvalidArgument);
+    // All unrecognized strings result in InvalidEnumString exception
+    EXPECT_THROW(strToOwner(""), InvalidEnumString);
+    EXPECT_THROW(strToOwner("Split"), InvalidEnumString);
+    EXPECT_THROW(strToOwner("xyz"), InvalidEnumString);
 }
 
 TEST(TestUtil, modeToStr)
 {
-    EXPECT_EQ("NTP", modeToStr(Mode::NTP));
-    EXPECT_EQ("MANUAL", modeToStr(Mode::MANUAL));
+    EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
+              modeToStr(Mode::NTP));
+    EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.Manual",
+              modeToStr(Mode::Manual));
 
-    // All unrecognized strings result in InvalidArgument exception
-    EXPECT_THROW(modeToStr(static_cast<Mode>(100)), InvalidArgument);
+    // All unrecognized strings result in exception
+    EXPECT_ANY_THROW(modeToStr(static_cast<Mode>(100)));
 }
 
 TEST(TestUtil, ownerToStr)
 {
-    EXPECT_EQ("BMC", ownerToStr(Owner::BMC));
-    EXPECT_EQ("HOST", ownerToStr(Owner::HOST));
-    EXPECT_EQ("SPLIT", ownerToStr(Owner::SPLIT));
-    EXPECT_EQ("BOTH", ownerToStr(Owner::BOTH));
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.BMC",
+              ownerToStr(Owner::BMC));
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Host",
+              ownerToStr(Owner::Host));
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Split",
+              ownerToStr(Owner::Split));
+    EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Both",
+              ownerToStr(Owner::Both));
 
-    // All unrecognized strings result in InvalidArgument exception
-    EXPECT_THROW(ownerToStr(static_cast<Owner>(100)), InvalidArgument);
+    // All unrecognized strings result in exception
+    EXPECT_ANY_THROW(ownerToStr(static_cast<Owner>(100)));
 }
 
 } // namespace utils