Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 1 | #include <iostream> |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 2 | #include <cassert> |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 3 | #include <sdbusplus/message.hpp> |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 5 | #include <unordered_map> |
| 6 | #include <set> |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 7 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 8 | // Make sure even in non-debug mode we use asserts |
| 9 | #define TEST_ASSERT(n) \ |
| 10 | do \ |
| 11 | { \ |
| 12 | if (!(n)) \ |
| 13 | { \ |
| 14 | fprintf(stderr, "%s:%d %s: Assertion `%s` failed\n", __FILE__, \ |
| 15 | __LINE__, __func__, #n); \ |
| 16 | abort(); \ |
| 17 | } \ |
| 18 | } while (0) |
| 19 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 20 | // Global to share the dbus type string between client and server. |
| 21 | static std::string verifyTypeString; |
| 22 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 23 | using verifyCallback_t = void (*)(sd_bus_message*); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 24 | verifyCallback_t verifyCallback = nullptr; |
| 25 | |
Patrick Williams | 24fb296 | 2016-11-04 17:08:59 -0500 | [diff] [blame] | 26 | static constexpr auto SERVICE = "sdbusplus.test.message.append"; |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 27 | static constexpr auto INTERFACE = SERVICE; |
| 28 | static constexpr auto TEST_METHOD = "test"; |
| 29 | static constexpr auto QUIT_METHOD = "quit"; |
| 30 | |
| 31 | // Open up the sdbus and claim SERVICE name. |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 32 | auto serverInit() |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 33 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 34 | auto b = sdbusplus::bus::new_default(); |
| 35 | b.request_name(SERVICE); |
| 36 | |
| 37 | return std::move(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // Thread to run the dbus server. |
| 41 | void* server(void* b) |
| 42 | { |
William A. Kennington III | b564550 | 2018-06-19 18:36:41 -0700 | [diff] [blame] | 43 | auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b), |
| 44 | std::false_type()); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 45 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 46 | while (1) |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 47 | { |
| 48 | // Wait for messages. |
Patrick Williams | 13b97c5 | 2016-09-09 09:36:55 -0500 | [diff] [blame] | 49 | auto m = bus.process().release(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 50 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 51 | if (m == nullptr) |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 52 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 53 | bus.wait(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 54 | continue; |
| 55 | } |
| 56 | |
| 57 | if (sd_bus_message_is_method_call(m, INTERFACE, TEST_METHOD)) |
| 58 | { |
| 59 | // Verify the message type matches what the test expects. |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 60 | TEST_ASSERT(verifyTypeString == |
| 61 | sd_bus_message_get_signature(m, true)); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 62 | if (verifyCallback) |
| 63 | { |
| 64 | verifyCallback(m); |
| 65 | verifyCallback = nullptr; |
| 66 | } |
| 67 | else |
| 68 | { |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 69 | std::cout << "Warning: No verification for " << verifyTypeString |
| 70 | << std::endl; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 71 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 72 | // Reply to client. |
| 73 | sd_bus_reply_method_return(m, nullptr); |
| 74 | } |
| 75 | else if (sd_bus_message_is_method_call(m, INTERFACE, QUIT_METHOD)) |
| 76 | { |
| 77 | // Reply and exit. |
| 78 | sd_bus_reply_method_return(m, nullptr); |
William A. Kennington III | b564550 | 2018-06-19 18:36:41 -0700 | [diff] [blame] | 79 | sd_bus_message_unref(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 80 | break; |
| 81 | } |
William A. Kennington III | b564550 | 2018-06-19 18:36:41 -0700 | [diff] [blame] | 82 | |
| 83 | sd_bus_message_unref(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 84 | } |
Patrick Williams | 696e315 | 2016-11-04 17:03:39 -0500 | [diff] [blame] | 85 | |
| 86 | return nullptr; |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 89 | auto newMethodCall__test(sdbusplus::bus::bus& b) |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 90 | { |
| 91 | // Allocate a method-call message for INTERFACE,TEST_METHOD. |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 92 | return b.new_method_call(SERVICE, "/", INTERFACE, TEST_METHOD); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void runTests() |
| 96 | { |
| 97 | using namespace std::literals; |
| 98 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 99 | auto b = sdbusplus::bus::new_default(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 100 | |
| 101 | // Test r-value int. |
| 102 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 103 | auto m = newMethodCall__test(b); |
| 104 | m.append(1); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 105 | verifyTypeString = "i"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 106 | |
| 107 | struct verify |
| 108 | { |
| 109 | static void op(sd_bus_message* m) |
| 110 | { |
| 111 | int32_t i = 0; |
| 112 | sd_bus_message_read_basic(m, 'i', &i); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 113 | TEST_ASSERT(i == 1); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 114 | } |
| 115 | }; |
| 116 | verifyCallback = &verify::op; |
| 117 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 118 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 119 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 120 | // Test l-value int. |
| 121 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 122 | auto m = newMethodCall__test(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 123 | int a = 1; |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 124 | m.append(a, a); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 125 | verifyTypeString = "ii"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 126 | |
| 127 | struct verify |
| 128 | { |
| 129 | static void op(sd_bus_message* m) |
| 130 | { |
| 131 | int32_t a = 0, b = 0; |
| 132 | sd_bus_message_read(m, "ii", &a, &b); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 133 | TEST_ASSERT(a == 1); |
| 134 | TEST_ASSERT(b == 1); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 135 | } |
| 136 | }; |
| 137 | verifyCallback = &verify::op; |
| 138 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 139 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // Test multiple ints. |
| 143 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 144 | auto m = newMethodCall__test(b); |
| 145 | m.append(1, 2, 3, 4, 5); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 146 | verifyTypeString = "iiiii"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 147 | |
| 148 | struct verify |
| 149 | { |
| 150 | static void op(sd_bus_message* m) |
| 151 | { |
| 152 | int32_t a = 0, b = 0, c = 0, d = 0, e = 0; |
| 153 | sd_bus_message_read(m, "iiiii", &a, &b, &c, &d, &e); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 154 | TEST_ASSERT(a == 1); |
| 155 | TEST_ASSERT(b == 2); |
| 156 | TEST_ASSERT(c == 3); |
| 157 | TEST_ASSERT(d == 4); |
| 158 | TEST_ASSERT(e == 5); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 159 | } |
| 160 | }; |
| 161 | verifyCallback = &verify::op; |
| 162 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 163 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 166 | // Test double and bool. |
| 167 | { |
| 168 | auto m = newMethodCall__test(b); |
| 169 | bool t = true; |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 170 | bool f = false; |
| 171 | bool f2 = false; |
| 172 | m.append(t, true, f, std::move(f2), false, 1.1); |
| 173 | verifyTypeString = "bbbbbd"; |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 174 | |
| 175 | struct verify |
| 176 | { |
| 177 | static void op(sd_bus_message* m) |
| 178 | { |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 179 | bool t1, t2, f1, f2, f3; |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 180 | double d; |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 181 | sd_bus_message_read(m, "bbbbbd", &t1, &t2, &f1, &f2, &f3, &d); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 182 | TEST_ASSERT(t1); |
| 183 | TEST_ASSERT(t2); |
| 184 | TEST_ASSERT(!f1); |
| 185 | TEST_ASSERT(!f2); |
| 186 | TEST_ASSERT(!f3); |
| 187 | TEST_ASSERT(d == 1.1); |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 188 | } |
| 189 | }; |
| 190 | verifyCallback = &verify::op; |
| 191 | |
| 192 | b.call_noreply(m); |
| 193 | } |
| 194 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 195 | // Test r-value string. |
| 196 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 197 | auto m = newMethodCall__test(b); |
| 198 | m.append("asdf"s); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 199 | verifyTypeString = "s"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 200 | |
| 201 | struct verify |
| 202 | { |
| 203 | static void op(sd_bus_message* m) |
| 204 | { |
| 205 | const char* s = nullptr; |
| 206 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 207 | TEST_ASSERT(0 == strcmp("asdf", s)); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 208 | } |
| 209 | }; |
| 210 | verifyCallback = &verify::op; |
| 211 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 212 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 213 | } |
| 214 | |
Patrick Williams | 16e1753 | 2017-02-15 10:23:22 -0600 | [diff] [blame] | 215 | // Test const string owned by const struct. openbmc/openbmc#1025 |
| 216 | { |
| 217 | struct |
| 218 | { |
| 219 | const char* foo; |
| 220 | |
| 221 | void insert(sdbusplus::message::message& m) |
| 222 | { |
| 223 | m.append(foo); |
| 224 | } |
| 225 | } s; |
| 226 | |
| 227 | auto m = newMethodCall__test(b); |
| 228 | s.foo = "1234"; |
| 229 | s.insert(m); |
| 230 | |
| 231 | verifyTypeString = "s"; |
| 232 | |
| 233 | struct verify |
| 234 | { |
| 235 | static void op(sd_bus_message* m) |
| 236 | { |
| 237 | const char* s = nullptr; |
| 238 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 239 | TEST_ASSERT(0 == strcmp("1234", s)); |
Patrick Williams | 16e1753 | 2017-02-15 10:23:22 -0600 | [diff] [blame] | 240 | } |
| 241 | }; |
| 242 | verifyCallback = &verify::op; |
| 243 | |
| 244 | b.call_noreply(m); |
| 245 | } |
| 246 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 247 | // Test multiple strings, various forms. |
| 248 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 249 | auto m = newMethodCall__test(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 250 | auto str = "jkl;"s; |
| 251 | auto str2 = "JKL:"s; |
Patrick Williams | 16e1753 | 2017-02-15 10:23:22 -0600 | [diff] [blame] | 252 | const char* str3 = "1234"; |
| 253 | const char* const str4 = "5678"; |
| 254 | const auto str5 = "!@#$"; |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 255 | m.append(1, "asdf", "ASDF"s, str, std::move(str2), str3, str4, str5, 5); |
Patrick Williams | 16e1753 | 2017-02-15 10:23:22 -0600 | [diff] [blame] | 256 | verifyTypeString = "isssssssi"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 257 | |
| 258 | struct verify |
| 259 | { |
| 260 | static void op(sd_bus_message* m) |
| 261 | { |
| 262 | int32_t a = 0, b = 0; |
| 263 | const char *s0 = nullptr, *s1 = nullptr, *s2 = nullptr, |
Patrick Williams | 16e1753 | 2017-02-15 10:23:22 -0600 | [diff] [blame] | 264 | *s3 = nullptr, *s4 = nullptr, *s5 = nullptr, |
| 265 | *s6 = nullptr; |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 266 | sd_bus_message_read(m, "isssssssi", &a, &s0, &s1, &s2, &s3, &s4, |
| 267 | &s5, &s6, &b); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 268 | TEST_ASSERT(a == 1); |
| 269 | TEST_ASSERT(b == 5); |
| 270 | TEST_ASSERT(0 == strcmp("asdf", s0)); |
| 271 | TEST_ASSERT(0 == strcmp("ASDF", s1)); |
| 272 | TEST_ASSERT(0 == strcmp("jkl;", s2)); |
| 273 | TEST_ASSERT(0 == strcmp("JKL:", s3)); |
| 274 | TEST_ASSERT(0 == strcmp("1234", s4)); |
| 275 | TEST_ASSERT(0 == strcmp("5678", s5)); |
| 276 | TEST_ASSERT(0 == strcmp("!@#$", s6)); |
| 277 | TEST_ASSERT(b == 5); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 278 | } |
| 279 | }; |
| 280 | verifyCallback = &verify::op; |
| 281 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 282 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Patrick Williams | fd3c462 | 2017-01-06 16:11:47 -0600 | [diff] [blame] | 285 | // Test object_path and signature. |
| 286 | { |
| 287 | auto m = newMethodCall__test(b); |
| 288 | auto o = sdbusplus::message::object_path("/asdf"); |
| 289 | auto s = sdbusplus::message::signature("iii"); |
| 290 | m.append(1, o, s, 4); |
| 291 | verifyTypeString = "iogi"; |
| 292 | |
| 293 | struct verify |
| 294 | { |
| 295 | static void op(sd_bus_message* m) |
| 296 | { |
| 297 | int32_t a = 0, b = 0; |
| 298 | const char *s0 = nullptr, *s1 = nullptr; |
| 299 | sd_bus_message_read(m, "iogi", &a, &s0, &s1, &b); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 300 | TEST_ASSERT(a == 1); |
| 301 | TEST_ASSERT(b == 4); |
| 302 | TEST_ASSERT(0 == strcmp("/asdf", s0)); |
| 303 | TEST_ASSERT(0 == strcmp("iii", s1)); |
Patrick Williams | fd3c462 | 2017-01-06 16:11:47 -0600 | [diff] [blame] | 304 | } |
| 305 | }; |
| 306 | verifyCallback = &verify::op; |
| 307 | |
| 308 | b.call_noreply(m); |
| 309 | } |
| 310 | |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 311 | // Test vector. |
| 312 | { |
| 313 | auto m = newMethodCall__test(b); |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 314 | std::vector<std::string> s{"1", "2", "3"}; |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 315 | m.append(1, s, 2); |
| 316 | verifyTypeString = "iasi"; |
| 317 | |
| 318 | struct verify |
| 319 | { |
| 320 | static void op(sd_bus_message* m) |
| 321 | { |
| 322 | int32_t a = 0; |
| 323 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 324 | TEST_ASSERT(a == 1); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 325 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 326 | auto rc = |
| 327 | sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 328 | TEST_ASSERT(0 <= rc); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 329 | |
| 330 | const char* s = nullptr; |
| 331 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 332 | TEST_ASSERT(0 == strcmp("1", s)); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 333 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 334 | TEST_ASSERT(0 == strcmp("2", s)); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 335 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 336 | TEST_ASSERT(0 == strcmp("3", s)); |
| 337 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 338 | |
| 339 | sd_bus_message_exit_container(m); |
| 340 | |
| 341 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 342 | TEST_ASSERT(a == 2); |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 343 | } |
| 344 | }; |
| 345 | verifyCallback = &verify::op; |
| 346 | |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 347 | b.call_noreply(m); |
| 348 | } |
| 349 | |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 350 | // Test map. |
| 351 | { |
| 352 | auto m = newMethodCall__test(b); |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 353 | std::map<std::string, int> s = {{"asdf", 3}, {"jkl;", 4}}; |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 354 | m.append(1, s, 2); |
| 355 | verifyTypeString = "ia{si}i"; |
| 356 | |
| 357 | struct verify |
| 358 | { |
| 359 | static void op(sd_bus_message* m) |
| 360 | { |
| 361 | int32_t a = 0; |
| 362 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 363 | TEST_ASSERT(a == 1); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 364 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 365 | auto rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 366 | "{si}"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 367 | TEST_ASSERT(0 <= rc); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 368 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 369 | rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 370 | "si"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 371 | TEST_ASSERT(0 <= rc); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 372 | |
| 373 | const char* s = nullptr; |
| 374 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 375 | TEST_ASSERT(0 == strcmp("asdf", s)); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 376 | sd_bus_message_read_basic(m, 'i', &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 377 | TEST_ASSERT(a == 3); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 378 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 379 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 380 | sd_bus_message_exit_container(m); |
| 381 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 382 | rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 383 | "si"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 384 | TEST_ASSERT(0 <= rc); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 385 | |
| 386 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 387 | TEST_ASSERT(0 == strcmp("jkl;", s)); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 388 | sd_bus_message_read_basic(m, 'i', &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 389 | TEST_ASSERT(a == 4); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 390 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 391 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 392 | sd_bus_message_exit_container(m); |
| 393 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 394 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 395 | sd_bus_message_exit_container(m); |
| 396 | |
| 397 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 398 | TEST_ASSERT(a == 2); |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 399 | } |
| 400 | }; |
| 401 | verifyCallback = &verify::op; |
| 402 | |
| 403 | b.call_noreply(m); |
| 404 | } |
| 405 | |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 406 | // Test unordered_map. |
| 407 | { |
| 408 | auto m = newMethodCall__test(b); |
| 409 | std::unordered_map<std::string, int> s = {{"asdf", 3}, {"jkl;", 4}}; |
| 410 | m.append(1, s, 2); |
| 411 | verifyTypeString = "ia{si}i"; |
| 412 | |
| 413 | struct verify |
| 414 | { |
| 415 | static void op(sd_bus_message* m) |
| 416 | { |
| 417 | int32_t a = 0; |
| 418 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 419 | TEST_ASSERT(a == 1); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 420 | |
| 421 | auto rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, |
| 422 | "{si}"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 423 | TEST_ASSERT(0 <= rc); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 424 | |
| 425 | rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, |
| 426 | "si"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 427 | TEST_ASSERT(0 <= rc); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 428 | |
| 429 | const char* s = nullptr; |
| 430 | sd_bus_message_read_basic(m, 's', &s); |
| 431 | sd_bus_message_read_basic(m, 'i', &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 432 | TEST_ASSERT((0 == strcmp("asdf", s) && a == 3) || |
| 433 | (a = 4 && 0 == strcmp("jkl;", s))); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 434 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 435 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 436 | sd_bus_message_exit_container(m); |
| 437 | |
| 438 | rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, |
| 439 | "si"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 440 | TEST_ASSERT(0 <= rc); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 441 | |
| 442 | sd_bus_message_read_basic(m, 's', &s); |
| 443 | sd_bus_message_read_basic(m, 'i', &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 444 | TEST_ASSERT((0 == strcmp("asdf", s) && a == 3) || |
| 445 | (a = 4 && 0 == strcmp("jkl;", s))); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 446 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 447 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 448 | sd_bus_message_exit_container(m); |
| 449 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 450 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 451 | sd_bus_message_exit_container(m); |
| 452 | |
| 453 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 454 | TEST_ASSERT(a == 2); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 455 | } |
| 456 | }; |
| 457 | verifyCallback = &verify::op; |
| 458 | |
| 459 | b.call_noreply(m); |
| 460 | } |
| 461 | |
| 462 | // Test set. |
| 463 | { |
| 464 | auto m = newMethodCall__test(b); |
| 465 | std::set<std::string> s = {{"asdf"}, {"jkl;"}}; |
| 466 | m.append(1, s, 2); |
| 467 | verifyTypeString = "iasi"; |
| 468 | |
| 469 | struct verify |
| 470 | { |
| 471 | static void op(sd_bus_message* m) |
| 472 | { |
| 473 | int32_t a = 0; |
| 474 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 475 | TEST_ASSERT(a == 1); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 476 | |
| 477 | auto rc = |
| 478 | sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 479 | TEST_ASSERT(0 <= rc); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 480 | |
| 481 | const char* s = nullptr; |
| 482 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 483 | TEST_ASSERT(0 == strcmp("asdf", s)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 484 | |
| 485 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 486 | TEST_ASSERT(0 == strcmp("jkl;", s)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 487 | |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 488 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 489 | sd_bus_message_exit_container(m); |
| 490 | |
| 491 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 492 | TEST_ASSERT(a == 2); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 493 | } |
| 494 | }; |
| 495 | verifyCallback = &verify::op; |
| 496 | |
| 497 | b.call_noreply(m); |
| 498 | } |
| 499 | |
| 500 | // Test array. |
| 501 | { |
| 502 | auto m = newMethodCall__test(b); |
| 503 | std::array<std::string, 3> s{"1", "2", "3"}; |
| 504 | m.append(1, s, 2); |
| 505 | verifyTypeString = "iasi"; |
| 506 | |
| 507 | struct verify |
| 508 | { |
| 509 | static void op(sd_bus_message* m) |
| 510 | { |
| 511 | int32_t a = 0; |
| 512 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 513 | TEST_ASSERT(a == 1); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 514 | |
| 515 | auto rc = |
| 516 | sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 517 | TEST_ASSERT(0 <= rc); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 518 | |
| 519 | const char* s = nullptr; |
| 520 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 521 | TEST_ASSERT(0 == strcmp("1", s)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 522 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 523 | TEST_ASSERT(0 == strcmp("2", s)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 524 | sd_bus_message_read_basic(m, 's', &s); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 525 | TEST_ASSERT(0 == strcmp("3", s)); |
| 526 | TEST_ASSERT(1 == sd_bus_message_at_end(m, false)); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 527 | |
| 528 | sd_bus_message_exit_container(m); |
| 529 | |
| 530 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 531 | TEST_ASSERT(a == 2); |
Ed Tanous | 28dc36d | 2018-02-21 12:22:54 -0800 | [diff] [blame] | 532 | } |
| 533 | }; |
| 534 | verifyCallback = &verify::op; |
| 535 | |
| 536 | b.call_noreply(m); |
| 537 | } |
| 538 | |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 539 | // Test tuple. |
| 540 | { |
| 541 | auto m = newMethodCall__test(b); |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 542 | std::tuple<int, double, std::string> a{3, 4.1, "asdf"}; |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 543 | m.append(1, a, 2); |
| 544 | verifyTypeString = "i(ids)i"; |
| 545 | |
| 546 | struct verify |
| 547 | { |
| 548 | static void op(sd_bus_message* m) |
| 549 | { |
| 550 | int32_t a = 0; |
| 551 | double b = 0; |
| 552 | const char* c = nullptr; |
| 553 | |
| 554 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 555 | TEST_ASSERT(a == 1); |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 556 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 557 | auto rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 558 | "ids"); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 559 | TEST_ASSERT(0 <= rc); |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 560 | |
| 561 | sd_bus_message_read(m, "ids", &a, &b, &c); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 562 | TEST_ASSERT(a == 3); |
| 563 | TEST_ASSERT(b == 4.1); |
| 564 | TEST_ASSERT(0 == strcmp(c, "asdf")); |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 565 | |
| 566 | sd_bus_message_exit_container(m); |
| 567 | |
| 568 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 569 | TEST_ASSERT(a == 2); |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 570 | } |
| 571 | }; |
| 572 | verifyCallback = &verify::op; |
| 573 | |
| 574 | b.call_noreply(m); |
| 575 | } |
| 576 | |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 577 | // Test variant. |
| 578 | { |
| 579 | auto m = newMethodCall__test(b); |
| 580 | sdbusplus::message::variant<int, double> a1{3.1}, a2{4}; |
| 581 | m.append(1, a1, a2, 2); |
| 582 | verifyTypeString = "ivvi"; |
| 583 | |
| 584 | struct verify |
| 585 | { |
| 586 | static void op(sd_bus_message* m) |
| 587 | { |
| 588 | int32_t a = 0; |
| 589 | double b = 0; |
| 590 | |
| 591 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 592 | TEST_ASSERT(a == 1); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 593 | |
| 594 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "d"); |
| 595 | sd_bus_message_read(m, "d", &b); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 596 | TEST_ASSERT(b == 3.1); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 597 | sd_bus_message_exit_container(m); |
| 598 | |
| 599 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "i"); |
| 600 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 601 | TEST_ASSERT(a == 4); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 602 | sd_bus_message_exit_container(m); |
| 603 | |
| 604 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 605 | TEST_ASSERT(a == 2); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 606 | } |
| 607 | }; |
| 608 | verifyCallback = &verify::op; |
| 609 | |
| 610 | b.call_noreply(m); |
| 611 | } |
| 612 | |
| 613 | // Test map-variant. |
| 614 | { |
| 615 | auto m = newMethodCall__test(b); |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 616 | std::map<std::string, sdbusplus::message::variant<int, double>> a1 = { |
| 617 | {"asdf", 3}, {"jkl;", 4.1}}; |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 618 | m.append(1, a1, 2); |
| 619 | verifyTypeString = "ia{sv}i"; |
| 620 | |
| 621 | struct verify |
| 622 | { |
| 623 | static void op(sd_bus_message* m) |
| 624 | { |
| 625 | int32_t a = 0; |
| 626 | double b = 0; |
| 627 | const char* c = nullptr; |
| 628 | |
| 629 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 630 | TEST_ASSERT(a == 1); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 631 | |
| 632 | sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); |
| 633 | sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv"); |
| 634 | sd_bus_message_read(m, "s", &c); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 635 | TEST_ASSERT(0 == strcmp("asdf", c)); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 636 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "i"); |
| 637 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 638 | TEST_ASSERT(a == 3); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 639 | sd_bus_message_exit_container(m); |
| 640 | sd_bus_message_exit_container(m); |
| 641 | sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv"); |
| 642 | sd_bus_message_read(m, "s", &c); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 643 | TEST_ASSERT(0 == strcmp("jkl;", c)); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 644 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "d"); |
| 645 | sd_bus_message_read(m, "d", &b); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 646 | TEST_ASSERT(b == 4.1); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 647 | sd_bus_message_exit_container(m); |
| 648 | sd_bus_message_exit_container(m); |
| 649 | sd_bus_message_exit_container(m); |
| 650 | |
| 651 | sd_bus_message_read(m, "i", &a); |
William A. Kennington III | 4869781 | 2018-06-19 18:35:38 -0700 | [diff] [blame^] | 652 | TEST_ASSERT(a == 2); |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 653 | } |
| 654 | }; |
| 655 | verifyCallback = &verify::op; |
| 656 | |
| 657 | b.call_noreply(m); |
| 658 | } |
| 659 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 660 | // Shutdown server. |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 661 | { |
| 662 | auto m = b.new_method_call(SERVICE, "/", INTERFACE, QUIT_METHOD); |
| 663 | b.call_noreply(m); |
| 664 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | int main() |
| 668 | { |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 669 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 670 | // Initialize and start server thread. |
| 671 | pthread_t t; |
| 672 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 673 | auto b = serverInit(); |
| 674 | pthread_create(&t, NULL, server, b.release()); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | runTests(); |
| 678 | |
| 679 | // Wait for server thread to exit. |
| 680 | pthread_join(t, NULL); |
| 681 | |
| 682 | return 0; |
| 683 | } |