1 #include "registries.hpp"
2 #include "registries/openbmc_message_registry.hpp"
3 
4 #include <gtest/gtest.h>
5 
6 namespace redfish::registries
7 {
8 namespace
9 {
10 
TEST(FillMessageArgs,ArgsAreFilledCorrectly)11 TEST(FillMessageArgs, ArgsAreFilledCorrectly)
12 {
13     EXPECT_EQ(fillMessageArgs({{"foo"}}, "%1"), "foo");
14     EXPECT_EQ(fillMessageArgs({}, ""), "");
15     EXPECT_EQ(fillMessageArgs({{"foo", "bar"}}, "%1, %2"), "foo, bar");
16     EXPECT_EQ(fillMessageArgs({{"foo"}}, "%1 bar"), "foo bar");
17     EXPECT_EQ(fillMessageArgs({}, "%1"), "");
18     EXPECT_EQ(fillMessageArgs({}, "%"), "");
19     EXPECT_EQ(fillMessageArgs({}, "%foo"), "");
20 }
21 
TEST(RedfishRegistries,GetMessageFromRegistry)22 TEST(RedfishRegistries, GetMessageFromRegistry)
23 {
24     const redfish::registries::Message* msg =
25         redfish::registries::getMessageFromRegistry(
26             "Non-Existent", redfish::registries::openbmc::registry);
27     ASSERT_EQ(msg, nullptr);
28 
29     const redfish::registries::Message* msg1 =
30         redfish::registries::getMessageFromRegistry(
31             "ServiceStarted", redfish::registries::openbmc::registry);
32     ASSERT_NE(msg1, nullptr);
33 
34     EXPECT_EQ(std::string(msg1->description),
35               "Indicates that a service has started successfully.");
36     EXPECT_EQ(std::string(msg1->message),
37               "Service %1 has started successfully.");
38     EXPECT_EQ(std::string(msg1->messageSeverity), "OK");
39     EXPECT_EQ(msg1->numberOfArgs, 1);
40     EXPECT_EQ(std::string(msg1->resolution), "None.");
41 }
42 
TEST(RedfishRegistries,GetMessage)43 TEST(RedfishRegistries, GetMessage)
44 {
45     const redfish::registries::Message* msg =
46         redfish::registries::getMessage("OpenBMC.1.0.Non_Existent_Message");
47     ASSERT_EQ(msg, nullptr);
48 
49     msg = redfish::registries::getMessage("OpenBMC.1.0.ServiceStarted");
50     ASSERT_NE(msg, nullptr);
51 }
52 
53 } // namespace
54 } // namespace redfish::registries
55