1 #include "MCTPEndpoint.hpp"
2 #include "Utils.hpp"
3
4 #include <stdexcept>
5
6 #include <gtest/gtest.h>
7
TEST(I2CMCTPDDevice,matchEmptyConfig)8 TEST(I2CMCTPDDevice, matchEmptyConfig)
9 {
10 SensorData config{};
11 EXPECT_FALSE(I2CMCTPDDevice::match(config));
12 }
13
TEST(I2CMCTPDDevice,matchIrrelevantConfig)14 TEST(I2CMCTPDDevice, matchIrrelevantConfig)
15 {
16 SensorData config{{"xyz.openbmc_project.Configuration.NVME1000", {}}};
17 EXPECT_FALSE(I2CMCTPDDevice::match(config));
18 }
19
TEST(I2CMCTPDDevice,matchRelevantConfig)20 TEST(I2CMCTPDDevice, matchRelevantConfig)
21 {
22 SensorData config{{"xyz.openbmc_project.Configuration.MCTPI2CTarget", {}}};
23 EXPECT_TRUE(I2CMCTPDDevice::match(config));
24 }
25
TEST(I2CMCTPDDevice,fromBadIfaceNoType)26 TEST(I2CMCTPDDevice, fromBadIfaceNoType)
27 {
28 SensorBaseConfigMap iface{{}};
29 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
30 }
31
TEST(I2CMCTPDDevice,fromBadIfaceWrongType)32 TEST(I2CMCTPDDevice, fromBadIfaceWrongType)
33 {
34 SensorBaseConfigMap iface{{"Type", "NVME1000"}};
35 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
36 }
37
TEST(I2CMCTPDDevice,fromBadIfaceNoAddress)38 TEST(I2CMCTPDDevice, fromBadIfaceNoAddress)
39 {
40 SensorBaseConfigMap iface{
41 {"Bus", "0"},
42 {"Name", "test"},
43 {"Type", "MCTPI2CTarget"},
44 };
45 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
46 }
47
TEST(I2CMCTPDDevice,fromBadIfaceBadAddress)48 TEST(I2CMCTPDDevice, fromBadIfaceBadAddress)
49 {
50 SensorBaseConfigMap iface{
51 {"Address", "not a number"},
52 {"Bus", "0"},
53 {"Name", "test"},
54 {"Type", "MCTPI2CTarget"},
55 };
56 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
57 }
58
TEST(I2CMCTPDDevice,fromBadIfaceNoBus)59 TEST(I2CMCTPDDevice, fromBadIfaceNoBus)
60 {
61 SensorBaseConfigMap iface{
62 {"Address", "0x1d"},
63 {"Name", "test"},
64 {"Type", "MCTPI2CTarget"},
65 };
66 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
67 }
68
TEST(I2CMCTPDDevice,fromBadIfaceBadBus)69 TEST(I2CMCTPDDevice, fromBadIfaceBadBus)
70 {
71 SensorBaseConfigMap iface{
72 {"Address", "0x1d"},
73 {"Bus", "not a number"},
74 {"Name", "test"},
75 {"Type", "MCTPI2CTarget"},
76 };
77 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
78 }
79
TEST(I2CMCTPDDevice,fromBadIfaceNoName)80 TEST(I2CMCTPDDevice, fromBadIfaceNoName)
81 {
82 SensorBaseConfigMap iface{
83 {"Address", "0x1d"},
84 {"Bus", "0"},
85 {"Type", "MCTPI2CTarget"},
86 };
87 EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
88 }
89