Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 3 | #include <xyz/openbmc_project/Common/error.hpp> |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 4 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 5 | #include <gtest/gtest.h> |
| 6 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace time |
| 10 | { |
| 11 | namespace utils |
| 12 | { |
| 13 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 14 | using InvalidEnumString = sdbusplus::exception::InvalidEnumString; |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 15 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 16 | TEST(TestUtil, strToMode) |
| 17 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 18 | EXPECT_EQ(Mode::NTP, |
| 19 | strToMode("xyz.openbmc_project.Time.Synchronization.Method.NTP")); |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 20 | EXPECT_EQ( |
| 21 | Mode::Manual, |
| 22 | strToMode("xyz.openbmc_project.Time.Synchronization.Method.Manual")); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 23 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 24 | // 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 YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 30 | } |
| 31 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 32 | TEST(TestUtil, modeToStr) |
| 33 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 34 | 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 YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 38 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 39 | // All unrecognized strings result in exception |
| 40 | EXPECT_ANY_THROW(modeToStr(static_cast<Mode>(100))); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 41 | } |
| 42 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 43 | } // namespace utils |
| 44 | } // namespace time |
| 45 | } // namespace phosphor |