Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 4 | #include <xyz/openbmc_project/Common/error.hpp> |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace time |
| 9 | { |
| 10 | namespace utils |
| 11 | { |
| 12 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 13 | using InvalidArgument = |
| 14 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 15 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 16 | TEST(TestUtil, strToMode) |
| 17 | { |
| 18 | EXPECT_EQ(Mode::NTP, strToMode("NTP")); |
| 19 | EXPECT_EQ(Mode::MANUAL, strToMode("MANUAL")); |
| 20 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 21 | // All unrecognized strings result in InvalidArgument exception |
| 22 | EXPECT_THROW(strToMode(""), InvalidArgument); |
| 23 | EXPECT_THROW(strToMode("Manual"), InvalidArgument); |
| 24 | EXPECT_THROW(strToMode("whatever"), InvalidArgument); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | |
| 28 | TEST(TestUtil, strToOwner) |
| 29 | { |
| 30 | EXPECT_EQ(Owner::BMC, strToOwner("BMC")); |
| 31 | EXPECT_EQ(Owner::HOST, strToOwner("HOST")); |
| 32 | EXPECT_EQ(Owner::SPLIT, strToOwner("SPLIT")); |
| 33 | EXPECT_EQ(Owner::BOTH, strToOwner("BOTH")); |
| 34 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 35 | // All unrecognized strings result in InvalidArgument exception |
| 36 | EXPECT_THROW(strToOwner(""), InvalidArgument); |
| 37 | EXPECT_THROW(strToOwner("Split"), InvalidArgument); |
| 38 | EXPECT_THROW(strToOwner("xyz"), InvalidArgument); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(TestUtil, modeToStr) |
| 42 | { |
| 43 | EXPECT_EQ("NTP", modeToStr(Mode::NTP)); |
| 44 | EXPECT_EQ("MANUAL", modeToStr(Mode::MANUAL)); |
| 45 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 46 | // All unrecognized strings result in InvalidArgument exception |
| 47 | EXPECT_THROW(modeToStr(static_cast<Mode>(100)), InvalidArgument); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | TEST(TestUtil, ownerToStr) |
| 51 | { |
| 52 | EXPECT_EQ("BMC", ownerToStr(Owner::BMC)); |
| 53 | EXPECT_EQ("HOST", ownerToStr(Owner::HOST)); |
| 54 | EXPECT_EQ("SPLIT", ownerToStr(Owner::SPLIT)); |
| 55 | EXPECT_EQ("BOTH", ownerToStr(Owner::BOTH)); |
| 56 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame^] | 57 | // All unrecognized strings result in InvalidArgument exception |
| 58 | EXPECT_THROW(ownerToStr(static_cast<Owner>(100)), InvalidArgument); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace utils |
| 62 | } // namespace time |
| 63 | } // namespace phosphor |