blob: 16ccd9c13b6bfaf4dbfaae607a1ade33a679d841 [file] [log] [blame]
Lei YUddd54422017-04-18 16:38:44 +08001#include "utils.hpp"
2
3#include <gtest/gtest.h>
Lei YU86d80412017-07-12 13:12:12 +08004#include <xyz/openbmc_project/Common/error.hpp>
Lei YUddd54422017-04-18 16:38:44 +08005
6namespace phosphor
7{
8namespace time
9{
10namespace utils
11{
12
Lei YU86d80412017-07-12 13:12:12 +080013using InvalidArgument =
14 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
15
Lei YUddd54422017-04-18 16:38:44 +080016TEST(TestUtil, strToMode)
17{
18 EXPECT_EQ(Mode::NTP, strToMode("NTP"));
19 EXPECT_EQ(Mode::MANUAL, strToMode("MANUAL"));
20
Lei YU86d80412017-07-12 13:12:12 +080021 // 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 YUddd54422017-04-18 16:38:44 +080025}
26
27
28TEST(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 YU86d80412017-07-12 13:12:12 +080035 // 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 YUddd54422017-04-18 16:38:44 +080039}
40
41TEST(TestUtil, modeToStr)
42{
43 EXPECT_EQ("NTP", modeToStr(Mode::NTP));
44 EXPECT_EQ("MANUAL", modeToStr(Mode::MANUAL));
45
Lei YU86d80412017-07-12 13:12:12 +080046 // All unrecognized strings result in InvalidArgument exception
47 EXPECT_THROW(modeToStr(static_cast<Mode>(100)), InvalidArgument);
Lei YUddd54422017-04-18 16:38:44 +080048}
49
50TEST(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 YU86d80412017-07-12 13:12:12 +080057 // All unrecognized strings result in InvalidArgument exception
58 EXPECT_THROW(ownerToStr(static_cast<Owner>(100)), InvalidArgument);
Lei YUddd54422017-04-18 16:38:44 +080059}
60
61} // namespace utils
62} // namespace time
63} // namespace phosphor