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> |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 5 | |
| 6 | // Global to share the dbus type string between client and server. |
| 7 | static std::string verifyTypeString; |
| 8 | |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 9 | using verifyCallback_t = void(*)(sd_bus_message*); |
| 10 | verifyCallback_t verifyCallback = nullptr; |
| 11 | |
Patrick Williams | 24fb296 | 2016-11-04 17:08:59 -0500 | [diff] [blame] | 12 | static constexpr auto SERVICE = "sdbusplus.test.message.append"; |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 13 | static constexpr auto INTERFACE = SERVICE; |
| 14 | static constexpr auto TEST_METHOD = "test"; |
| 15 | static constexpr auto QUIT_METHOD = "quit"; |
| 16 | |
| 17 | // Open up the sdbus and claim SERVICE name. |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 18 | auto serverInit() |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 19 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 20 | auto b = sdbusplus::bus::new_default(); |
| 21 | b.request_name(SERVICE); |
| 22 | |
| 23 | return std::move(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | // Thread to run the dbus server. |
| 27 | void* server(void* b) |
| 28 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 29 | auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b)); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 30 | |
| 31 | while(1) |
| 32 | { |
| 33 | // Wait for messages. |
Patrick Williams | 13b97c5 | 2016-09-09 09:36:55 -0500 | [diff] [blame] | 34 | auto m = bus.process().release(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 35 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 36 | if(m == nullptr) |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 37 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 38 | bus.wait(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (sd_bus_message_is_method_call(m, INTERFACE, TEST_METHOD)) |
| 43 | { |
| 44 | // Verify the message type matches what the test expects. |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 45 | assert(verifyTypeString == sd_bus_message_get_signature(m, true)); |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 46 | if (verifyCallback) |
| 47 | { |
| 48 | verifyCallback(m); |
| 49 | verifyCallback = nullptr; |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | std::cout << "Warning: No verification for " |
| 54 | << verifyTypeString << std::endl; |
| 55 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 56 | // Reply to client. |
| 57 | sd_bus_reply_method_return(m, nullptr); |
| 58 | } |
| 59 | else if (sd_bus_message_is_method_call(m, INTERFACE, QUIT_METHOD)) |
| 60 | { |
| 61 | // Reply and exit. |
| 62 | sd_bus_reply_method_return(m, nullptr); |
| 63 | break; |
| 64 | } |
| 65 | } |
Patrick Williams | 696e315 | 2016-11-04 17:03:39 -0500 | [diff] [blame] | 66 | |
| 67 | return nullptr; |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 70 | auto newMethodCall__test(sdbusplus::bus::bus& b) |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 71 | { |
| 72 | // Allocate a method-call message for INTERFACE,TEST_METHOD. |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 73 | return b.new_method_call(SERVICE, "/", INTERFACE, TEST_METHOD); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void runTests() |
| 77 | { |
| 78 | using namespace std::literals; |
| 79 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 80 | auto b = sdbusplus::bus::new_default(); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 81 | |
| 82 | // Test r-value int. |
| 83 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 84 | auto m = newMethodCall__test(b); |
| 85 | m.append(1); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 86 | verifyTypeString = "i"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 87 | |
| 88 | struct verify |
| 89 | { |
| 90 | static void op(sd_bus_message* m) |
| 91 | { |
| 92 | int32_t i = 0; |
| 93 | sd_bus_message_read_basic(m, 'i', &i); |
| 94 | assert(i == 1); |
| 95 | } |
| 96 | }; |
| 97 | verifyCallback = &verify::op; |
| 98 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 99 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 100 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 101 | // Test l-value int. |
| 102 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 103 | auto m = newMethodCall__test(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 104 | int a = 1; |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 105 | m.append(a, a); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 106 | verifyTypeString = "ii"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 107 | |
| 108 | struct verify |
| 109 | { |
| 110 | static void op(sd_bus_message* m) |
| 111 | { |
| 112 | int32_t a = 0, b = 0; |
| 113 | sd_bus_message_read(m, "ii", &a, &b); |
| 114 | assert(a == 1); |
| 115 | assert(b == 1); |
| 116 | } |
| 117 | }; |
| 118 | verifyCallback = &verify::op; |
| 119 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 120 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // Test multiple ints. |
| 124 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 125 | auto m = newMethodCall__test(b); |
| 126 | m.append(1, 2, 3, 4, 5); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 127 | verifyTypeString = "iiiii"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 128 | |
| 129 | struct verify |
| 130 | { |
| 131 | static void op(sd_bus_message* m) |
| 132 | { |
| 133 | int32_t a = 0, b = 0, c = 0, d = 0, e = 0; |
| 134 | sd_bus_message_read(m, "iiiii", &a, &b, &c, &d, &e); |
| 135 | assert(a == 1); |
| 136 | assert(b == 2); |
| 137 | assert(c == 3); |
| 138 | assert(d == 4); |
| 139 | assert(e == 5); |
| 140 | } |
| 141 | }; |
| 142 | verifyCallback = &verify::op; |
| 143 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 144 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 147 | // Test double and bool. |
| 148 | { |
| 149 | auto m = newMethodCall__test(b); |
| 150 | bool t = true; |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 151 | bool f = false; |
| 152 | bool f2 = false; |
| 153 | m.append(t, true, f, std::move(f2), false, 1.1); |
| 154 | verifyTypeString = "bbbbbd"; |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 155 | |
| 156 | struct verify |
| 157 | { |
| 158 | static void op(sd_bus_message* m) |
| 159 | { |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 160 | bool t1, t2, f1, f2, f3; |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 161 | double d; |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 162 | sd_bus_message_read(m, "bbbbbd", &t1, &t2, &f1, &f2, &f3, &d); |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 163 | assert(t1); |
| 164 | assert(t2); |
| 165 | assert(!f1); |
Patrick Williams | b760a99 | 2016-11-28 11:26:55 -0600 | [diff] [blame] | 166 | assert(!f2); |
| 167 | assert(!f3); |
Patrick Williams | 9e3b51e | 2016-10-18 07:47:29 -0500 | [diff] [blame] | 168 | assert(d == 1.1); |
| 169 | } |
| 170 | }; |
| 171 | verifyCallback = &verify::op; |
| 172 | |
| 173 | b.call_noreply(m); |
| 174 | } |
| 175 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 176 | // Test r-value string. |
| 177 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 178 | auto m = newMethodCall__test(b); |
| 179 | m.append("asdf"s); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 180 | verifyTypeString = "s"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 181 | |
| 182 | struct verify |
| 183 | { |
| 184 | static void op(sd_bus_message* m) |
| 185 | { |
| 186 | const char* s = nullptr; |
| 187 | sd_bus_message_read_basic(m, 's', &s); |
| 188 | assert(0 == strcmp("asdf", s)); |
| 189 | } |
| 190 | }; |
| 191 | verifyCallback = &verify::op; |
| 192 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 193 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Test multiple strings, various forms. |
| 197 | { |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 198 | auto m = newMethodCall__test(b); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 199 | auto str = "jkl;"s; |
| 200 | auto str2 = "JKL:"s; |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 201 | m.append(1, "asdf", "ASDF"s, str, |
| 202 | std::move(str2), 5); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 203 | verifyTypeString = "issssi"; |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 204 | |
| 205 | struct verify |
| 206 | { |
| 207 | static void op(sd_bus_message* m) |
| 208 | { |
| 209 | int32_t a = 0, b = 0; |
| 210 | const char *s0 = nullptr, *s1 = nullptr, *s2 = nullptr, |
| 211 | *s3 = nullptr; |
| 212 | sd_bus_message_read(m, "issssi", &a, &s0, &s1, &s2, &s3, &b); |
| 213 | assert(a == 1); |
| 214 | assert(b == 5); |
| 215 | assert(0 == strcmp("asdf", s0)); |
| 216 | assert(0 == strcmp("ASDF", s1)); |
| 217 | assert(0 == strcmp("jkl;", s2)); |
| 218 | assert(0 == strcmp("JKL:", s3)); |
| 219 | } |
| 220 | }; |
| 221 | verifyCallback = &verify::op; |
| 222 | |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 223 | b.call_noreply(m); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Patrick Williams | 930460c | 2016-07-20 17:52:55 -0500 | [diff] [blame] | 226 | // Test vector. |
| 227 | { |
| 228 | auto m = newMethodCall__test(b); |
| 229 | std::vector<std::string> s{ "1", "2", "3"}; |
| 230 | m.append(1, s, 2); |
| 231 | verifyTypeString = "iasi"; |
| 232 | |
| 233 | struct verify |
| 234 | { |
| 235 | static void op(sd_bus_message* m) |
| 236 | { |
| 237 | int32_t a = 0; |
| 238 | sd_bus_message_read(m, "i", &a); |
| 239 | assert(a == 1); |
| 240 | |
| 241 | auto rc = sd_bus_message_enter_container(m, |
| 242 | SD_BUS_TYPE_ARRAY, |
| 243 | "s"); |
| 244 | assert(0 <= rc); |
| 245 | |
| 246 | const char* s = nullptr; |
| 247 | sd_bus_message_read_basic(m, 's', &s); |
| 248 | assert(0 == strcmp("1", s)); |
| 249 | sd_bus_message_read_basic(m, 's', &s); |
| 250 | assert(0 == strcmp("2", s)); |
| 251 | sd_bus_message_read_basic(m, 's', &s); |
| 252 | assert(0 == strcmp("3", s)); |
| 253 | assert(1 == sd_bus_message_at_end(m, false)); |
| 254 | |
| 255 | sd_bus_message_exit_container(m); |
| 256 | |
| 257 | sd_bus_message_read(m, "i", &a); |
| 258 | assert(a == 2); |
| 259 | |
| 260 | } |
| 261 | }; |
| 262 | verifyCallback = &verify::op; |
| 263 | |
| 264 | |
| 265 | b.call_noreply(m); |
| 266 | } |
| 267 | |
Patrick Williams | bbe0e43 | 2016-09-10 08:57:03 -0500 | [diff] [blame] | 268 | // Test map. |
| 269 | { |
| 270 | auto m = newMethodCall__test(b); |
| 271 | std::map<std::string, int> s = { { "asdf", 3 }, { "jkl;", 4 } }; |
| 272 | m.append(1, s, 2); |
| 273 | verifyTypeString = "ia{si}i"; |
| 274 | |
| 275 | struct verify |
| 276 | { |
| 277 | static void op(sd_bus_message* m) |
| 278 | { |
| 279 | int32_t a = 0; |
| 280 | sd_bus_message_read(m, "i", &a); |
| 281 | assert(a == 1); |
| 282 | |
| 283 | auto rc = sd_bus_message_enter_container(m, |
| 284 | SD_BUS_TYPE_ARRAY, |
| 285 | "{si}"); |
| 286 | assert(0 <= rc); |
| 287 | |
| 288 | rc = sd_bus_message_enter_container(m, |
| 289 | SD_BUS_TYPE_DICT_ENTRY, |
| 290 | "si"); |
| 291 | assert(0 <= rc); |
| 292 | |
| 293 | const char* s = nullptr; |
| 294 | sd_bus_message_read_basic(m, 's', &s); |
| 295 | assert(0 == strcmp("asdf", s)); |
| 296 | sd_bus_message_read_basic(m, 'i', &a); |
| 297 | assert(a == 3); |
| 298 | |
| 299 | assert(1 == sd_bus_message_at_end(m, false)); |
| 300 | sd_bus_message_exit_container(m); |
| 301 | |
| 302 | rc = sd_bus_message_enter_container(m, |
| 303 | SD_BUS_TYPE_DICT_ENTRY, |
| 304 | "si"); |
| 305 | assert(0 <= rc); |
| 306 | |
| 307 | sd_bus_message_read_basic(m, 's', &s); |
| 308 | assert(0 == strcmp("jkl;", s)); |
| 309 | sd_bus_message_read_basic(m, 'i', &a); |
| 310 | assert(a == 4); |
| 311 | |
| 312 | assert(1 == sd_bus_message_at_end(m, false)); |
| 313 | sd_bus_message_exit_container(m); |
| 314 | |
| 315 | assert(1 == sd_bus_message_at_end(m, false)); |
| 316 | sd_bus_message_exit_container(m); |
| 317 | |
| 318 | sd_bus_message_read(m, "i", &a); |
| 319 | assert(a == 2); |
| 320 | } |
| 321 | }; |
| 322 | verifyCallback = &verify::op; |
| 323 | |
| 324 | b.call_noreply(m); |
| 325 | } |
| 326 | |
Patrick Williams | aa2f48a | 2016-09-10 14:23:34 -0500 | [diff] [blame] | 327 | // Test tuple. |
| 328 | { |
| 329 | auto m = newMethodCall__test(b); |
| 330 | std::tuple<int, double, std::string> a{ 3, 4.1, "asdf" }; |
| 331 | m.append(1, a, 2); |
| 332 | verifyTypeString = "i(ids)i"; |
| 333 | |
| 334 | struct verify |
| 335 | { |
| 336 | static void op(sd_bus_message* m) |
| 337 | { |
| 338 | int32_t a = 0; |
| 339 | double b = 0; |
| 340 | const char* c = nullptr; |
| 341 | |
| 342 | sd_bus_message_read(m, "i", &a); |
| 343 | assert(a == 1); |
| 344 | |
| 345 | auto rc = sd_bus_message_enter_container(m, |
| 346 | SD_BUS_TYPE_STRUCT, |
| 347 | "ids"); |
| 348 | assert(0 <= rc); |
| 349 | |
| 350 | sd_bus_message_read(m, "ids", &a, &b, &c); |
| 351 | assert(a == 3); |
| 352 | assert(b == 4.1); |
| 353 | assert(0 == strcmp(c, "asdf")); |
| 354 | |
| 355 | sd_bus_message_exit_container(m); |
| 356 | |
| 357 | sd_bus_message_read(m, "i", &a); |
| 358 | assert(a == 2); |
| 359 | } |
| 360 | }; |
| 361 | verifyCallback = &verify::op; |
| 362 | |
| 363 | b.call_noreply(m); |
| 364 | } |
| 365 | |
Patrick Williams | 7559678 | 2016-09-11 21:14:10 -0500 | [diff] [blame] | 366 | // Test variant. |
| 367 | { |
| 368 | auto m = newMethodCall__test(b); |
| 369 | sdbusplus::message::variant<int, double> a1{3.1}, a2{4}; |
| 370 | m.append(1, a1, a2, 2); |
| 371 | verifyTypeString = "ivvi"; |
| 372 | |
| 373 | struct verify |
| 374 | { |
| 375 | static void op(sd_bus_message* m) |
| 376 | { |
| 377 | int32_t a = 0; |
| 378 | double b = 0; |
| 379 | |
| 380 | sd_bus_message_read(m, "i", &a); |
| 381 | assert(a == 1); |
| 382 | |
| 383 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "d"); |
| 384 | sd_bus_message_read(m, "d", &b); |
| 385 | assert(b == 3.1); |
| 386 | sd_bus_message_exit_container(m); |
| 387 | |
| 388 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "i"); |
| 389 | sd_bus_message_read(m, "i", &a); |
| 390 | assert(a == 4); |
| 391 | sd_bus_message_exit_container(m); |
| 392 | |
| 393 | sd_bus_message_read(m, "i", &a); |
| 394 | assert(a == 2); |
| 395 | } |
| 396 | }; |
| 397 | verifyCallback = &verify::op; |
| 398 | |
| 399 | b.call_noreply(m); |
| 400 | } |
| 401 | |
| 402 | // Test map-variant. |
| 403 | { |
| 404 | auto m = newMethodCall__test(b); |
| 405 | std::map<std::string, sdbusplus::message::variant<int, double>> a1 = |
| 406 | { { "asdf", 3 }, { "jkl;", 4.1 } }; |
| 407 | m.append(1, a1, 2); |
| 408 | verifyTypeString = "ia{sv}i"; |
| 409 | |
| 410 | struct verify |
| 411 | { |
| 412 | static void op(sd_bus_message* m) |
| 413 | { |
| 414 | int32_t a = 0; |
| 415 | double b = 0; |
| 416 | const char* c = nullptr; |
| 417 | |
| 418 | sd_bus_message_read(m, "i", &a); |
| 419 | assert(a == 1); |
| 420 | |
| 421 | sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); |
| 422 | sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv"); |
| 423 | sd_bus_message_read(m, "s", &c); |
| 424 | assert(0 == strcmp("asdf", c)); |
| 425 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "i"); |
| 426 | sd_bus_message_read(m, "i", &a); |
| 427 | assert(a == 3); |
| 428 | sd_bus_message_exit_container(m); |
| 429 | sd_bus_message_exit_container(m); |
| 430 | sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv"); |
| 431 | sd_bus_message_read(m, "s", &c); |
| 432 | assert(0 == strcmp("jkl;", c)); |
| 433 | sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, "d"); |
| 434 | sd_bus_message_read(m, "d", &b); |
| 435 | assert(b == 4.1); |
| 436 | sd_bus_message_exit_container(m); |
| 437 | sd_bus_message_exit_container(m); |
| 438 | sd_bus_message_exit_container(m); |
| 439 | |
| 440 | sd_bus_message_read(m, "i", &a); |
| 441 | assert(a == 2); |
| 442 | } |
| 443 | }; |
| 444 | verifyCallback = &verify::op; |
| 445 | |
| 446 | b.call_noreply(m); |
| 447 | } |
| 448 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 449 | // Shutdown server. |
Patrick Williams | 7802c07 | 2016-09-02 15:20:22 -0500 | [diff] [blame] | 450 | { |
| 451 | auto m = b.new_method_call(SERVICE, "/", INTERFACE, QUIT_METHOD); |
| 452 | b.call_noreply(m); |
| 453 | } |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | int main() |
| 457 | { |
Patrick Williams | 07e1d6f | 2016-09-08 15:54:09 -0500 | [diff] [blame] | 458 | |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 459 | // Initialize and start server thread. |
| 460 | pthread_t t; |
| 461 | { |
Patrick Williams | 5b48579 | 2016-08-02 07:35:14 -0500 | [diff] [blame] | 462 | auto b = serverInit(); |
| 463 | pthread_create(&t, NULL, server, b.release()); |
Patrick Williams | 1807fa4 | 2016-08-01 22:23:30 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | runTests(); |
| 467 | |
| 468 | // Wait for server thread to exit. |
| 469 | pthread_join(t, NULL); |
| 470 | |
| 471 | return 0; |
| 472 | } |