blob: 36b7d3ccbff0f5b4c82c898e8996f6bbe1a174ab [file] [log] [blame]
#include "MCTPEndpoint.hpp"
#include "Utils.hpp"
#include <stdexcept>
#include <gtest/gtest.h>
TEST(I2CMCTPDDevice, matchEmptyConfig)
{
SensorData config{};
EXPECT_FALSE(I2CMCTPDDevice::match(config));
}
TEST(I2CMCTPDDevice, matchIrrelevantConfig)
{
SensorData config{{"xyz.openbmc_project.Configuration.NVME1000", {}}};
EXPECT_FALSE(I2CMCTPDDevice::match(config));
}
TEST(I2CMCTPDDevice, matchRelevantConfig)
{
SensorData config{{"xyz.openbmc_project.Configuration.MCTPI2CTarget", {}}};
EXPECT_TRUE(I2CMCTPDDevice::match(config));
}
TEST(I2CMCTPDDevice, fromBadIfaceNoType)
{
SensorBaseConfigMap iface{{}};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceWrongType)
{
SensorBaseConfigMap iface{{"Type", "NVME1000"}};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceNoAddress)
{
SensorBaseConfigMap iface{
{"Bus", "0"},
{"Name", "test"},
{"Type", "MCTPI2CTarget"},
};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceBadAddress)
{
SensorBaseConfigMap iface{
{"Address", "not a number"},
{"Bus", "0"},
{"Name", "test"},
{"Type", "MCTPI2CTarget"},
};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceNoBus)
{
SensorBaseConfigMap iface{
{"Address", "0x1d"},
{"Name", "test"},
{"Type", "MCTPI2CTarget"},
};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceBadBus)
{
SensorBaseConfigMap iface{
{"Address", "0x1d"},
{"Bus", "not a number"},
{"Name", "test"},
{"Type", "MCTPI2CTarget"},
};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}
TEST(I2CMCTPDDevice, fromBadIfaceNoName)
{
SensorBaseConfigMap iface{
{"Address", "0x1d"},
{"Bus", "0"},
{"Type", "MCTPI2CTarget"},
};
EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
}