| Ed Tanous | e8f2b0d | 2025-09-12 15:11:13 -0700 | [diff] [blame^] | 1 | #include <boost/system/error_code.hpp> |
| 2 | #include <sdbusplus/message.hpp> |
| 3 | #include <sdbusplus/utility/make_dbus_args_tuple.hpp> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace sdbusplus |
| 8 | { |
| 9 | namespace utility |
| 10 | { |
| 11 | |
| 12 | TEST(MakeDbusArgsTuple, MessageFirst) |
| 13 | { |
| 14 | std::tuple<boost::system::error_code, sdbusplus::message_t, int> |
| 15 | input_tuple; |
| 16 | auto tuple_out = make_dbus_args_tuple(input_tuple); |
| 17 | static_assert( |
| 18 | std::is_same_v<std::tuple_element_t<0, decltype(tuple_out)>, int&>, |
| 19 | "Second type wasn't int"); |
| 20 | static_assert(std::tuple_size_v<decltype(tuple_out)> == 1, |
| 21 | "Size was wrong"); |
| 22 | // Verify the output reference is now the first member, and references the 2 |
| 23 | // index tuple arg |
| 24 | EXPECT_EQ(&std::get<2>(input_tuple), &std::get<0>(tuple_out)); |
| 25 | } |
| 26 | TEST(MakeDbusArgsTuple, ArgFirst) |
| 27 | { |
| 28 | std::tuple<boost::system::error_code, int> input_tuple{ |
| 29 | boost::system::error_code(), 42}; |
| 30 | auto tuple_out = make_dbus_args_tuple(input_tuple); |
| 31 | static_assert( |
| 32 | std::is_same_v<std::tuple_element_t<0, decltype(tuple_out)>, int&>, |
| 33 | "Second type wasn't int"); |
| 34 | static_assert(std::tuple_size_v<decltype(tuple_out)> == 1, |
| 35 | "Size was wrong"); |
| 36 | // Verify the output reference is now the first member, and references the 1 |
| 37 | // index tuple arg |
| 38 | EXPECT_EQ(&std::get<1>(input_tuple), &std::get<0>(tuple_out)); |
| 39 | EXPECT_EQ(std::get<0>(tuple_out), 42); |
| 40 | } |
| 41 | TEST(MakeDbusArgsTuple, NoArgs) |
| 42 | { |
| 43 | std::tuple<boost::system::error_code> input_tuple; |
| 44 | auto tuple_out = make_dbus_args_tuple(input_tuple); |
| 45 | static_assert(std::tuple_size_v<decltype(tuple_out)> == 0, |
| 46 | "Size was wrong"); |
| 47 | } |
| 48 | } // namespace utility |
| 49 | } // namespace sdbusplus |