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