blob: 4c3ea0ec5dfeb8b53fef7e70add80d4ec7a915c7 [file] [log] [blame]
#include "Test/server.hpp"
#include <sdbusplus/bus.hpp>
#include <gtest/gtest.h>
using TestIf = sdbusplus::server::server::Test;
struct Object : public ::testing::Test
{
sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
sdbusplus::message::message msg = bus.new_method_call(
"xyz.openbmc_project.sdbusplus.test.Object",
"/xyz/openbmc_project/sdbusplus/test/object",
"xyz.openbmc_project.sdbusplus.test.Object", "Unused");
using variant_t =
std::variant<TestIf::EnumOne, std::string, TestIf::EnumTwo>;
template <typename V, typename T>
void run_test(const T& value)
{
const V data = value;
msg.append(data);
ASSERT_EQ(0, sd_bus_message_seal(msg.get(), 0, 0));
V new_data = {};
msg.read(new_data);
EXPECT_EQ(data, new_data);
}
template <typename V1, typename V2, typename T>
void run_test_throw_bad_enum(const T& value)
{
const V1 data = value;
msg.append(data);
ASSERT_EQ(0, sd_bus_message_seal(msg.get(), 0, 0));
V2 new_data = {};
EXPECT_THROW(msg.read(new_data),
sdbusplus::exception::InvalidEnumString);
}
};
TEST_F(Object, PlainEnumOne)
{
run_test<TestIf::EnumOne>(TestIf::EnumOne::OneA);
}
TEST_F(Object, PlainEnumTwo)
{
run_test<TestIf::EnumTwo>(TestIf::EnumTwo::TwoB);
}
TEST_F(Object, EnumOneAsEnumTwoThrows)
{
run_test_throw_bad_enum<TestIf::EnumOne, TestIf::EnumTwo>(
TestIf::EnumOne::OneA);
}
TEST_F(Object, EnumTwoAsEnumOneThrows)
{
run_test_throw_bad_enum<TestIf::EnumTwo, TestIf::EnumOne>(
TestIf::EnumTwo::TwoB);
}
TEST_F(Object, DISABLED_VariantAsString)
{
run_test<variant_t>(std::string("Hello"));
}
TEST_F(Object, VariantAsEnumOne)
{
run_test<variant_t>(TestIf::EnumOne::OneA);
}
TEST_F(Object, DISABLED_VariantAsEnumTwo)
{
run_test<variant_t>(TestIf::EnumTwo::TwoB);
}