blob: 3d381719a69798428c129799456831bb3f35ccb6 [file] [log] [blame]
Lei YUddd54422017-04-18 16:38:44 +08001#include "utils.hpp"
2
Lei YU86d80412017-07-12 13:12:12 +08003#include <xyz/openbmc_project/Common/error.hpp>
Lei YUddd54422017-04-18 16:38:44 +08004
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05005#include <gtest/gtest.h>
6
Lei YUddd54422017-04-18 16:38:44 +08007namespace phosphor
8{
9namespace time
10{
11namespace utils
12{
13
Lei YUad143542017-07-25 14:27:07 +080014using InvalidEnumString = sdbusplus::exception::InvalidEnumString;
Lei YU86d80412017-07-12 13:12:12 +080015
Lei YUddd54422017-04-18 16:38:44 +080016TEST(TestUtil, strToMode)
17{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050018 EXPECT_EQ(Mode::NTP,
19 strToMode("xyz.openbmc_project.Time.Synchronization.Method.NTP"));
Lei YUad143542017-07-25 14:27:07 +080020 EXPECT_EQ(
21 Mode::Manual,
22 strToMode("xyz.openbmc_project.Time.Synchronization.Method.Manual"));
Lei YUddd54422017-04-18 16:38:44 +080023
Lei YUad143542017-07-25 14:27:07 +080024 // All unrecognized strings result in InvalidEnumString exception
25 EXPECT_THROW(strToMode(""), InvalidEnumString);
26 EXPECT_THROW(
27 strToMode("xyz.openbmc_project.Time.Synchronization.Method.MANUAL"),
28 InvalidEnumString);
29 EXPECT_THROW(strToMode("whatever"), InvalidEnumString);
Lei YUddd54422017-04-18 16:38:44 +080030}
31
Lei YUddd54422017-04-18 16:38:44 +080032TEST(TestUtil, modeToStr)
33{
Lei YUad143542017-07-25 14:27:07 +080034 EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
35 modeToStr(Mode::NTP));
36 EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.Manual",
37 modeToStr(Mode::Manual));
Lei YUddd54422017-04-18 16:38:44 +080038
Lei YUad143542017-07-25 14:27:07 +080039 // All unrecognized strings result in exception
40 EXPECT_ANY_THROW(modeToStr(static_cast<Mode>(100)));
Lei YUddd54422017-04-18 16:38:44 +080041}
42
Lei YUddd54422017-04-18 16:38:44 +080043} // namespace utils
44} // namespace time
45} // namespace phosphor