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