xref: /openbmc/pldm/fw-update/test/firmware_inventory_test.cpp (revision 7ad45b401134e3b3a05a75200dbba00afd5aee46)
1 #include "fw-update/firmware_inventory.hpp"
2 
3 #include <string>
4 
5 #include <gtest/gtest.h>
6 
7 using namespace pldm::fw_update;
8 
9 class FirmwareInventoryTest : public FirmwareInventory
10 {
11   public:
12     using FirmwareInventory::FirmwareInventory;
getSoftwarePath() const13     const std::string& getSoftwarePath() const
14     {
15         return this->softwarePath;
16     }
getAssociation() const17     const SoftwareAssociationDefinitions& getAssociation() const
18     {
19         return this->association;
20     }
getVersion() const21     const SoftwareVersion& getVersion() const
22     {
23         return this->version;
24     }
25 };
26 
TEST(FirmwareInventoryTest,ConstructorSetsProperties)27 TEST(FirmwareInventoryTest, ConstructorSetsProperties)
28 {
29     SoftwareIdentifier softwareIdentifier{1, 100};
30     std::string expectedSoftwarePath =
31         "/xyz/openbmc_project/software/PLDM_Device_TestDevice_1234";
32     std::string expectedSoftwareVersion = "2.3.4";
33     std::string expectedEndpointPath =
34         "/xyz/openbmc_project/inventory/system/board/PLDM_Device";
35     Descriptors firmwareDescriptors;
36     ComponentInfo firmwareComponentInfo;
37     SoftwareVersionPurpose expectedPurpose = SoftwareVersionPurpose::Unknown;
38 
39     FirmwareInventoryTest inventory(
40         softwareIdentifier, expectedSoftwarePath, expectedSoftwareVersion,
41         expectedEndpointPath, firmwareDescriptors, firmwareComponentInfo,
42         expectedPurpose);
43 
44     EXPECT_EQ(inventory.getSoftwarePath(), expectedSoftwarePath);
45     auto associationTuples = inventory.getAssociation().associations();
46     ASSERT_FALSE(associationTuples.empty());
47     EXPECT_EQ(std::get<2>(associationTuples[0]), expectedEndpointPath);
48     EXPECT_EQ(inventory.getVersion().version(), expectedSoftwareVersion);
49     EXPECT_EQ(inventory.getVersion().purpose(), expectedPurpose);
50 }
51