blob: 4cc9db9aef40fa3ef973f501e2404bc299426096 [file] [log] [blame]
John Wange2efdcc2020-02-12 17:02:06 +08001#include "libpldmresponder/bios_attribute.hpp"
2
3#include <nlohmann/json.hpp>
4
5#include <gtest/gtest.h>
6
7using namespace pldm::responder::bios;
8
9class TestAttribute : public BIOSAttribute
10{
11 public:
12 TestAttribute(const Json& entry, DBusHandler* const dbusHandler) :
13 BIOSAttribute(entry, dbusHandler)
14 {
15 }
16
17 void setAttrValueOnDbus(const pldm_bios_attr_val_table_entry*,
18 const pldm_bios_attr_table_entry*,
19 const BIOSStringTable&) override
20 {
21 }
22
23 void constructEntry(const BIOSStringTable&, Table&, Table&) override
24 {
25 }
26
27 const std::optional<DBusMapping>& getDbusMap()
28 {
29 return dBusMap;
30 }
Sampa Misra46ece062020-03-18 07:17:44 -050031
32 int updateAttrVal(Table& /*newValue*/, uint16_t /*attrHdl*/,
33 uint8_t /*attrType*/,
34 const PropertyValue& /*newPropVal*/) override
35 {
36 return PLDM_SUCCESS;
37 }
John Wange2efdcc2020-02-12 17:02:06 +080038};
39
40TEST(BIOSAttribute, CtorTest)
41{
42 auto jsonReadOnly = R"({
43 "attribute_name" : "ReadOnly"
44 })"_json;
45
46 TestAttribute readOnly{jsonReadOnly, nullptr};
47 EXPECT_EQ(readOnly.name, "ReadOnly");
48 EXPECT_EQ(readOnly.readOnly, true);
49
50 auto jsonReadOnlyError = R"({
51 "attribute_nam":"ReadOnly"
52 })"_json;
53 using Json = nlohmann::json;
54
55 EXPECT_THROW((TestAttribute{jsonReadOnlyError, nullptr}), Json::exception);
56
57 auto jsonReadWrite = R"({
58 "attribute_name":"ReadWrite",
59 "dbus":
60 {
61 "object_path" : "/xyz/abc/def",
62 "interface" : "xyz.openbmc.FWBoot.Side",
63 "property_name" : "Side",
64 "property_type" : "bool"
65 }
66 })"_json;
67
68 TestAttribute readWrite{jsonReadWrite, nullptr};
69 EXPECT_EQ(readWrite.name, "ReadWrite");
70 EXPECT_EQ(readWrite.readOnly, false);
71 auto dbusMap = readWrite.getDbusMap();
72 EXPECT_NE(dbusMap, std::nullopt);
73 EXPECT_EQ(dbusMap->objectPath, "/xyz/abc/def");
74 EXPECT_EQ(dbusMap->interface, "xyz.openbmc.FWBoot.Side");
75 EXPECT_EQ(dbusMap->propertyName, "Side");
76 EXPECT_EQ(dbusMap->propertyType, "bool");
77
78 auto jsonReadWriteError = R"({
79 "attribute_name":"ReadWrite",
80 "dbus":
81 {
82 "object_path" : "/xyz/abc/def",
83 "interface" : "xyz.openbmc.FWBoot.Side",
84 "property_name" : "Side"
85 }
86 })"_json; // missing property_type.
87
88 EXPECT_THROW((TestAttribute{jsonReadWriteError, nullptr}), Json::exception);
Sampa Misra46ece062020-03-18 07:17:44 -050089}