blob: b4200d3e24c53e1af37ba75b2e20def4a270e9a9 [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)
George Liu6492f522020-06-16 10:34:05 +080014 {}
John Wange2efdcc2020-02-12 17:02:06 +080015
16 void setAttrValueOnDbus(const pldm_bios_attr_val_table_entry*,
17 const pldm_bios_attr_table_entry*,
18 const BIOSStringTable&) override
George Liu6492f522020-06-16 10:34:05 +080019 {}
John Wange2efdcc2020-02-12 17:02:06 +080020
21 void constructEntry(const BIOSStringTable&, Table&, Table&) override
George Liu6492f522020-06-16 10:34:05 +080022 {}
John Wange2efdcc2020-02-12 17:02:06 +080023
24 const std::optional<DBusMapping>& getDbusMap()
25 {
26 return dBusMap;
27 }
Sampa Misra46ece062020-03-18 07:17:44 -050028
29 int updateAttrVal(Table& /*newValue*/, uint16_t /*attrHdl*/,
30 uint8_t /*attrType*/,
31 const PropertyValue& /*newPropVal*/) override
32 {
33 return PLDM_SUCCESS;
34 }
John Wange2efdcc2020-02-12 17:02:06 +080035};
36
37TEST(BIOSAttribute, CtorTest)
38{
39 auto jsonReadOnly = R"({
40 "attribute_name" : "ReadOnly"
41 })"_json;
42
43 TestAttribute readOnly{jsonReadOnly, nullptr};
44 EXPECT_EQ(readOnly.name, "ReadOnly");
45 EXPECT_EQ(readOnly.readOnly, true);
46
47 auto jsonReadOnlyError = R"({
48 "attribute_nam":"ReadOnly"
49 })"_json;
50 using Json = nlohmann::json;
51
52 EXPECT_THROW((TestAttribute{jsonReadOnlyError, nullptr}), Json::exception);
53
54 auto jsonReadWrite = R"({
55 "attribute_name":"ReadWrite",
56 "dbus":
57 {
58 "object_path" : "/xyz/abc/def",
59 "interface" : "xyz.openbmc.FWBoot.Side",
60 "property_name" : "Side",
61 "property_type" : "bool"
62 }
63 })"_json;
64
65 TestAttribute readWrite{jsonReadWrite, nullptr};
66 EXPECT_EQ(readWrite.name, "ReadWrite");
67 EXPECT_EQ(readWrite.readOnly, false);
68 auto dbusMap = readWrite.getDbusMap();
69 EXPECT_NE(dbusMap, std::nullopt);
70 EXPECT_EQ(dbusMap->objectPath, "/xyz/abc/def");
71 EXPECT_EQ(dbusMap->interface, "xyz.openbmc.FWBoot.Side");
72 EXPECT_EQ(dbusMap->propertyName, "Side");
73 EXPECT_EQ(dbusMap->propertyType, "bool");
74
75 auto jsonReadWriteError = R"({
76 "attribute_name":"ReadWrite",
77 "dbus":
78 {
79 "object_path" : "/xyz/abc/def",
80 "interface" : "xyz.openbmc.FWBoot.Side",
81 "property_name" : "Side"
82 }
83 })"_json; // missing property_type.
84
85 EXPECT_THROW((TestAttribute{jsonReadWriteError, nullptr}), Json::exception);
Sampa Misra46ece062020-03-18 07:17:44 -050086}