195269dbcSPatrick Venture #include <systemd/sd-bus-protocol.h>
295269dbcSPatrick Venture
313367e49SWilliam A. Kennington III #include <sdbusplus/exception.hpp>
44fe85a30SPatrick Williams #include <sdbusplus/message.hpp>
5b4b4fa1fSWilliam A. Kennington III #include <sdbusplus/test/sdbus_mock.hpp>
6127b8abeSPatrick Williams
7127b8abeSPatrick Williams #include <cerrno>
8127b8abeSPatrick Williams #include <map>
928dc36d5SEd Tanous #include <set>
10b4b4fa1fSWilliam A. Kennington III #include <string>
11b4b4fa1fSWilliam A. Kennington III #include <tuple>
12b4b4fa1fSWilliam A. Kennington III #include <unordered_map>
13b98bdc6fSPatrick Williams #include <unordered_set>
144274c117SWilliam A. Kennington III #include <variant>
15b4b4fa1fSWilliam A. Kennington III #include <vector>
164fe85a30SPatrick Williams
1795269dbcSPatrick Venture #include <gmock/gmock.h>
1895269dbcSPatrick Venture #include <gtest/gtest.h>
1995269dbcSPatrick Venture
20b4b4fa1fSWilliam A. Kennington III namespace
214fe85a30SPatrick Williams {
224fe85a30SPatrick Williams
23b4b4fa1fSWilliam A. Kennington III using testing::DoAll;
24b4b4fa1fSWilliam A. Kennington III using testing::Return;
25b4b4fa1fSWilliam A. Kennington III using testing::StrEq;
26b4b4fa1fSWilliam A. Kennington III
ACTION_TEMPLATE(AssignReadVal,HAS_1_TEMPLATE_PARAMS (typename,T),AND_1_VALUE_PARAMS (val))27b4b4fa1fSWilliam A. Kennington III ACTION_TEMPLATE(AssignReadVal, HAS_1_TEMPLATE_PARAMS(typename, T),
28b4b4fa1fSWilliam A. Kennington III AND_1_VALUE_PARAMS(val))
29b4b4fa1fSWilliam A. Kennington III {
30b4b4fa1fSWilliam A. Kennington III *static_cast<T*>(arg2) = val;
314fe85a30SPatrick Williams }
324fe85a30SPatrick Williams
33b4b4fa1fSWilliam A. Kennington III class ReadTest : public testing::Test
344fe85a30SPatrick Williams {
35b4b4fa1fSWilliam A. Kennington III protected:
36b4b4fa1fSWilliam A. Kennington III testing::StrictMock<sdbusplus::SdBusMock> mock;
374fe85a30SPatrick Williams
SetUp()38b4b4fa1fSWilliam A. Kennington III void SetUp() override
394fe85a30SPatrick Williams {
40b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_new_method_call(testing::_, testing::_,
41b4b4fa1fSWilliam A. Kennington III nullptr, nullptr,
42b4b4fa1fSWilliam A. Kennington III nullptr, nullptr))
43b4b4fa1fSWilliam A. Kennington III .WillRepeatedly(Return(0));
44cb2fbeb9SEd Tanous }
454fe85a30SPatrick Williams
new_message()4610d7aa12SPatrick Williams sdbusplus::message_t new_message()
474fe85a30SPatrick Williams {
48b4b4fa1fSWilliam A. Kennington III return sdbusplus::get_mocked_new(&mock).new_method_call(
49b4b4fa1fSWilliam A. Kennington III nullptr, nullptr, nullptr, nullptr);
504fe85a30SPatrick Williams }
514fe85a30SPatrick Williams
expect_basic_error(char type,int ret)5213367e49SWilliam A. Kennington III void expect_basic_error(char type, int ret)
5313367e49SWilliam A. Kennington III {
5413367e49SWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_read_basic(nullptr, type, testing::_))
5513367e49SWilliam A. Kennington III .WillOnce(Return(ret));
5613367e49SWilliam A. Kennington III }
5713367e49SWilliam A. Kennington III
582b238afbSPatrick Venture template <typename T>
expect_basic(char type,T val)592b238afbSPatrick Venture void expect_basic(char type, T val)
604fe85a30SPatrick Williams {
61b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_read_basic(nullptr, type, testing::_))
62b4b4fa1fSWilliam A. Kennington III .WillOnce(DoAll(AssignReadVal<T>(val), Return(0)));
63b4b4fa1fSWilliam A. Kennington III }
644fe85a30SPatrick Williams
expect_verify_type(char type,const char * contents,int ret)65b4b4fa1fSWilliam A. Kennington III void expect_verify_type(char type, const char* contents, int ret)
664fe85a30SPatrick Williams {
67b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock,
68b4b4fa1fSWilliam A. Kennington III sd_bus_message_verify_type(nullptr, type, StrEq(contents)))
69b4b4fa1fSWilliam A. Kennington III .WillOnce(Return(ret));
70b4b4fa1fSWilliam A. Kennington III }
714fe85a30SPatrick Williams
expect_at_end(bool complete,int ret)72b4b4fa1fSWilliam A. Kennington III void expect_at_end(bool complete, int ret)
73b4b4fa1fSWilliam A. Kennington III {
74b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_at_end(nullptr, complete))
75b4b4fa1fSWilliam A. Kennington III .WillOnce(Return(ret));
76b4b4fa1fSWilliam A. Kennington III }
77b4b4fa1fSWilliam A. Kennington III
expect_skip(const char * contents,int ret=0)7813367e49SWilliam A. Kennington III void expect_skip(const char* contents, int ret = 0)
7960a72835SWilliam A. Kennington III {
8060a72835SWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_skip(nullptr, StrEq(contents)))
8113367e49SWilliam A. Kennington III .WillOnce(Return(ret));
8260a72835SWilliam A. Kennington III }
8360a72835SWilliam A. Kennington III
expect_enter_container(char type,const char * contents,int ret=0)8413367e49SWilliam A. Kennington III void expect_enter_container(char type, const char* contents, int ret = 0)
85b4b4fa1fSWilliam A. Kennington III {
86b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_enter_container(nullptr, type,
87b4b4fa1fSWilliam A. Kennington III StrEq(contents)))
8813367e49SWilliam A. Kennington III .WillOnce(Return(ret));
89b4b4fa1fSWilliam A. Kennington III }
90b4b4fa1fSWilliam A. Kennington III
expect_exit_container(int ret=0)9113367e49SWilliam A. Kennington III void expect_exit_container(int ret = 0)
92b4b4fa1fSWilliam A. Kennington III {
93b4b4fa1fSWilliam A. Kennington III EXPECT_CALL(mock, sd_bus_message_exit_container(nullptr))
9413367e49SWilliam A. Kennington III .WillOnce(Return(ret));
95b4b4fa1fSWilliam A. Kennington III }
96b4b4fa1fSWilliam A. Kennington III };
97b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,Int)98b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Int)
99b4b4fa1fSWilliam A. Kennington III {
100b4b4fa1fSWilliam A. Kennington III const int i = 1;
101b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, i);
102b4b4fa1fSWilliam A. Kennington III int ret;
103b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
104b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(i, ret);
105b4b4fa1fSWilliam A. Kennington III }
106b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,Bool)107b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Bool)
108b4b4fa1fSWilliam A. Kennington III {
109b4b4fa1fSWilliam A. Kennington III const bool b = true;
110b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_BOOLEAN, b);
111b4b4fa1fSWilliam A. Kennington III bool ret;
112b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
113b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(b, ret);
114b4b4fa1fSWilliam A. Kennington III }
115b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,Double)116b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Double)
117b4b4fa1fSWilliam A. Kennington III {
118b4b4fa1fSWilliam A. Kennington III const double d = 1.1;
119b4b4fa1fSWilliam A. Kennington III expect_basic<double>(SD_BUS_TYPE_DOUBLE, d);
120b4b4fa1fSWilliam A. Kennington III double ret;
121b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
122b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(d, ret);
123b4b4fa1fSWilliam A. Kennington III }
124b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,CString)125b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, CString)
126b4b4fa1fSWilliam A. Kennington III {
127b4b4fa1fSWilliam A. Kennington III const char* const s = "asdf";
128b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, s);
129b4b4fa1fSWilliam A. Kennington III const char* ret;
130b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
131b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(s, ret);
132b4b4fa1fSWilliam A. Kennington III }
133b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,String)134b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, String)
135b4b4fa1fSWilliam A. Kennington III {
136b4b4fa1fSWilliam A. Kennington III const char* const s = "fsda";
137b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, s);
138b4b4fa1fSWilliam A. Kennington III std::string ret;
139b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
140b4b4fa1fSWilliam A. Kennington III // Pointer comparison here is intentional as we don't expect a copy
141b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(s, ret);
142b4b4fa1fSWilliam A. Kennington III }
143b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,ObjectPath)144b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, ObjectPath)
145b4b4fa1fSWilliam A. Kennington III {
146b4b4fa1fSWilliam A. Kennington III const char* const s = "/fsda";
147b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_OBJECT_PATH, s);
148b4b4fa1fSWilliam A. Kennington III sdbusplus::message::object_path ret;
149b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
150b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(s, ret.str);
151b4b4fa1fSWilliam A. Kennington III }
152b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,Signature)153b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Signature)
154b4b4fa1fSWilliam A. Kennington III {
155b4b4fa1fSWilliam A. Kennington III const char* const s = "{ii}";
156b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_SIGNATURE, s);
157b4b4fa1fSWilliam A. Kennington III sdbusplus::message::signature ret;
158b4b4fa1fSWilliam A. Kennington III new_message().read(ret);
159b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(s, ret.str);
160b4b4fa1fSWilliam A. Kennington III }
161b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,UnixFd)1627770d2b9SPatrick Williams TEST_F(ReadTest, UnixFd)
1637770d2b9SPatrick Williams {
1647770d2b9SPatrick Williams const int fd = 42;
1657770d2b9SPatrick Williams expect_basic<int>(SD_BUS_TYPE_UNIX_FD, fd);
1667770d2b9SPatrick Williams sdbusplus::message::unix_fd ret;
1677770d2b9SPatrick Williams new_message().read(ret);
1687770d2b9SPatrick Williams EXPECT_EQ(fd, ret);
1697770d2b9SPatrick Williams }
1707770d2b9SPatrick Williams
TEST_F(ReadTest,CombinedBasic)171b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, CombinedBasic)
172b4b4fa1fSWilliam A. Kennington III {
173b4b4fa1fSWilliam A. Kennington III const double a = 2.2;
174b4b4fa1fSWilliam A. Kennington III const char* const b = "ijkd";
175b4b4fa1fSWilliam A. Kennington III const bool c = false;
176b4b4fa1fSWilliam A. Kennington III const int d = 18;
177b4b4fa1fSWilliam A. Kennington III
178b4b4fa1fSWilliam A. Kennington III {
179b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
180b4b4fa1fSWilliam A. Kennington III expect_basic<double>(SD_BUS_TYPE_DOUBLE, a);
181b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, b);
182b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_BOOLEAN, c);
183b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, d);
184b4b4fa1fSWilliam A. Kennington III }
185b4b4fa1fSWilliam A. Kennington III
186b4b4fa1fSWilliam A. Kennington III double ret_a;
187b4b4fa1fSWilliam A. Kennington III const char* ret_b;
188b4b4fa1fSWilliam A. Kennington III bool ret_c;
189b4b4fa1fSWilliam A. Kennington III int ret_d;
190b4b4fa1fSWilliam A. Kennington III new_message().read(ret_a, ret_b, ret_c, ret_d);
191b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(a, ret_a);
192b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(b, ret_b);
193b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(c, ret_c);
194b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(d, ret_d);
195b4b4fa1fSWilliam A. Kennington III }
196b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,BasicError)19713367e49SWilliam A. Kennington III TEST_F(ReadTest, BasicError)
19813367e49SWilliam A. Kennington III {
19913367e49SWilliam A. Kennington III expect_basic_error(SD_BUS_TYPE_INT32, -EINVAL);
20013367e49SWilliam A. Kennington III int ret;
20113367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
20213367e49SWilliam A. Kennington III }
20313367e49SWilliam A. Kennington III
TEST_F(ReadTest,BasicStringError)20413367e49SWilliam A. Kennington III TEST_F(ReadTest, BasicStringError)
20513367e49SWilliam A. Kennington III {
20613367e49SWilliam A. Kennington III expect_basic_error(SD_BUS_TYPE_STRING, -EINVAL);
20713367e49SWilliam A. Kennington III std::string ret;
20813367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
20913367e49SWilliam A. Kennington III }
21013367e49SWilliam A. Kennington III
TEST_F(ReadTest,BasicStringWrapperError)21113367e49SWilliam A. Kennington III TEST_F(ReadTest, BasicStringWrapperError)
21213367e49SWilliam A. Kennington III {
21313367e49SWilliam A. Kennington III expect_basic_error(SD_BUS_TYPE_SIGNATURE, -EINVAL);
21413367e49SWilliam A. Kennington III sdbusplus::message::signature ret;
21513367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
21613367e49SWilliam A. Kennington III }
21713367e49SWilliam A. Kennington III
TEST_F(ReadTest,BasicBoolError)21813367e49SWilliam A. Kennington III TEST_F(ReadTest, BasicBoolError)
21913367e49SWilliam A. Kennington III {
22013367e49SWilliam A. Kennington III expect_basic_error(SD_BUS_TYPE_BOOLEAN, -EINVAL);
22113367e49SWilliam A. Kennington III bool ret;
22213367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
22313367e49SWilliam A. Kennington III }
22413367e49SWilliam A. Kennington III
TEST_F(ReadTest,Vector)225b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Vector)
226b4b4fa1fSWilliam A. Kennington III {
227b4b4fa1fSWilliam A. Kennington III const std::vector<int> vi{1, 2, 3, 4};
228b4b4fa1fSWilliam A. Kennington III
229b4b4fa1fSWilliam A. Kennington III {
230b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
231b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "i");
232b4b4fa1fSWilliam A. Kennington III for (const auto& i : vi)
233b4b4fa1fSWilliam A. Kennington III {
234b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
235b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, i);
236b4b4fa1fSWilliam A. Kennington III }
237b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
238b4b4fa1fSWilliam A. Kennington III expect_exit_container();
239b4b4fa1fSWilliam A. Kennington III }
240b4b4fa1fSWilliam A. Kennington III
241b4b4fa1fSWilliam A. Kennington III std::vector<int> ret_vi;
242b4b4fa1fSWilliam A. Kennington III new_message().read(ret_vi);
243b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(vi, ret_vi);
244b4b4fa1fSWilliam A. Kennington III }
245b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,VectorEnterError)24613367e49SWilliam A. Kennington III TEST_F(ReadTest, VectorEnterError)
24713367e49SWilliam A. Kennington III {
24813367e49SWilliam A. Kennington III {
24913367e49SWilliam A. Kennington III testing::InSequence seq;
25013367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "i", -EINVAL);
25113367e49SWilliam A. Kennington III }
25213367e49SWilliam A. Kennington III
25313367e49SWilliam A. Kennington III std::vector<int> ret;
25413367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
25513367e49SWilliam A. Kennington III }
25613367e49SWilliam A. Kennington III
TEST_F(ReadTest,VectorIterError)25713367e49SWilliam A. Kennington III TEST_F(ReadTest, VectorIterError)
25813367e49SWilliam A. Kennington III {
25913367e49SWilliam A. Kennington III {
26013367e49SWilliam A. Kennington III testing::InSequence seq;
26113367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "i");
26213367e49SWilliam A. Kennington III expect_at_end(false, 0);
26313367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
26413367e49SWilliam A. Kennington III expect_at_end(false, -EINVAL);
26513367e49SWilliam A. Kennington III }
26613367e49SWilliam A. Kennington III
26713367e49SWilliam A. Kennington III std::vector<int> ret;
26813367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
26913367e49SWilliam A. Kennington III }
27013367e49SWilliam A. Kennington III
TEST_F(ReadTest,VectorExitError)27113367e49SWilliam A. Kennington III TEST_F(ReadTest, VectorExitError)
27213367e49SWilliam A. Kennington III {
27313367e49SWilliam A. Kennington III {
27413367e49SWilliam A. Kennington III testing::InSequence seq;
27513367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "i");
27613367e49SWilliam A. Kennington III expect_at_end(false, 0);
27713367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
27813367e49SWilliam A. Kennington III expect_at_end(false, 0);
27913367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 2);
28013367e49SWilliam A. Kennington III expect_at_end(false, 1);
28113367e49SWilliam A. Kennington III expect_exit_container(-EINVAL);
28213367e49SWilliam A. Kennington III }
28313367e49SWilliam A. Kennington III
28413367e49SWilliam A. Kennington III std::vector<int> ret;
28513367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
28613367e49SWilliam A. Kennington III }
28713367e49SWilliam A. Kennington III
TEST_F(ReadTest,Set)288b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Set)
289b4b4fa1fSWilliam A. Kennington III {
290b4b4fa1fSWilliam A. Kennington III const std::set<std::string> ss{"one", "two", "eight"};
291b4b4fa1fSWilliam A. Kennington III
292b4b4fa1fSWilliam A. Kennington III {
293b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
294b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "s");
295b4b4fa1fSWilliam A. Kennington III for (const auto& s : ss)
296b4b4fa1fSWilliam A. Kennington III {
297b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
298b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, s.c_str());
299b4b4fa1fSWilliam A. Kennington III }
300b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
301b4b4fa1fSWilliam A. Kennington III expect_exit_container();
302b4b4fa1fSWilliam A. Kennington III }
303b4b4fa1fSWilliam A. Kennington III
304b4b4fa1fSWilliam A. Kennington III std::set<std::string> ret_ss;
305b4b4fa1fSWilliam A. Kennington III new_message().read(ret_ss);
306b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(ss, ret_ss);
307b4b4fa1fSWilliam A. Kennington III }
308b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,UnorderedSet)309b98bdc6fSPatrick Williams TEST_F(ReadTest, UnorderedSet)
310b98bdc6fSPatrick Williams {
311b98bdc6fSPatrick Williams const std::unordered_set<std::string> ss{"one", "two", "eight"};
312b98bdc6fSPatrick Williams
313b98bdc6fSPatrick Williams {
314b98bdc6fSPatrick Williams testing::InSequence seq;
315b98bdc6fSPatrick Williams expect_enter_container(SD_BUS_TYPE_ARRAY, "s");
316b98bdc6fSPatrick Williams for (const auto& s : ss)
317b98bdc6fSPatrick Williams {
318b98bdc6fSPatrick Williams expect_at_end(false, 0);
319b98bdc6fSPatrick Williams expect_basic<const char*>(SD_BUS_TYPE_STRING, s.c_str());
320b98bdc6fSPatrick Williams }
321b98bdc6fSPatrick Williams expect_at_end(false, 1);
322b98bdc6fSPatrick Williams expect_exit_container();
323b98bdc6fSPatrick Williams }
324b98bdc6fSPatrick Williams
325b98bdc6fSPatrick Williams std::unordered_set<std::string> ret_ss;
326b98bdc6fSPatrick Williams new_message().read(ret_ss);
327b98bdc6fSPatrick Williams EXPECT_EQ(ss, ret_ss);
328b98bdc6fSPatrick Williams }
329b98bdc6fSPatrick Williams
TEST_F(ReadTest,Map)330b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Map)
331b4b4fa1fSWilliam A. Kennington III {
332b4b4fa1fSWilliam A. Kennington III const std::map<int, std::string> mis{
333b4b4fa1fSWilliam A. Kennington III {1, "a"},
334b4b4fa1fSWilliam A. Kennington III {2, "bc"},
335b4b4fa1fSWilliam A. Kennington III {3, "def"},
336b4b4fa1fSWilliam A. Kennington III {4, "ghij"},
337b4b4fa1fSWilliam A. Kennington III };
338b4b4fa1fSWilliam A. Kennington III
339b4b4fa1fSWilliam A. Kennington III {
340b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
341b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{is}");
342b4b4fa1fSWilliam A. Kennington III for (const auto& is : mis)
343b4b4fa1fSWilliam A. Kennington III {
344b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
345b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "is");
346b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, is.first);
347b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, is.second.c_str());
348b4b4fa1fSWilliam A. Kennington III expect_exit_container();
349b4b4fa1fSWilliam A. Kennington III }
350b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
351b4b4fa1fSWilliam A. Kennington III expect_exit_container();
352b4b4fa1fSWilliam A. Kennington III }
353b4b4fa1fSWilliam A. Kennington III
354b4b4fa1fSWilliam A. Kennington III std::map<int, std::string> ret_mis;
355b4b4fa1fSWilliam A. Kennington III new_message().read(ret_mis);
356b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(mis, ret_mis);
357b4b4fa1fSWilliam A. Kennington III }
358b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,MapEnterError)35913367e49SWilliam A. Kennington III TEST_F(ReadTest, MapEnterError)
36013367e49SWilliam A. Kennington III {
36113367e49SWilliam A. Kennington III {
36213367e49SWilliam A. Kennington III testing::InSequence seq;
36313367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{si}", -EINVAL);
36413367e49SWilliam A. Kennington III }
36513367e49SWilliam A. Kennington III
36613367e49SWilliam A. Kennington III std::map<std::string, int> ret;
36713367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
36813367e49SWilliam A. Kennington III }
36913367e49SWilliam A. Kennington III
TEST_F(ReadTest,MapEntryEnterError)37013367e49SWilliam A. Kennington III TEST_F(ReadTest, MapEntryEnterError)
37113367e49SWilliam A. Kennington III {
37213367e49SWilliam A. Kennington III {
37313367e49SWilliam A. Kennington III testing::InSequence seq;
37413367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{si}");
37513367e49SWilliam A. Kennington III expect_at_end(false, 0);
37613367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "si", -EINVAL);
37713367e49SWilliam A. Kennington III }
37813367e49SWilliam A. Kennington III
37913367e49SWilliam A. Kennington III std::map<std::string, int> ret;
38013367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
38113367e49SWilliam A. Kennington III }
38213367e49SWilliam A. Kennington III
TEST_F(ReadTest,MapEntryExitError)38313367e49SWilliam A. Kennington III TEST_F(ReadTest, MapEntryExitError)
38413367e49SWilliam A. Kennington III {
38513367e49SWilliam A. Kennington III {
38613367e49SWilliam A. Kennington III testing::InSequence seq;
38713367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{si}");
38813367e49SWilliam A. Kennington III expect_at_end(false, 0);
38913367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "si");
39013367e49SWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, "ab");
39113367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
39213367e49SWilliam A. Kennington III expect_exit_container(-EINVAL);
39313367e49SWilliam A. Kennington III }
39413367e49SWilliam A. Kennington III
39513367e49SWilliam A. Kennington III std::map<std::string, int> ret;
39613367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
39713367e49SWilliam A. Kennington III }
39813367e49SWilliam A. Kennington III
TEST_F(ReadTest,MapIterError)39913367e49SWilliam A. Kennington III TEST_F(ReadTest, MapIterError)
40013367e49SWilliam A. Kennington III {
40113367e49SWilliam A. Kennington III {
40213367e49SWilliam A. Kennington III testing::InSequence seq;
40313367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{si}");
40413367e49SWilliam A. Kennington III expect_at_end(false, 0);
40513367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "si");
40613367e49SWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, "ab");
40713367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
40813367e49SWilliam A. Kennington III expect_exit_container();
40913367e49SWilliam A. Kennington III expect_at_end(false, -EINVAL);
41013367e49SWilliam A. Kennington III }
41113367e49SWilliam A. Kennington III
41213367e49SWilliam A. Kennington III std::map<std::string, int> ret;
41313367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
41413367e49SWilliam A. Kennington III }
41513367e49SWilliam A. Kennington III
TEST_F(ReadTest,MapExitError)41613367e49SWilliam A. Kennington III TEST_F(ReadTest, MapExitError)
41713367e49SWilliam A. Kennington III {
41813367e49SWilliam A. Kennington III {
41913367e49SWilliam A. Kennington III testing::InSequence seq;
42013367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{si}");
42113367e49SWilliam A. Kennington III expect_at_end(false, 0);
42213367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "si");
42313367e49SWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, "ab");
42413367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
42513367e49SWilliam A. Kennington III expect_exit_container();
42613367e49SWilliam A. Kennington III expect_at_end(false, 1);
42713367e49SWilliam A. Kennington III expect_exit_container(-EINVAL);
42813367e49SWilliam A. Kennington III }
42913367e49SWilliam A. Kennington III
43013367e49SWilliam A. Kennington III std::map<std::string, int> ret;
43113367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
43213367e49SWilliam A. Kennington III }
43313367e49SWilliam A. Kennington III
TEST_F(ReadTest,UnorderedMap)434b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, UnorderedMap)
435b4b4fa1fSWilliam A. Kennington III {
436b4b4fa1fSWilliam A. Kennington III const std::unordered_map<int, std::string> mis{
437b4b4fa1fSWilliam A. Kennington III {1, "a"},
438b4b4fa1fSWilliam A. Kennington III {2, "bc"},
439b4b4fa1fSWilliam A. Kennington III {3, "def"},
440b4b4fa1fSWilliam A. Kennington III {4, "ghij"},
441b4b4fa1fSWilliam A. Kennington III };
442b4b4fa1fSWilliam A. Kennington III
443b4b4fa1fSWilliam A. Kennington III {
444b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
445b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{is}");
446b4b4fa1fSWilliam A. Kennington III for (const auto& is : mis)
447b4b4fa1fSWilliam A. Kennington III {
448b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
449b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "is");
450b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, is.first);
451b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, is.second.c_str());
452b4b4fa1fSWilliam A. Kennington III expect_exit_container();
453b4b4fa1fSWilliam A. Kennington III }
454b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
455b4b4fa1fSWilliam A. Kennington III expect_exit_container();
456b4b4fa1fSWilliam A. Kennington III }
457b4b4fa1fSWilliam A. Kennington III
458b4b4fa1fSWilliam A. Kennington III std::unordered_map<int, std::string> ret_mis;
459b4b4fa1fSWilliam A. Kennington III new_message().read(ret_mis);
460b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(mis, ret_mis);
461b4b4fa1fSWilliam A. Kennington III }
462b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,Tuple)463b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Tuple)
464b4b4fa1fSWilliam A. Kennington III {
465b4b4fa1fSWilliam A. Kennington III const std::tuple<int, std::string, bool> tisb{3, "hi", false};
466b4b4fa1fSWilliam A. Kennington III
467b4b4fa1fSWilliam A. Kennington III {
468b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
469b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_STRUCT, "isb");
470b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, std::get<0>(tisb));
471b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING,
472b4b4fa1fSWilliam A. Kennington III std::get<1>(tisb).c_str());
473b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_BOOLEAN, std::get<2>(tisb));
474b4b4fa1fSWilliam A. Kennington III expect_exit_container();
475b4b4fa1fSWilliam A. Kennington III }
476b4b4fa1fSWilliam A. Kennington III
477b4b4fa1fSWilliam A. Kennington III std::tuple<int, std::string, bool> ret_tisb;
478b4b4fa1fSWilliam A. Kennington III new_message().read(ret_tisb);
479b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(tisb, ret_tisb);
480b4b4fa1fSWilliam A. Kennington III }
481b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,TupleEnterError)48213367e49SWilliam A. Kennington III TEST_F(ReadTest, TupleEnterError)
48313367e49SWilliam A. Kennington III {
48413367e49SWilliam A. Kennington III {
48513367e49SWilliam A. Kennington III testing::InSequence seq;
48613367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_STRUCT, "bis", -EINVAL);
48713367e49SWilliam A. Kennington III }
48813367e49SWilliam A. Kennington III
48913367e49SWilliam A. Kennington III std::tuple<bool, int, std::string> ret;
49013367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
49113367e49SWilliam A. Kennington III }
49213367e49SWilliam A. Kennington III
TEST_F(ReadTest,TupleExitError)49313367e49SWilliam A. Kennington III TEST_F(ReadTest, TupleExitError)
49413367e49SWilliam A. Kennington III {
49513367e49SWilliam A. Kennington III {
49613367e49SWilliam A. Kennington III testing::InSequence seq;
49713367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_STRUCT, "bis");
49813367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_BOOLEAN, false);
49913367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 1);
50013367e49SWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, "ab");
50113367e49SWilliam A. Kennington III expect_exit_container(-EINVAL);
50213367e49SWilliam A. Kennington III }
50313367e49SWilliam A. Kennington III
50413367e49SWilliam A. Kennington III std::tuple<bool, int, std::string> ret;
50513367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
50613367e49SWilliam A. Kennington III }
50713367e49SWilliam A. Kennington III
TEST_F(ReadTest,Variant)508b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, Variant)
509b4b4fa1fSWilliam A. Kennington III {
510b4b4fa1fSWilliam A. Kennington III const bool b1 = false;
511b4b4fa1fSWilliam A. Kennington III const std::string s2{"asdf"};
5124274c117SWilliam A. Kennington III const std::variant<int, std::string, bool> v1{b1}, v2{s2};
513b4b4fa1fSWilliam A. Kennington III
514b4b4fa1fSWilliam A. Kennington III {
515b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
516b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", false);
517b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "s", false);
518b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "b", true);
519b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "b");
520b4b4fa1fSWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_BOOLEAN, b1);
521b4b4fa1fSWilliam A. Kennington III expect_exit_container();
522b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", false);
523b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "s", true);
524b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "s");
525b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, s2.c_str());
526b4b4fa1fSWilliam A. Kennington III expect_exit_container();
527b4b4fa1fSWilliam A. Kennington III }
528b4b4fa1fSWilliam A. Kennington III
5294274c117SWilliam A. Kennington III std::variant<int, std::string, bool> ret_v1, ret_v2;
530b4b4fa1fSWilliam A. Kennington III new_message().read(ret_v1, ret_v2);
531b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(v1, ret_v1);
532b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(v2, ret_v2);
533b4b4fa1fSWilliam A. Kennington III }
534b4b4fa1fSWilliam A. Kennington III
TEST_F(ReadTest,VariantVerifyError)53513367e49SWilliam A. Kennington III TEST_F(ReadTest, VariantVerifyError)
53613367e49SWilliam A. Kennington III {
53713367e49SWilliam A. Kennington III {
53813367e49SWilliam A. Kennington III testing::InSequence seq;
53913367e49SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", -EINVAL);
54013367e49SWilliam A. Kennington III }
54113367e49SWilliam A. Kennington III
5424274c117SWilliam A. Kennington III std::variant<int, bool> ret;
54313367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
54413367e49SWilliam A. Kennington III }
54513367e49SWilliam A. Kennington III
TEST_F(ReadTest,VariantSkipUnmatched)54660a72835SWilliam A. Kennington III TEST_F(ReadTest, VariantSkipUnmatched)
54760a72835SWilliam A. Kennington III {
54860a72835SWilliam A. Kennington III {
54960a72835SWilliam A. Kennington III testing::InSequence seq;
55060a72835SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", false);
55160a72835SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "b", false);
55260a72835SWilliam A. Kennington III expect_skip("v");
55360a72835SWilliam A. Kennington III }
55413367e49SWilliam A. Kennington III
5554274c117SWilliam A. Kennington III std::variant<int, bool> ret;
55660a72835SWilliam A. Kennington III new_message().read(ret);
55760a72835SWilliam A. Kennington III }
55860a72835SWilliam A. Kennington III
TEST_F(ReadTest,VariantSkipError)55913367e49SWilliam A. Kennington III TEST_F(ReadTest, VariantSkipError)
56013367e49SWilliam A. Kennington III {
56113367e49SWilliam A. Kennington III {
56213367e49SWilliam A. Kennington III testing::InSequence seq;
56313367e49SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", false);
56413367e49SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "b", false);
56513367e49SWilliam A. Kennington III expect_skip("v", -EINVAL);
56613367e49SWilliam A. Kennington III }
56713367e49SWilliam A. Kennington III
5684274c117SWilliam A. Kennington III std::variant<int, bool> ret;
56913367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
57013367e49SWilliam A. Kennington III }
57113367e49SWilliam A. Kennington III
TEST_F(ReadTest,VariantEnterError)57213367e49SWilliam A. Kennington III TEST_F(ReadTest, VariantEnterError)
57313367e49SWilliam A. Kennington III {
57413367e49SWilliam A. Kennington III {
57513367e49SWilliam A. Kennington III testing::InSequence seq;
57613367e49SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", true);
57713367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "i", -EINVAL);
57813367e49SWilliam A. Kennington III }
57913367e49SWilliam A. Kennington III
5804274c117SWilliam A. Kennington III std::variant<int, bool> ret;
58113367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
58213367e49SWilliam A. Kennington III }
58313367e49SWilliam A. Kennington III
TEST_F(ReadTest,VariantExitError)58413367e49SWilliam A. Kennington III TEST_F(ReadTest, VariantExitError)
58513367e49SWilliam A. Kennington III {
58613367e49SWilliam A. Kennington III {
58713367e49SWilliam A. Kennington III testing::InSequence seq;
58813367e49SWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", true);
58913367e49SWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "i");
59013367e49SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, 10);
59113367e49SWilliam A. Kennington III expect_exit_container(-EINVAL);
59213367e49SWilliam A. Kennington III }
59313367e49SWilliam A. Kennington III
5944274c117SWilliam A. Kennington III std::variant<int, bool> ret;
59513367e49SWilliam A. Kennington III EXPECT_THROW(new_message().read(ret), sdbusplus::exception::SdBusError);
59613367e49SWilliam A. Kennington III }
59713367e49SWilliam A. Kennington III
TEST_F(ReadTest,LargeCombo)598b4b4fa1fSWilliam A. Kennington III TEST_F(ReadTest, LargeCombo)
599b4b4fa1fSWilliam A. Kennington III {
600b4b4fa1fSWilliam A. Kennington III const std::vector<std::set<std::string>> vas{
601b4b4fa1fSWilliam A. Kennington III {"a", "b", "c"},
602b4b4fa1fSWilliam A. Kennington III {"d", "", "e"},
603b4b4fa1fSWilliam A. Kennington III };
6044274c117SWilliam A. Kennington III const std::map<std::string, std::variant<int, double>> msv = {
6054274c117SWilliam A. Kennington III {"a", 3.3}, {"b", 1}, {"c", 4.4}};
606b4b4fa1fSWilliam A. Kennington III
607b4b4fa1fSWilliam A. Kennington III {
608b4b4fa1fSWilliam A. Kennington III testing::InSequence seq;
609b4b4fa1fSWilliam A. Kennington III
610b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "as");
611b4b4fa1fSWilliam A. Kennington III for (const auto& as : vas)
612b4b4fa1fSWilliam A. Kennington III {
613b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
614b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "s");
615b4b4fa1fSWilliam A. Kennington III for (const auto& s : as)
616b4b4fa1fSWilliam A. Kennington III {
617b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
618b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, s.c_str());
619b4b4fa1fSWilliam A. Kennington III }
620b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
621b4b4fa1fSWilliam A. Kennington III expect_exit_container();
622b4b4fa1fSWilliam A. Kennington III }
623b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
624b4b4fa1fSWilliam A. Kennington III expect_exit_container();
625b4b4fa1fSWilliam A. Kennington III
626b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_ARRAY, "{sv}");
627b4b4fa1fSWilliam A. Kennington III for (const auto& sv : msv)
628b4b4fa1fSWilliam A. Kennington III {
629b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 0);
630b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_DICT_ENTRY, "sv");
631b4b4fa1fSWilliam A. Kennington III expect_basic<const char*>(SD_BUS_TYPE_STRING, sv.first.c_str());
6324274c117SWilliam A. Kennington III if (std::holds_alternative<int>(sv.second))
633b4b4fa1fSWilliam A. Kennington III {
634b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", true);
635b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "i");
6364274c117SWilliam A. Kennington III expect_basic<int>(SD_BUS_TYPE_INT32, std::get<int>(sv.second));
637b4b4fa1fSWilliam A. Kennington III expect_exit_container();
6384fe85a30SPatrick Williams }
6394fe85a30SPatrick Williams else
6404fe85a30SPatrick Williams {
641b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "i", false);
642b4b4fa1fSWilliam A. Kennington III expect_verify_type(SD_BUS_TYPE_VARIANT, "d", true);
643b4b4fa1fSWilliam A. Kennington III expect_enter_container(SD_BUS_TYPE_VARIANT, "d");
644b4b4fa1fSWilliam A. Kennington III expect_basic<double>(SD_BUS_TYPE_DOUBLE,
6454274c117SWilliam A. Kennington III std::get<double>(sv.second));
646b4b4fa1fSWilliam A. Kennington III expect_exit_container();
6474fe85a30SPatrick Williams }
648b4b4fa1fSWilliam A. Kennington III expect_exit_container();
6494fe85a30SPatrick Williams }
650b4b4fa1fSWilliam A. Kennington III expect_at_end(false, 1);
651b4b4fa1fSWilliam A. Kennington III expect_exit_container();
6524fe85a30SPatrick Williams }
653696e3159SPatrick Williams
654b4b4fa1fSWilliam A. Kennington III std::vector<std::set<std::string>> ret_vas;
6554274c117SWilliam A. Kennington III std::map<std::string, std::variant<int, double>> ret_msv;
656b4b4fa1fSWilliam A. Kennington III new_message().read(ret_vas, ret_msv);
657b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(vas, ret_vas);
658b4b4fa1fSWilliam A. Kennington III EXPECT_EQ(msv, ret_msv);
6594fe85a30SPatrick Williams }
6604fe85a30SPatrick Williams
6619cde21ffSPatrick Williams // Unpack tests.
6629cde21ffSPatrick Williams // Since unpack uses read, we're mostly just testing the compilation.
6639cde21ffSPatrick Williams // Duplicate a few tests from Read using 'unpack'.
6649cde21ffSPatrick Williams
TEST_F(ReadTest,UnpackSingleVector)6659cde21ffSPatrick Williams TEST_F(ReadTest, UnpackSingleVector)
6669cde21ffSPatrick Williams {
6679cde21ffSPatrick Williams const std::vector<int> vi{1, 2, 3, 4};
6689cde21ffSPatrick Williams
6699cde21ffSPatrick Williams {
6709cde21ffSPatrick Williams testing::InSequence seq;
6719cde21ffSPatrick Williams expect_enter_container(SD_BUS_TYPE_ARRAY, "i");
6729cde21ffSPatrick Williams for (const auto& i : vi)
6739cde21ffSPatrick Williams {
6749cde21ffSPatrick Williams expect_at_end(false, 0);
6759cde21ffSPatrick Williams expect_basic<int>(SD_BUS_TYPE_INT32, i);
6769cde21ffSPatrick Williams }
6779cde21ffSPatrick Williams expect_at_end(false, 1);
6789cde21ffSPatrick Williams expect_exit_container();
6799cde21ffSPatrick Williams }
6809cde21ffSPatrick Williams
6819cde21ffSPatrick Williams auto ret_vi = new_message().unpack<std::vector<int>>();
6829cde21ffSPatrick Williams EXPECT_EQ(vi, ret_vi);
6839cde21ffSPatrick Williams }
6849cde21ffSPatrick Williams
TEST_F(ReadTest,UnpackMultiple)6859cde21ffSPatrick Williams TEST_F(ReadTest, UnpackMultiple)
6869cde21ffSPatrick Williams {
6879cde21ffSPatrick Williams const std::tuple<int, std::string, bool> tisb{3, "hi", false};
6889cde21ffSPatrick Williams
6899cde21ffSPatrick Williams {
6909cde21ffSPatrick Williams testing::InSequence seq;
6919cde21ffSPatrick Williams expect_basic<int>(SD_BUS_TYPE_INT32, std::get<0>(tisb));
6929cde21ffSPatrick Williams expect_basic<const char*>(SD_BUS_TYPE_STRING,
6939cde21ffSPatrick Williams std::get<1>(tisb).c_str());
6949cde21ffSPatrick Williams expect_basic<int>(SD_BUS_TYPE_BOOLEAN, std::get<2>(tisb));
6959cde21ffSPatrick Williams }
6969cde21ffSPatrick Williams
6979cde21ffSPatrick Williams auto ret_tisb = new_message().unpack<int, std::string, bool>();
6989cde21ffSPatrick Williams EXPECT_EQ(tisb, ret_tisb);
6999cde21ffSPatrick Williams }
7009cde21ffSPatrick Williams
TEST_F(ReadTest,UnpackStructuredBinding)7015f1c0bd5SPatrick Williams TEST_F(ReadTest, UnpackStructuredBinding)
7025f1c0bd5SPatrick Williams {
7035f1c0bd5SPatrick Williams const std::tuple<int, std::string, bool> tisb{3, "hi", false};
7045f1c0bd5SPatrick Williams
7055f1c0bd5SPatrick Williams {
7065f1c0bd5SPatrick Williams testing::InSequence seq;
7075f1c0bd5SPatrick Williams expect_basic<int>(SD_BUS_TYPE_INT32, std::get<0>(tisb));
7085f1c0bd5SPatrick Williams expect_basic<const char*>(SD_BUS_TYPE_STRING,
7095f1c0bd5SPatrick Williams std::get<1>(tisb).c_str());
7105f1c0bd5SPatrick Williams expect_basic<int>(SD_BUS_TYPE_BOOLEAN, std::get<2>(tisb));
7115f1c0bd5SPatrick Williams }
7125f1c0bd5SPatrick Williams
7135f1c0bd5SPatrick Williams auto [ret_ti, ret_ts,
7145f1c0bd5SPatrick Williams ret_tb] = new_message().unpack<int, std::string, bool>();
7155f1c0bd5SPatrick Williams EXPECT_EQ(tisb, std::make_tuple(ret_ti, ret_ts, ret_tb));
7165f1c0bd5SPatrick Williams }
7175f1c0bd5SPatrick Williams
TEST_F(ReadTest,UnpackVoid)718*88c6a823SLei YU TEST_F(ReadTest, UnpackVoid)
719*88c6a823SLei YU {
720*88c6a823SLei YU new_message().unpack<>();
721*88c6a823SLei YU new_message().unpack<void>();
722*88c6a823SLei YU }
723*88c6a823SLei YU
724b4b4fa1fSWilliam A. Kennington III } // namespace
725