| 1 |
/* GLib testing framework examples and tests |
| 2 |
* |
| 3 |
* Copyright (C) 2008-2010 Red Hat, Inc. |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General |
| 18 |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 19 |
* |
| 20 |
* Author: David Zeuthen <[email protected]> |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <gio/gio.h> |
| 24 |
#include <unistd.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "gdbus-tests.h" |
| 28 |
|
| 29 |
/* all tests rely on a shared mainloop */ |
| 30 |
static GMainLoop *loop = NULL; |
| 31 |
|
| 32 |
static GDBusConnection *c = NULL; |
| 33 |
|
| 34 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 35 |
/* Test that we can export objects, the hierarchy is correct and the right handlers are invoked */ |
| 36 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 37 |
|
| 38 |
static const GDBusArgInfo foo_method1_in_args = |
| 39 |
{ |
| 40 |
-1, |
| 41 |
"an_input_string", |
| 42 |
"s", |
| 43 |
NULL |
| 44 |
}; |
| 45 |
static const GDBusArgInfo * const foo_method1_in_arg_pointers[] = {&foo_method1_in_args, NULL}; |
| 46 |
|
| 47 |
static const GDBusArgInfo foo_method1_out_args = |
| 48 |
{ |
| 49 |
-1, |
| 50 |
"an_output_string", |
| 51 |
"s", |
| 52 |
NULL |
| 53 |
}; |
| 54 |
static const GDBusArgInfo * const foo_method1_out_arg_pointers[] = {&foo_method1_out_args, NULL}; |
| 55 |
|
| 56 |
static const GDBusMethodInfo foo_method_info_method1 = |
| 57 |
{ |
| 58 |
-1, |
| 59 |
"Method1", |
| 60 |
(GDBusArgInfo **) &foo_method1_in_arg_pointers, |
| 61 |
(GDBusArgInfo **) &foo_method1_out_arg_pointers, |
| 62 |
NULL |
| 63 |
}; |
| 64 |
static const GDBusMethodInfo foo_method_info_method2 = |
| 65 |
{ |
| 66 |
-1, |
| 67 |
"Method2", |
| 68 |
NULL, |
| 69 |
NULL, |
| 70 |
NULL |
| 71 |
}; |
| 72 |
static const GDBusMethodInfo * const foo_method_info_pointers[] = {&foo_method_info_method1, &foo_method_info_method2, NULL}; |
| 73 |
|
| 74 |
static const GDBusSignalInfo foo_signal_info = |
| 75 |
{ |
| 76 |
-1, |
| 77 |
"SignalAlpha", |
| 78 |
NULL, |
| 79 |
NULL |
| 80 |
}; |
| 81 |
static const GDBusSignalInfo * const foo_signal_info_pointers[] = {&foo_signal_info, NULL}; |
| 82 |
|
| 83 |
static const GDBusPropertyInfo foo_property_info[] = |
| 84 |
{ |
| 85 |
{ |
| 86 |
-1, |
| 87 |
"PropertyUno", |
| 88 |
"s", |
| 89 |
G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, |
| 90 |
NULL |
| 91 |
}, |
| 92 |
{ |
| 93 |
-1, |
| 94 |
"NotWritable", |
| 95 |
"s", |
| 96 |
G_DBUS_PROPERTY_INFO_FLAGS_READABLE, |
| 97 |
NULL |
| 98 |
}, |
| 99 |
{ |
| 100 |
-1, |
| 101 |
"NotReadable", |
| 102 |
"s", |
| 103 |
G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, |
| 104 |
NULL |
| 105 |
} |
| 106 |
}; |
| 107 |
static const GDBusPropertyInfo * const foo_property_info_pointers[] = |
| 108 |
{ |
| 109 |
&foo_property_info[0], |
| 110 |
&foo_property_info[1], |
| 111 |
&foo_property_info[2], |
| 112 |
NULL |
| 113 |
}; |
| 114 |
|
| 115 |
static const GDBusInterfaceInfo foo_interface_info = |
| 116 |
{ |
| 117 |
-1, |
| 118 |
"org.example.Foo", |
| 119 |
(GDBusMethodInfo **) &foo_method_info_pointers, |
| 120 |
(GDBusSignalInfo **) &foo_signal_info_pointers, |
| 121 |
(GDBusPropertyInfo **)&foo_property_info_pointers, |
| 122 |
NULL, |
| 123 |
}; |
| 124 |
|
| 125 |
/* Foo2 is just Foo without the properties */ |
| 126 |
static const GDBusInterfaceInfo foo2_interface_info = |
| 127 |
{ |
| 128 |
-1, |
| 129 |
"org.example.Foo2", |
| 130 |
(GDBusMethodInfo **) &foo_method_info_pointers, |
| 131 |
(GDBusSignalInfo **) &foo_signal_info_pointers, |
| 132 |
NULL, |
| 133 |
NULL |
| 134 |
}; |
| 135 |
|
| 136 |
static void |
| 137 |
foo_method_call (GDBusConnection *connection, |
| 138 |
const gchar *sender, |
| 139 |
const gchar *object_path, |
| 140 |
const gchar *interface_name, |
| 141 |
const gchar *method_name, |
| 142 |
GVariant *parameters, |
| 143 |
GDBusMethodInvocation *invocation, |
| 144 |
gpointer user_data) |
| 145 |
{ |
| 146 |
if (g_strcmp0 (method_name, "Method1") == 0) |
| 147 |
{ |
| 148 |
const gchar *input; |
| 149 |
gchar *output; |
| 150 |
g_variant_get (parameters, "(&s)", &input); |
| 151 |
output = g_strdup_printf ("You passed the string '%s'. Jolly good!", input); |
| 152 |
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", output)); |
| 153 |
g_free (output); |
| 154 |
} |
| 155 |
else |
| 156 |
{ |
| 157 |
g_dbus_method_invocation_return_dbus_error (invocation, |
| 158 |
"org.example.SomeError", |
| 159 |
"How do you like them apples, buddy!"); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
static GVariant * |
| 164 |
foo_get_property (GDBusConnection *connection, |
| 165 |
const gchar *sender, |
| 166 |
const gchar *object_path, |
| 167 |
const gchar *interface_name, |
| 168 |
const gchar *property_name, |
| 169 |
GError **error, |
| 170 |
gpointer user_data) |
| 171 |
{ |
| 172 |
GVariant *ret; |
| 173 |
gchar *s; |
| 174 |
s = g_strdup_printf ("Property '%s' Is What It Is!", property_name); |
| 175 |
ret = g_variant_new_string (s); |
| 176 |
g_free (s); |
| 177 |
return ret; |
| 178 |
} |
| 179 |
|
| 180 |
static gboolean |
| 181 |
foo_set_property (GDBusConnection *connection, |
| 182 |
const gchar *sender, |
| 183 |
const gchar *object_path, |
| 184 |
const gchar *interface_name, |
| 185 |
const gchar *property_name, |
| 186 |
GVariant *value, |
| 187 |
GError **error, |
| 188 |
gpointer user_data) |
| 189 |
{ |
| 190 |
gchar *s; |
| 191 |
s = g_variant_print (value, TRUE); |
| 192 |
g_set_error (error, |
| 193 |
G_DBUS_ERROR, |
| 194 |
G_DBUS_ERROR_SPAWN_FILE_INVALID, |
| 195 |
"Returning some error instead of writing the value '%s' to the property '%s'", |
| 196 |
s, property_name); |
| 197 |
g_free (s); |
| 198 |
return FALSE; |
| 199 |
} |
| 200 |
|
| 201 |
static const GDBusInterfaceVTable foo_vtable = |
| 202 |
{ |
| 203 |
foo_method_call, |
| 204 |
foo_get_property, |
| 205 |
foo_set_property, |
| 206 |
{ 0 }, |
| 207 |
}; |
| 208 |
|
| 209 |
/* -------------------- */ |
| 210 |
|
| 211 |
static const GDBusMethodInfo bar_method_info[] = |
| 212 |
{ |
| 213 |
{ |
| 214 |
-1, |
| 215 |
"MethodA", |
| 216 |
NULL, |
| 217 |
NULL, |
| 218 |
NULL |
| 219 |
}, |
| 220 |
{ |
| 221 |
-1, |
| 222 |
"MethodB", |
| 223 |
NULL, |
| 224 |
NULL, |
| 225 |
NULL |
| 226 |
} |
| 227 |
}; |
| 228 |
static const GDBusMethodInfo * const bar_method_info_pointers[] = {&bar_method_info[0], &bar_method_info[1], NULL}; |
| 229 |
|
| 230 |
static const GDBusSignalInfo bar_signal_info[] = |
| 231 |
{ |
| 232 |
{ |
| 233 |
-1, |
| 234 |
"SignalMars", |
| 235 |
NULL, |
| 236 |
NULL |
| 237 |
} |
| 238 |
}; |
| 239 |
static const GDBusSignalInfo * const bar_signal_info_pointers[] = {&bar_signal_info[0], NULL}; |
| 240 |
|
| 241 |
static const GDBusPropertyInfo bar_property_info[] = |
| 242 |
{ |
| 243 |
{ |
| 244 |
-1, |
| 245 |
"PropertyDuo", |
| 246 |
"s", |
| 247 |
G_DBUS_PROPERTY_INFO_FLAGS_READABLE, |
| 248 |
NULL |
| 249 |
} |
| 250 |
}; |
| 251 |
static const GDBusPropertyInfo * const bar_property_info_pointers[] = {&bar_property_info[0], NULL}; |
| 252 |
|
| 253 |
static const GDBusInterfaceInfo bar_interface_info = |
| 254 |
{ |
| 255 |
-1, |
| 256 |
"org.example.Bar", |
| 257 |
(GDBusMethodInfo **) bar_method_info_pointers, |
| 258 |
(GDBusSignalInfo **) bar_signal_info_pointers, |
| 259 |
(GDBusPropertyInfo **) bar_property_info_pointers, |
| 260 |
NULL, |
| 261 |
}; |
| 262 |
|
| 263 |
/* -------------------- */ |
| 264 |
|
| 265 |
static const GDBusMethodInfo dyna_method_info[] = |
| 266 |
{ |
| 267 |
{ |
| 268 |
-1, |
| 269 |
"DynaCyber", |
| 270 |
NULL, |
| 271 |
NULL, |
| 272 |
NULL |
| 273 |
} |
| 274 |
}; |
| 275 |
static const GDBusMethodInfo * const dyna_method_info_pointers[] = {&dyna_method_info[0], NULL}; |
| 276 |
|
| 277 |
static const GDBusInterfaceInfo dyna_interface_info = |
| 278 |
{ |
| 279 |
-1, |
| 280 |
"org.example.Dyna", |
| 281 |
(GDBusMethodInfo **) dyna_method_info_pointers, |
| 282 |
NULL, /* no signals */ |
| 283 |
NULL, /* no properties */ |
| 284 |
NULL, |
| 285 |
}; |
| 286 |
|
| 287 |
static void |
| 288 |
dyna_cyber (GDBusConnection *connection, |
| 289 |
const gchar *sender, |
| 290 |
const gchar *object_path, |
| 291 |
const gchar *interface_name, |
| 292 |
const gchar *method_name, |
| 293 |
GVariant *parameters, |
| 294 |
GDBusMethodInvocation *invocation, |
| 295 |
gpointer user_data) |
| 296 |
{ |
| 297 |
GPtrArray *data = user_data; |
| 298 |
gchar *node_name; |
| 299 |
guint n; |
| 300 |
|
| 301 |
node_name = strrchr (object_path, '/') + 1; |
| 302 |
|
| 303 |
/* Add new node if it is not already known */ |
| 304 |
for (n = 0; n < data->len ; n++) |
| 305 |
{ |
| 306 |
if (g_strcmp0 (g_ptr_array_index (data, n), node_name) == 0) |
| 307 |
goto out; |
| 308 |
} |
| 309 |
g_ptr_array_add (data, g_strdup(node_name)); |
| 310 |
|
| 311 |
out: |
| 312 |
g_dbus_method_invocation_return_value (invocation, NULL); |
| 313 |
} |
| 314 |
|
| 315 |
static const GDBusInterfaceVTable dyna_interface_vtable = |
| 316 |
{ |
| 317 |
dyna_cyber, |
| 318 |
NULL, |
| 319 |
NULL, |
| 320 |
{ 0 } |
| 321 |
}; |
| 322 |
|
| 323 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 324 |
|
| 325 |
static void |
| 326 |
introspect_callback (GDBusProxy *proxy, |
| 327 |
GAsyncResult *res, |
| 328 |
gpointer user_data) |
| 329 |
{ |
| 330 |
gchar **xml_data = user_data; |
| 331 |
GVariant *result; |
| 332 |
GError *error; |
| 333 |
|
| 334 |
error = NULL; |
| 335 |
result = g_dbus_proxy_call_finish (proxy, |
| 336 |
res, |
| 337 |
&error); |
| 338 |
g_assert_no_error (error); |
| 339 |
g_assert (result != NULL); |
| 340 |
g_variant_get (result, "(s)", xml_data); |
| 341 |
g_variant_unref (result); |
| 342 |
|
| 343 |
g_main_loop_quit (loop); |
| 344 |
} |
| 345 |
|
| 346 |
static gint |
| 347 |
compare_strings (gconstpointer a, |
| 348 |
gconstpointer b) |
| 349 |
{ |
| 350 |
const gchar *sa = a; |
| 351 |
const gchar *sb = b; |
| 352 |
|
| 353 |
/* Array terminator must sort last */ |
| 354 |
if (sa == NULL) |
| 355 |
return 1; |
| 356 |
if (sb == NULL) |
| 357 |
return -1; |
| 358 |
|
| 359 |
return strcmp (sa, sb); |
| 360 |
} |
| 361 |
|
| 362 |
static gchar ** |
| 363 |
get_nodes_at (GDBusConnection *c, |
| 364 |
const gchar *object_path) |
| 365 |
{ |
| 366 |
GError *error; |
| 367 |
GDBusProxy *proxy; |
| 368 |
gchar *xml_data; |
| 369 |
GPtrArray *p; |
| 370 |
GDBusNodeInfo *node_info; |
| 371 |
guint n; |
| 372 |
|
| 373 |
error = NULL; |
| 374 |
proxy = g_dbus_proxy_new_sync (c, |
| 375 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | |
| 376 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, |
| 377 |
NULL, |
| 378 |
g_dbus_connection_get_unique_name (c), |
| 379 |
object_path, |
| 380 |
"org.freedesktop.DBus.Introspectable", |
| 381 |
NULL, |
| 382 |
&error); |
| 383 |
g_assert_no_error (error); |
| 384 |
g_assert (proxy != NULL); |
| 385 |
|
| 386 |
/* do this async to avoid libdbus-1 deadlocks */ |
| 387 |
xml_data = NULL; |
| 388 |
g_dbus_proxy_call (proxy, |
| 389 |
"Introspect", |
| 390 |
NULL, |
| 391 |
G_DBUS_CALL_FLAGS_NONE, |
| 392 |
-1, |
| 393 |
NULL, |
| 394 |
(GAsyncReadyCallback) introspect_callback, |
| 395 |
&xml_data); |
| 396 |
g_main_loop_run (loop); |
| 397 |
g_assert (xml_data != NULL); |
| 398 |
|
| 399 |
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); |
| 400 |
g_assert_no_error (error); |
| 401 |
g_assert (node_info != NULL); |
| 402 |
|
| 403 |
p = g_ptr_array_new (); |
| 404 |
for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++) |
| 405 |
{ |
| 406 |
const GDBusNodeInfo *sub_node_info = node_info->nodes[n]; |
| 407 |
g_ptr_array_add (p, g_strdup (sub_node_info->path)); |
| 408 |
} |
| 409 |
g_ptr_array_add (p, NULL); |
| 410 |
|
| 411 |
g_object_unref (proxy); |
| 412 |
g_free (xml_data); |
| 413 |
g_dbus_node_info_unref (node_info); |
| 414 |
|
| 415 |
/* Nodes are semantically unordered; sort array so tests can rely on order */ |
| 416 |
g_ptr_array_sort_values (p, compare_strings); |
| 417 |
|
| 418 |
return (gchar **) g_ptr_array_free (p, FALSE); |
| 419 |
} |
| 420 |
|
| 421 |
static gboolean |
| 422 |
has_interface (GDBusConnection *c, |
| 423 |
const gchar *object_path, |
| 424 |
const gchar *interface_name) |
| 425 |
{ |
| 426 |
GError *error; |
| 427 |
GDBusProxy *proxy; |
| 428 |
gchar *xml_data; |
| 429 |
GDBusNodeInfo *node_info; |
| 430 |
gboolean ret; |
| 431 |
|
| 432 |
error = NULL; |
| 433 |
proxy = g_dbus_proxy_new_sync (c, |
| 434 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | |
| 435 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, |
| 436 |
NULL, |
| 437 |
g_dbus_connection_get_unique_name (c), |
| 438 |
object_path, |
| 439 |
"org.freedesktop.DBus.Introspectable", |
| 440 |
NULL, |
| 441 |
&error); |
| 442 |
g_assert_no_error (error); |
| 443 |
g_assert (proxy != NULL); |
| 444 |
|
| 445 |
/* do this async to avoid libdbus-1 deadlocks */ |
| 446 |
xml_data = NULL; |
| 447 |
g_dbus_proxy_call (proxy, |
| 448 |
"Introspect", |
| 449 |
NULL, |
| 450 |
G_DBUS_CALL_FLAGS_NONE, |
| 451 |
-1, |
| 452 |
NULL, |
| 453 |
(GAsyncReadyCallback) introspect_callback, |
| 454 |
&xml_data); |
| 455 |
g_main_loop_run (loop); |
| 456 |
g_assert (xml_data != NULL); |
| 457 |
|
| 458 |
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); |
| 459 |
g_assert_no_error (error); |
| 460 |
g_assert (node_info != NULL); |
| 461 |
|
| 462 |
ret = (g_dbus_node_info_lookup_interface (node_info, interface_name) != NULL); |
| 463 |
|
| 464 |
g_object_unref (proxy); |
| 465 |
g_free (xml_data); |
| 466 |
g_dbus_node_info_unref (node_info); |
| 467 |
|
| 468 |
return ret; |
| 469 |
} |
| 470 |
|
| 471 |
static guint |
| 472 |
count_interfaces (GDBusConnection *c, |
| 473 |
const gchar *object_path) |
| 474 |
{ |
| 475 |
GError *error; |
| 476 |
GDBusProxy *proxy; |
| 477 |
gchar *xml_data; |
| 478 |
GDBusNodeInfo *node_info; |
| 479 |
guint ret; |
| 480 |
|
| 481 |
error = NULL; |
| 482 |
proxy = g_dbus_proxy_new_sync (c, |
| 483 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | |
| 484 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, |
| 485 |
NULL, |
| 486 |
g_dbus_connection_get_unique_name (c), |
| 487 |
object_path, |
| 488 |
"org.freedesktop.DBus.Introspectable", |
| 489 |
NULL, |
| 490 |
&error); |
| 491 |
g_assert_no_error (error); |
| 492 |
g_assert (proxy != NULL); |
| 493 |
|
| 494 |
/* do this async to avoid libdbus-1 deadlocks */ |
| 495 |
xml_data = NULL; |
| 496 |
g_dbus_proxy_call (proxy, |
| 497 |
"Introspect", |
| 498 |
NULL, |
| 499 |
G_DBUS_CALL_FLAGS_NONE, |
| 500 |
-1, |
| 501 |
NULL, |
| 502 |
(GAsyncReadyCallback) introspect_callback, |
| 503 |
&xml_data); |
| 504 |
g_main_loop_run (loop); |
| 505 |
g_assert (xml_data != NULL); |
| 506 |
|
| 507 |
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); |
| 508 |
g_assert_no_error (error); |
| 509 |
g_assert (node_info != NULL); |
| 510 |
|
| 511 |
ret = 0; |
| 512 |
while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL) |
| 513 |
ret++; |
| 514 |
|
| 515 |
g_object_unref (proxy); |
| 516 |
g_free (xml_data); |
| 517 |
g_dbus_node_info_unref (node_info); |
| 518 |
|
| 519 |
return ret; |
| 520 |
} |
| 521 |
|
| 522 |
static void |
| 523 |
dyna_create_callback (GDBusProxy *proxy, |
| 524 |
GAsyncResult *res, |
| 525 |
gpointer user_data) |
| 526 |
{ |
| 527 |
GVariant *result; |
| 528 |
GError *error; |
| 529 |
|
| 530 |
error = NULL; |
| 531 |
result = g_dbus_proxy_call_finish (proxy, |
| 532 |
res, |
| 533 |
&error); |
| 534 |
g_assert_no_error (error); |
| 535 |
g_assert (result != NULL); |
| 536 |
g_variant_unref (result); |
| 537 |
|
| 538 |
g_main_loop_quit (loop); |
| 539 |
} |
| 540 |
|
| 541 |
/* Dynamically create @object_name under /foo/dyna */ |
| 542 |
static void |
| 543 |
dyna_create (GDBusConnection *c, |
| 544 |
const gchar *object_name) |
| 545 |
{ |
| 546 |
GError *error; |
| 547 |
GDBusProxy *proxy; |
| 548 |
gchar *object_path; |
| 549 |
|
| 550 |
object_path = g_strconcat ("/foo/dyna/", object_name, NULL); |
| 551 |
|
| 552 |
error = NULL; |
| 553 |
proxy = g_dbus_proxy_new_sync (c, |
| 554 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | |
| 555 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, |
| 556 |
NULL, |
| 557 |
g_dbus_connection_get_unique_name (c), |
| 558 |
object_path, |
| 559 |
"org.example.Dyna", |
| 560 |
NULL, |
| 561 |
&error); |
| 562 |
g_assert_no_error (error); |
| 563 |
g_assert (proxy != NULL); |
| 564 |
|
| 565 |
/* do this async to avoid libdbus-1 deadlocks */ |
| 566 |
g_dbus_proxy_call (proxy, |
| 567 |
"DynaCyber", |
| 568 |
g_variant_new ("()"), |
| 569 |
G_DBUS_CALL_FLAGS_NONE, |
| 570 |
-1, |
| 571 |
NULL, |
| 572 |
(GAsyncReadyCallback) dyna_create_callback, |
| 573 |
NULL); |
| 574 |
g_main_loop_run (loop); |
| 575 |
|
| 576 |
g_assert_no_error (error); |
| 577 |
|
| 578 |
g_object_unref (proxy); |
| 579 |
g_free (object_path); |
| 580 |
|
| 581 |
return; |
| 582 |
} |
| 583 |
|
| 584 |
typedef struct |
| 585 |
{ |
| 586 |
guint num_unregistered_calls; |
| 587 |
guint num_unregistered_subtree_calls; |
| 588 |
guint num_subtree_nodes; |
| 589 |
} ObjectRegistrationData; |
| 590 |
|
| 591 |
static void |
| 592 |
on_object_unregistered (gpointer user_data) |
| 593 |
{ |
| 594 |
ObjectRegistrationData *data = user_data; |
| 595 |
|
| 596 |
data->num_unregistered_calls++; |
| 597 |
} |
| 598 |
|
| 599 |
static void |
| 600 |
on_subtree_unregistered (gpointer user_data) |
| 601 |
{ |
| 602 |
ObjectRegistrationData *data = user_data; |
| 603 |
|
| 604 |
data->num_unregistered_subtree_calls++; |
| 605 |
} |
| 606 |
|
| 607 |
/* -------------------- */ |
| 608 |
|
| 609 |
static gchar ** |
| 610 |
subtree_enumerate (GDBusConnection *connection, |
| 611 |
const gchar *sender, |
| 612 |
const gchar *object_path, |
| 613 |
gpointer user_data) |
| 614 |
{ |
| 615 |
ObjectRegistrationData *data = user_data; |
| 616 |
GPtrArray *p; |
| 617 |
gchar **nodes; |
| 618 |
guint n; |
| 619 |
|
| 620 |
p = g_ptr_array_new (); |
| 621 |
|
| 622 |
for (n = 0; n < data->num_subtree_nodes; n++) |
| 623 |
{ |
| 624 |
g_ptr_array_add (p, g_strdup_printf ("vp%d", n)); |
| 625 |
g_ptr_array_add (p, g_strdup_printf ("evp%d", n)); |
| 626 |
} |
| 627 |
g_ptr_array_add (p, NULL); |
| 628 |
|
| 629 |
nodes = (gchar **) g_ptr_array_free (p, FALSE); |
| 630 |
|
| 631 |
return nodes; |
| 632 |
} |
| 633 |
|
| 634 |
/* Only allows certain objects, and aborts on unknowns */ |
| 635 |
static GDBusInterfaceInfo ** |
| 636 |
subtree_introspect (GDBusConnection *connection, |
| 637 |
const gchar *sender, |
| 638 |
const gchar *object_path, |
| 639 |
const gchar *node, |
| 640 |
gpointer user_data) |
| 641 |
{ |
| 642 |
const GDBusInterfaceInfo *interfaces[2] = { |
| 643 |
NULL /* filled in below */, NULL |
| 644 |
}; |
| 645 |
|
| 646 |
/* VPs implement the Foo interface, EVPs implement the Bar interface. The root |
| 647 |
* does not implement any interfaces |
| 648 |
*/ |
| 649 |
if (node == NULL) |
| 650 |
{ |
| 651 |
return NULL; |
| 652 |
} |
| 653 |
else if (g_str_has_prefix (node, "vp")) |
| 654 |
{ |
| 655 |
interfaces[0] = &foo_interface_info; |
| 656 |
} |
| 657 |
else if (g_str_has_prefix (node, "evp")) |
| 658 |
{ |
| 659 |
interfaces[0] = &bar_interface_info; |
| 660 |
} |
| 661 |
else |
| 662 |
{ |
| 663 |
g_assert_not_reached (); |
| 664 |
} |
| 665 |
|
| 666 |
return g_memdup2 (interfaces, 2 * sizeof (void *)); |
| 667 |
} |
| 668 |
|
| 669 |
static const GDBusInterfaceVTable * |
| 670 |
subtree_dispatch (GDBusConnection *connection, |
| 671 |
const gchar *sender, |
| 672 |
const gchar *object_path, |
| 673 |
const gchar *interface_name, |
| 674 |
const gchar *node, |
| 675 |
gpointer *out_user_data, |
| 676 |
gpointer user_data) |
| 677 |
{ |
| 678 |
if (g_strcmp0 (interface_name, "org.example.Foo") == 0) |
| 679 |
return &foo_vtable; |
| 680 |
else |
| 681 |
return NULL; |
| 682 |
} |
| 683 |
|
| 684 |
static const GDBusSubtreeVTable subtree_vtable = |
| 685 |
{ |
| 686 |
subtree_enumerate, |
| 687 |
subtree_introspect, |
| 688 |
subtree_dispatch, |
| 689 |
{ 0 } |
| 690 |
}; |
| 691 |
|
| 692 |
/* -------------------- */ |
| 693 |
|
| 694 |
static gchar ** |
| 695 |
dynamic_subtree_enumerate (GDBusConnection *connection, |
| 696 |
const gchar *sender, |
| 697 |
const gchar *object_path, |
| 698 |
gpointer user_data) |
| 699 |
{ |
| 700 |
GPtrArray *data = user_data; |
| 701 |
gchar **nodes = g_new (gchar*, data->len + 1); |
| 702 |
guint n; |
| 703 |
|
| 704 |
for (n = 0; n < data->len; n++) |
| 705 |
{ |
| 706 |
nodes[n] = g_strdup (g_ptr_array_index (data, n)); |
| 707 |
} |
| 708 |
nodes[data->len] = NULL; |
| 709 |
|
| 710 |
return nodes; |
| 711 |
} |
| 712 |
|
| 713 |
/* Allow all objects to be introspected */ |
| 714 |
static GDBusInterfaceInfo ** |
| 715 |
dynamic_subtree_introspect (GDBusConnection *connection, |
| 716 |
const gchar *sender, |
| 717 |
const gchar *object_path, |
| 718 |
const gchar *node, |
| 719 |
gpointer user_data) |
| 720 |
{ |
| 721 |
const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL }; |
| 722 |
|
| 723 |
return g_memdup2 (interfaces, 2 * sizeof (void *)); |
| 724 |
} |
| 725 |
|
| 726 |
static const GDBusInterfaceVTable * |
| 727 |
dynamic_subtree_dispatch (GDBusConnection *connection, |
| 728 |
const gchar *sender, |
| 729 |
const gchar *object_path, |
| 730 |
const gchar *interface_name, |
| 731 |
const gchar *node, |
| 732 |
gpointer *out_user_data, |
| 733 |
gpointer user_data) |
| 734 |
{ |
| 735 |
*out_user_data = user_data; |
| 736 |
return &dyna_interface_vtable; |
| 737 |
} |
| 738 |
|
| 739 |
static const GDBusSubtreeVTable dynamic_subtree_vtable = |
| 740 |
{ |
| 741 |
dynamic_subtree_enumerate, |
| 742 |
dynamic_subtree_introspect, |
| 743 |
dynamic_subtree_dispatch, |
| 744 |
{ 0 } |
| 745 |
}; |
| 746 |
|
| 747 |
/* -------------------- */ |
| 748 |
|
| 749 |
typedef struct |
| 750 |
{ |
| 751 |
const gchar *object_path; |
| 752 |
gboolean check_remote_errors; |
| 753 |
} TestDispatchThreadFuncArgs; |
| 754 |
|
| 755 |
static gpointer |
| 756 |
test_dispatch_thread_func (gpointer user_data) |
| 757 |
{ |
| 758 |
TestDispatchThreadFuncArgs *args = user_data; |
| 759 |
const gchar *object_path = args->object_path; |
| 760 |
GDBusProxy *foo_proxy; |
| 761 |
GVariant *value; |
| 762 |
GVariant *inner; |
| 763 |
GError *error; |
| 764 |
gchar *s; |
| 765 |
const gchar *value_str; |
| 766 |
|
| 767 |
foo_proxy = g_dbus_proxy_new_sync (c, |
| 768 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | |
| 769 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, |
| 770 |
NULL, |
| 771 |
g_dbus_connection_get_unique_name (c), |
| 772 |
object_path, |
| 773 |
"org.example.Foo", |
| 774 |
NULL, |
| 775 |
&error); |
| 776 |
g_assert (foo_proxy != NULL); |
| 777 |
|
| 778 |
/* generic interfaces */ |
| 779 |
error = NULL; |
| 780 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 781 |
"org.freedesktop.DBus.Peer.Ping", |
| 782 |
NULL, |
| 783 |
G_DBUS_CALL_FLAGS_NONE, |
| 784 |
-1, |
| 785 |
NULL, |
| 786 |
&error); |
| 787 |
g_assert_no_error (error); |
| 788 |
g_assert (value != NULL); |
| 789 |
g_variant_unref (value); |
| 790 |
|
| 791 |
/* user methods */ |
| 792 |
error = NULL; |
| 793 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 794 |
"Method1", |
| 795 |
g_variant_new ("(s)", "winwinwin"), |
| 796 |
G_DBUS_CALL_FLAGS_NONE, |
| 797 |
-1, |
| 798 |
NULL, |
| 799 |
&error); |
| 800 |
g_assert_no_error (error); |
| 801 |
g_assert (value != NULL); |
| 802 |
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)"))); |
| 803 |
g_variant_get (value, "(&s)", &value_str); |
| 804 |
g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!"); |
| 805 |
g_variant_unref (value); |
| 806 |
|
| 807 |
error = NULL; |
| 808 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 809 |
"Method2", |
| 810 |
NULL, |
| 811 |
G_DBUS_CALL_FLAGS_NONE, |
| 812 |
-1, |
| 813 |
NULL, |
| 814 |
&error); |
| 815 |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR); |
| 816 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.example.SomeError: How do you like them apples, buddy!"); |
| 817 |
g_error_free (error); |
| 818 |
g_assert (value == NULL); |
| 819 |
|
| 820 |
error = NULL; |
| 821 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 822 |
"Method2", |
| 823 |
g_variant_new ("(s)", "failfailfail"), |
| 824 |
G_DBUS_CALL_FLAGS_NONE, |
| 825 |
-1, |
| 826 |
NULL, |
| 827 |
&error); |
| 828 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); |
| 829 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Type of message, “(s)”, does not match expected type “()”"); |
| 830 |
g_error_free (error); |
| 831 |
g_assert (value == NULL); |
| 832 |
|
| 833 |
error = NULL; |
| 834 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 835 |
"NonExistantMethod", |
| 836 |
NULL, |
| 837 |
G_DBUS_CALL_FLAGS_NONE, |
| 838 |
-1, |
| 839 |
NULL, |
| 840 |
&error); |
| 841 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD); |
| 842 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method “NonExistantMethod”"); |
| 843 |
g_error_free (error); |
| 844 |
g_assert (value == NULL); |
| 845 |
|
| 846 |
error = NULL; |
| 847 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 848 |
"org.example.FooXYZ.NonExistant", |
| 849 |
NULL, |
| 850 |
G_DBUS_CALL_FLAGS_NONE, |
| 851 |
-1, |
| 852 |
NULL, |
| 853 |
&error); |
| 854 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD); |
| 855 |
g_error_free (error); |
| 856 |
g_assert (value == NULL); |
| 857 |
|
| 858 |
/* user properties */ |
| 859 |
error = NULL; |
| 860 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 861 |
"org.freedesktop.DBus.Properties.Get", |
| 862 |
g_variant_new ("(ss)", |
| 863 |
"org.example.Foo", |
| 864 |
"PropertyUno"), |
| 865 |
G_DBUS_CALL_FLAGS_NONE, |
| 866 |
-1, |
| 867 |
NULL, |
| 868 |
&error); |
| 869 |
g_assert_no_error (error); |
| 870 |
g_assert (value != NULL); |
| 871 |
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)"))); |
| 872 |
g_variant_get (value, "(v)", &inner); |
| 873 |
g_assert (g_variant_is_of_type (inner, G_VARIANT_TYPE_STRING)); |
| 874 |
g_assert_cmpstr (g_variant_get_string (inner, NULL), ==, "Property 'PropertyUno' Is What It Is!"); |
| 875 |
g_variant_unref (value); |
| 876 |
g_variant_unref (inner); |
| 877 |
|
| 878 |
error = NULL; |
| 879 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 880 |
"org.freedesktop.DBus.Properties.Get", |
| 881 |
g_variant_new ("(ss)", |
| 882 |
"org.example.Foo", |
| 883 |
"ThisDoesntExist"), |
| 884 |
G_DBUS_CALL_FLAGS_NONE, |
| 885 |
-1, |
| 886 |
NULL, |
| 887 |
&error); |
| 888 |
g_assert (value == NULL); |
| 889 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); |
| 890 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such property “ThisDoesntExist”"); |
| 891 |
g_error_free (error); |
| 892 |
|
| 893 |
error = NULL; |
| 894 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 895 |
"org.freedesktop.DBus.Properties.Get", |
| 896 |
g_variant_new ("(ss)", |
| 897 |
"org.example.Foo", |
| 898 |
"NotReadable"), |
| 899 |
G_DBUS_CALL_FLAGS_NONE, |
| 900 |
-1, |
| 901 |
NULL, |
| 902 |
&error); |
| 903 |
g_assert (value == NULL); |
| 904 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); |
| 905 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotReadable” is not readable"); |
| 906 |
g_error_free (error); |
| 907 |
|
| 908 |
error = NULL; |
| 909 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 910 |
"org.freedesktop.DBus.Properties.Set", |
| 911 |
g_variant_new ("(ssv)", |
| 912 |
"org.example.Foo", |
| 913 |
"NotReadable", |
| 914 |
g_variant_new_string ("But Writable you are!")), |
| 915 |
G_DBUS_CALL_FLAGS_NONE, |
| 916 |
-1, |
| 917 |
NULL, |
| 918 |
&error); |
| 919 |
g_assert (value == NULL); |
| 920 |
if (args->check_remote_errors) |
| 921 |
{ |
| 922 |
/* _with_closures variant doesn't support customizing error data. */ |
| 923 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FILE_INVALID); |
| 924 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.Spawn.FileInvalid: Returning some error instead of writing the value ''But Writable you are!'' to the property 'NotReadable'"); |
| 925 |
} |
| 926 |
g_assert (error != NULL && error->domain == G_DBUS_ERROR); |
| 927 |
g_error_free (error); |
| 928 |
|
| 929 |
error = NULL; |
| 930 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 931 |
"org.freedesktop.DBus.Properties.Set", |
| 932 |
g_variant_new ("(ssv)", |
| 933 |
"org.example.Foo", |
| 934 |
"NotWritable", |
| 935 |
g_variant_new_uint32 (42)), |
| 936 |
G_DBUS_CALL_FLAGS_NONE, |
| 937 |
-1, |
| 938 |
NULL, |
| 939 |
&error); |
| 940 |
g_assert (value == NULL); |
| 941 |
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); |
| 942 |
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property “NotWritable” is not writable"); |
| 943 |
g_error_free (error); |
| 944 |
|
| 945 |
error = NULL; |
| 946 |
value = g_dbus_proxy_call_sync (foo_proxy, |
| 947 |
"org.freedesktop.DBus.Properties.GetAll", |
| 948 |
g_variant_new ("(s)", |
| 949 |
"org.example.Foo"), |
| 950 |
G_DBUS_CALL_FLAGS_NONE, |
| 951 |
-1, |
| 952 |
NULL, |
| 953 |
&error); |
| 954 |
g_assert_no_error (error); |
| 955 |
g_assert (value != NULL); |
| 956 |
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(a{sv})"))); |
| 957 |
s = g_variant_print (value, TRUE); |
| 958 |
g_assert_cmpstr (s, ==, "({'PropertyUno': <\"Property 'PropertyUno' Is What It Is!\">, 'NotWritable': <\"Property 'NotWritable' Is What It Is!\">},)"); |
| 959 |
g_free (s); |
| 960 |
g_variant_unref (value); |
| 961 |
|
| 962 |
g_object_unref (foo_proxy); |
| 963 |
|
| 964 |
g_main_loop_quit (loop); |
| 965 |
return NULL; |
| 966 |
} |
| 967 |
|
| 968 |
static void |
| 969 |
test_dispatch (const gchar *object_path, |
| 970 |
gboolean check_remote_errors) |
| 971 |
{ |
| 972 |
GThread *thread; |
| 973 |
|
| 974 |
TestDispatchThreadFuncArgs args = {object_path, check_remote_errors}; |
| 975 |
|
| 976 |
/* run this in a thread to avoid deadlocks */ |
| 977 |
thread = g_thread_new ("test_dispatch", |
| 978 |
test_dispatch_thread_func, |
| 979 |
(gpointer) &args); |
| 980 |
g_main_loop_run (loop); |
| 981 |
g_thread_join (thread); |
| 982 |
} |
| 983 |
|
| 984 |
static void |
| 985 |
test_object_registration (void) |
| 986 |
{ |
| 987 |
GError *error; |
| 988 |
ObjectRegistrationData data; |
| 989 |
GPtrArray *dyna_data; |
| 990 |
gchar **nodes; |
| 991 |
guint boss_foo_reg_id; |
| 992 |
guint boss_bar_reg_id; |
| 993 |
guint worker1_foo_reg_id; |
| 994 |
guint worker1p1_foo_reg_id; |
| 995 |
guint worker2_bar_reg_id; |
| 996 |
guint intern1_foo_reg_id; |
| 997 |
guint intern2_bar_reg_id; |
| 998 |
guint intern2_foo_reg_id; |
| 999 |
guint intern3_bar_reg_id; |
| 1000 |
guint registration_id; |
| 1001 |
guint subtree_registration_id; |
| 1002 |
guint non_subtree_object_path_foo_reg_id; |
| 1003 |
guint non_subtree_object_path_bar_reg_id; |
| 1004 |
guint dyna_subtree_registration_id; |
| 1005 |
guint num_successful_registrations; |
| 1006 |
|
| 1007 |
data.num_unregistered_calls = 0; |
| 1008 |
data.num_unregistered_subtree_calls = 0; |
| 1009 |
data.num_subtree_nodes = 0; |
| 1010 |
|
| 1011 |
num_successful_registrations = 0; |
| 1012 |
|
| 1013 |
error = NULL; |
| 1014 |
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); |
| 1015 |
g_assert_no_error (error); |
| 1016 |
g_assert (c != NULL); |
| 1017 |
|
| 1018 |
registration_id = g_dbus_connection_register_object (c, |
| 1019 |
"/foo/boss", |
| 1020 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1021 |
&foo_vtable, |
| 1022 |
&data, |
| 1023 |
on_object_unregistered, |
| 1024 |
&error); |
| 1025 |
g_assert_no_error (error); |
| 1026 |
g_assert (registration_id > 0); |
| 1027 |
boss_foo_reg_id = registration_id; |
| 1028 |
num_successful_registrations++; |
| 1029 |
|
| 1030 |
registration_id = g_dbus_connection_register_object (c, |
| 1031 |
"/foo/boss", |
| 1032 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1033 |
NULL, |
| 1034 |
&data, |
| 1035 |
on_object_unregistered, |
| 1036 |
&error); |
| 1037 |
g_assert_no_error (error); |
| 1038 |
g_assert (registration_id > 0); |
| 1039 |
boss_bar_reg_id = registration_id; |
| 1040 |
num_successful_registrations++; |
| 1041 |
|
| 1042 |
registration_id = g_dbus_connection_register_object (c, |
| 1043 |
"/foo/boss/worker1", |
| 1044 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1045 |
NULL, |
| 1046 |
&data, |
| 1047 |
on_object_unregistered, |
| 1048 |
&error); |
| 1049 |
g_assert_no_error (error); |
| 1050 |
g_assert (registration_id > 0); |
| 1051 |
worker1_foo_reg_id = registration_id; |
| 1052 |
num_successful_registrations++; |
| 1053 |
|
| 1054 |
registration_id = g_dbus_connection_register_object (c, |
| 1055 |
"/foo/boss/worker1p1", |
| 1056 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1057 |
NULL, |
| 1058 |
&data, |
| 1059 |
on_object_unregistered, |
| 1060 |
&error); |
| 1061 |
g_assert_no_error (error); |
| 1062 |
g_assert (registration_id > 0); |
| 1063 |
worker1p1_foo_reg_id = registration_id; |
| 1064 |
num_successful_registrations++; |
| 1065 |
|
| 1066 |
registration_id = g_dbus_connection_register_object (c, |
| 1067 |
"/foo/boss/worker2", |
| 1068 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1069 |
NULL, |
| 1070 |
&data, |
| 1071 |
on_object_unregistered, |
| 1072 |
&error); |
| 1073 |
g_assert_no_error (error); |
| 1074 |
g_assert (registration_id > 0); |
| 1075 |
worker2_bar_reg_id = registration_id; |
| 1076 |
num_successful_registrations++; |
| 1077 |
|
| 1078 |
registration_id = g_dbus_connection_register_object (c, |
| 1079 |
"/foo/boss/interns/intern1", |
| 1080 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1081 |
NULL, |
| 1082 |
&data, |
| 1083 |
on_object_unregistered, |
| 1084 |
&error); |
| 1085 |
g_assert_no_error (error); |
| 1086 |
g_assert (registration_id > 0); |
| 1087 |
intern1_foo_reg_id = registration_id; |
| 1088 |
num_successful_registrations++; |
| 1089 |
|
| 1090 |
/* ... and try again at another path */ |
| 1091 |
registration_id = g_dbus_connection_register_object (c, |
| 1092 |
"/foo/boss/interns/intern2", |
| 1093 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1094 |
NULL, |
| 1095 |
&data, |
| 1096 |
on_object_unregistered, |
| 1097 |
&error); |
| 1098 |
g_assert_no_error (error); |
| 1099 |
g_assert (registration_id > 0); |
| 1100 |
intern2_bar_reg_id = registration_id; |
| 1101 |
num_successful_registrations++; |
| 1102 |
|
| 1103 |
/* register at the same path/interface - this should fail */ |
| 1104 |
registration_id = g_dbus_connection_register_object (c, |
| 1105 |
"/foo/boss/interns/intern2", |
| 1106 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1107 |
NULL, |
| 1108 |
&data, |
| 1109 |
on_object_unregistered, |
| 1110 |
&error); |
| 1111 |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); |
| 1112 |
g_assert (!g_dbus_error_is_remote_error (error)); |
| 1113 |
g_error_free (error); |
| 1114 |
error = NULL; |
| 1115 |
g_assert (registration_id == 0); |
| 1116 |
|
| 1117 |
/* register at different interface - shouldn't fail */ |
| 1118 |
registration_id = g_dbus_connection_register_object (c, |
| 1119 |
"/foo/boss/interns/intern2", |
| 1120 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1121 |
NULL, |
| 1122 |
&data, |
| 1123 |
on_object_unregistered, |
| 1124 |
&error); |
| 1125 |
g_assert_no_error (error); |
| 1126 |
g_assert (registration_id > 0); |
| 1127 |
intern2_foo_reg_id = registration_id; |
| 1128 |
num_successful_registrations++; |
| 1129 |
|
| 1130 |
/* unregister it via the id */ |
| 1131 |
g_assert (g_dbus_connection_unregister_object (c, registration_id)); |
| 1132 |
g_main_context_iteration (NULL, FALSE); |
| 1133 |
g_assert_cmpint (data.num_unregistered_calls, ==, 1); |
| 1134 |
intern2_foo_reg_id = 0; |
| 1135 |
|
| 1136 |
/* register it back */ |
| 1137 |
registration_id = g_dbus_connection_register_object (c, |
| 1138 |
"/foo/boss/interns/intern2", |
| 1139 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1140 |
NULL, |
| 1141 |
&data, |
| 1142 |
on_object_unregistered, |
| 1143 |
&error); |
| 1144 |
g_assert_no_error (error); |
| 1145 |
g_assert (registration_id > 0); |
| 1146 |
intern2_foo_reg_id = registration_id; |
| 1147 |
num_successful_registrations++; |
| 1148 |
|
| 1149 |
registration_id = g_dbus_connection_register_object (c, |
| 1150 |
"/foo/boss/interns/intern3", |
| 1151 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1152 |
NULL, |
| 1153 |
&data, |
| 1154 |
on_object_unregistered, |
| 1155 |
&error); |
| 1156 |
g_assert_no_error (error); |
| 1157 |
g_assert (registration_id > 0); |
| 1158 |
intern3_bar_reg_id = registration_id; |
| 1159 |
num_successful_registrations++; |
| 1160 |
|
| 1161 |
/* now register a whole subtree at /foo/boss/executives */ |
| 1162 |
subtree_registration_id = g_dbus_connection_register_subtree (c, |
| 1163 |
"/foo/boss/executives", |
| 1164 |
&subtree_vtable, |
| 1165 |
G_DBUS_SUBTREE_FLAGS_NONE, |
| 1166 |
&data, |
| 1167 |
on_subtree_unregistered, |
| 1168 |
&error); |
| 1169 |
g_assert_no_error (error); |
| 1170 |
g_assert (subtree_registration_id > 0); |
| 1171 |
/* try registering it again.. this should fail */ |
| 1172 |
registration_id = g_dbus_connection_register_subtree (c, |
| 1173 |
"/foo/boss/executives", |
| 1174 |
&subtree_vtable, |
| 1175 |
G_DBUS_SUBTREE_FLAGS_NONE, |
| 1176 |
&data, |
| 1177 |
on_subtree_unregistered, |
| 1178 |
&error); |
| 1179 |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); |
| 1180 |
g_assert (!g_dbus_error_is_remote_error (error)); |
| 1181 |
g_error_free (error); |
| 1182 |
error = NULL; |
| 1183 |
g_assert (registration_id == 0); |
| 1184 |
|
| 1185 |
/* unregister it, then register it again */ |
| 1186 |
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 0); |
| 1187 |
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id)); |
| 1188 |
g_main_context_iteration (NULL, FALSE); |
| 1189 |
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1); |
| 1190 |
subtree_registration_id = g_dbus_connection_register_subtree (c, |
| 1191 |
"/foo/boss/executives", |
| 1192 |
&subtree_vtable, |
| 1193 |
G_DBUS_SUBTREE_FLAGS_NONE, |
| 1194 |
&data, |
| 1195 |
on_subtree_unregistered, |
| 1196 |
&error); |
| 1197 |
g_assert_no_error (error); |
| 1198 |
g_assert (subtree_registration_id > 0); |
| 1199 |
|
| 1200 |
/* try to register something under /foo/boss/executives - this should work |
| 1201 |
* because registered subtrees and registered objects can coexist. |
| 1202 |
* |
| 1203 |
* Make the exported object implement *two* interfaces so we can check |
| 1204 |
* that the right introspection handler is invoked. |
| 1205 |
*/ |
| 1206 |
registration_id = g_dbus_connection_register_object (c, |
| 1207 |
"/foo/boss/executives/non_subtree_object", |
| 1208 |
(GDBusInterfaceInfo *) &bar_interface_info, |
| 1209 |
NULL, |
| 1210 |
&data, |
| 1211 |
on_object_unregistered, |
| 1212 |
&error); |
| 1213 |
g_assert_no_error (error); |
| 1214 |
g_assert (registration_id > 0); |
| 1215 |
non_subtree_object_path_bar_reg_id = registration_id; |
| 1216 |
num_successful_registrations++; |
| 1217 |
registration_id = g_dbus_connection_register_object (c, |
| 1218 |
"/foo/boss/executives/non_subtree_object", |
| 1219 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1220 |
NULL, |
| 1221 |
&data, |
| 1222 |
on_object_unregistered, |
| 1223 |
&error); |
| 1224 |
g_assert_no_error (error); |
| 1225 |
g_assert (registration_id > 0); |
| 1226 |
non_subtree_object_path_foo_reg_id = registration_id; |
| 1227 |
num_successful_registrations++; |
| 1228 |
|
| 1229 |
/* now register a dynamic subtree, spawning objects as they are called */ |
| 1230 |
dyna_data = g_ptr_array_new_with_free_func (g_free); |
| 1231 |
dyna_subtree_registration_id = g_dbus_connection_register_subtree (c, |
| 1232 |
"/foo/dyna", |
| 1233 |
&dynamic_subtree_vtable, |
| 1234 |
G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES, |
| 1235 |
dyna_data, |
| 1236 |
(GDestroyNotify)g_ptr_array_unref, |
| 1237 |
&error); |
| 1238 |
g_assert_no_error (error); |
| 1239 |
g_assert (dyna_subtree_registration_id > 0); |
| 1240 |
|
| 1241 |
/* First assert that we have no nodes in the dynamic subtree */ |
| 1242 |
nodes = get_nodes_at (c, "/foo/dyna"); |
| 1243 |
g_assert (nodes != NULL); |
| 1244 |
g_assert_cmpint (g_strv_length (nodes), ==, 0); |
| 1245 |
g_strfreev (nodes); |
| 1246 |
g_assert_cmpint (count_interfaces (c, "/foo/dyna"), ==, 4); |
| 1247 |
|
| 1248 |
/* Install three nodes in the dynamic subtree via the dyna_data backdoor and |
| 1249 |
* assert that they show up correctly in the introspection data */ |
| 1250 |
g_ptr_array_add (dyna_data, g_strdup ("lol")); |
| 1251 |
g_ptr_array_add (dyna_data, g_strdup ("cat")); |
| 1252 |
g_ptr_array_add (dyna_data, g_strdup ("cheezburger")); |
| 1253 |
nodes = get_nodes_at (c, "/foo/dyna"); |
| 1254 |
g_assert (nodes != NULL); |
| 1255 |
g_assert_cmpint (g_strv_length (nodes), ==, 3); |
| 1256 |
g_assert_cmpstr (nodes[0], ==, "cat"); |
| 1257 |
g_assert_cmpstr (nodes[1], ==, "cheezburger"); |
| 1258 |
g_assert_cmpstr (nodes[2], ==, "lol"); |
| 1259 |
g_strfreev (nodes); |
| 1260 |
g_assert_cmpint (count_interfaces (c, "/foo/dyna/lol"), ==, 4); |
| 1261 |
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cat"), ==, 4); |
| 1262 |
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cheezburger"), ==, 4); |
| 1263 |
|
| 1264 |
/* Call a non-existing object path and assert that it has been created */ |
| 1265 |
dyna_create (c, "dynamicallycreated"); |
| 1266 |
nodes = get_nodes_at (c, "/foo/dyna"); |
| 1267 |
g_assert (nodes != NULL); |
| 1268 |
g_assert_cmpint (g_strv_length (nodes), ==, 4); |
| 1269 |
g_assert_cmpstr (nodes[0], ==, "cat"); |
| 1270 |
g_assert_cmpstr (nodes[1], ==, "cheezburger"); |
| 1271 |
g_assert_cmpstr (nodes[2], ==, "dynamicallycreated"); |
| 1272 |
g_assert_cmpstr (nodes[3], ==, "lol"); |
| 1273 |
g_strfreev (nodes); |
| 1274 |
g_assert_cmpint (count_interfaces (c, "/foo/dyna/dynamicallycreated"), ==, 4); |
| 1275 |
|
| 1276 |
/* now check that the object hierarchy is properly generated... yes, it's a bit |
| 1277 |
* perverse that we round-trip to the bus to introspect ourselves ;-) |
| 1278 |
*/ |
| 1279 |
nodes = get_nodes_at (c, "/"); |
| 1280 |
g_assert (nodes != NULL); |
| 1281 |
g_assert_cmpint (g_strv_length (nodes), ==, 1); |
| 1282 |
g_assert_cmpstr (nodes[0], ==, "foo"); |
| 1283 |
g_strfreev (nodes); |
| 1284 |
g_assert_cmpint (count_interfaces (c, "/"), ==, 0); |
| 1285 |
|
| 1286 |
nodes = get_nodes_at (c, "/foo"); |
| 1287 |
g_assert (nodes != NULL); |
| 1288 |
g_assert_cmpint (g_strv_length (nodes), ==, 2); |
| 1289 |
g_assert_cmpstr (nodes[0], ==, "boss"); |
| 1290 |
g_assert_cmpstr (nodes[1], ==, "dyna"); |
| 1291 |
g_strfreev (nodes); |
| 1292 |
g_assert_cmpint (count_interfaces (c, "/foo"), ==, 0); |
| 1293 |
|
| 1294 |
nodes = get_nodes_at (c, "/foo/boss"); |
| 1295 |
g_assert (nodes != NULL); |
| 1296 |
g_assert_cmpint (g_strv_length (nodes), ==, 5); |
| 1297 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker1")); |
| 1298 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker1p1")); |
| 1299 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "worker2")); |
| 1300 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "interns")); |
| 1301 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "executives")); |
| 1302 |
g_strfreev (nodes); |
| 1303 |
/* any registered object always implement org.freedesktop.DBus.[Peer,Introspectable,Properties] */ |
| 1304 |
g_assert_cmpint (count_interfaces (c, "/foo/boss"), ==, 5); |
| 1305 |
g_assert (has_interface (c, "/foo/boss", foo_interface_info.name)); |
| 1306 |
g_assert (has_interface (c, "/foo/boss", bar_interface_info.name)); |
| 1307 |
|
| 1308 |
/* check subtree nodes - we should have only non_subtree_object in /foo/boss/executives |
| 1309 |
* because data.num_subtree_nodes is 0 |
| 1310 |
*/ |
| 1311 |
nodes = get_nodes_at (c, "/foo/boss/executives"); |
| 1312 |
g_assert (nodes != NULL); |
| 1313 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); |
| 1314 |
g_assert_cmpint (g_strv_length (nodes), ==, 1); |
| 1315 |
g_strfreev (nodes); |
| 1316 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives"), ==, 0); |
| 1317 |
|
| 1318 |
/* now change data.num_subtree_nodes and check */ |
| 1319 |
data.num_subtree_nodes = 2; |
| 1320 |
nodes = get_nodes_at (c, "/foo/boss/executives"); |
| 1321 |
g_assert (nodes != NULL); |
| 1322 |
g_assert_cmpint (g_strv_length (nodes), ==, 5); |
| 1323 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); |
| 1324 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp0")); |
| 1325 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp1")); |
| 1326 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp0")); |
| 1327 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp1")); |
| 1328 |
/* check that /foo/boss/executives/non_subtree_object is not handled by the |
| 1329 |
* subtree handlers - we can do this because objects from subtree handlers |
| 1330 |
* has exactly one interface and non_subtree_object has two |
| 1331 |
*/ |
| 1332 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/non_subtree_object"), ==, 5); |
| 1333 |
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", foo_interface_info.name)); |
| 1334 |
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", bar_interface_info.name)); |
| 1335 |
/* check that the vp and evp objects are handled by the subtree handlers */ |
| 1336 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp0"), ==, 4); |
| 1337 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp1"), ==, 4); |
| 1338 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp0"), ==, 4); |
| 1339 |
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp1"), ==, 4); |
| 1340 |
g_assert (has_interface (c, "/foo/boss/executives/vp0", foo_interface_info.name)); |
| 1341 |
g_assert (has_interface (c, "/foo/boss/executives/vp1", foo_interface_info.name)); |
| 1342 |
g_assert (has_interface (c, "/foo/boss/executives/evp0", bar_interface_info.name)); |
| 1343 |
g_assert (has_interface (c, "/foo/boss/executives/evp1", bar_interface_info.name)); |
| 1344 |
g_strfreev (nodes); |
| 1345 |
data.num_subtree_nodes = 3; |
| 1346 |
nodes = get_nodes_at (c, "/foo/boss/executives"); |
| 1347 |
g_assert (nodes != NULL); |
| 1348 |
g_assert_cmpint (g_strv_length (nodes), ==, 7); |
| 1349 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); |
| 1350 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp0")); |
| 1351 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp1")); |
| 1352 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "vp2")); |
| 1353 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp0")); |
| 1354 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp1")); |
| 1355 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "evp2")); |
| 1356 |
g_strfreev (nodes); |
| 1357 |
|
| 1358 |
/* This is to check that a bug (rather, class of bugs) in gdbusconnection.c's |
| 1359 |
* |
| 1360 |
* g_dbus_connection_list_registered_unlocked() |
| 1361 |
* |
| 1362 |
* where /foo/boss/worker1 reported a child '1', is now fixed. |
| 1363 |
*/ |
| 1364 |
nodes = get_nodes_at (c, "/foo/boss/worker1"); |
| 1365 |
g_assert (nodes != NULL); |
| 1366 |
g_assert_cmpint (g_strv_length (nodes), ==, 0); |
| 1367 |
g_strfreev (nodes); |
| 1368 |
|
| 1369 |
/* check that calls are properly dispatched to the functions in foo_vtable for objects |
| 1370 |
* implementing the org.example.Foo interface |
| 1371 |
* |
| 1372 |
* We do this for both a regular registered object (/foo/boss) and also for an object |
| 1373 |
* registered through the subtree mechanism. |
| 1374 |
*/ |
| 1375 |
test_dispatch ("/foo/boss", TRUE); |
| 1376 |
test_dispatch ("/foo/boss/executives/vp0", TRUE); |
| 1377 |
|
| 1378 |
/* To prevent from exiting and attaching a D-Bus tool like D-Feet; uncomment: */ |
| 1379 |
#if 0 |
| 1380 |
g_debug ("Point D-feet or other tool at: %s", g_test_dbus_get_temporary_address()); |
| 1381 |
g_main_loop_run (loop); |
| 1382 |
#endif |
| 1383 |
|
| 1384 |
/* check that unregistering the subtree handler works */ |
| 1385 |
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1); |
| 1386 |
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id)); |
| 1387 |
g_main_context_iteration (NULL, FALSE); |
| 1388 |
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2); |
| 1389 |
nodes = get_nodes_at (c, "/foo/boss/executives"); |
| 1390 |
g_assert (nodes != NULL); |
| 1391 |
g_assert_cmpint (g_strv_length (nodes), ==, 1); |
| 1392 |
g_assert (g_strv_contains ((const gchar* const *) nodes, "non_subtree_object")); |
| 1393 |
g_strfreev (nodes); |
| 1394 |
|
| 1395 |
g_assert (g_dbus_connection_unregister_object (c, boss_foo_reg_id)); |
| 1396 |
g_assert (g_dbus_connection_unregister_object (c, boss_bar_reg_id)); |
| 1397 |
g_assert (g_dbus_connection_unregister_object (c, worker1_foo_reg_id)); |
| 1398 |
g_assert (g_dbus_connection_unregister_object (c, worker1p1_foo_reg_id)); |
| 1399 |
g_assert (g_dbus_connection_unregister_object (c, worker2_bar_reg_id)); |
| 1400 |
g_assert (g_dbus_connection_unregister_object (c, intern1_foo_reg_id)); |
| 1401 |
g_assert (g_dbus_connection_unregister_object (c, intern2_bar_reg_id)); |
| 1402 |
g_assert (g_dbus_connection_unregister_object (c, intern2_foo_reg_id)); |
| 1403 |
g_assert (g_dbus_connection_unregister_object (c, intern3_bar_reg_id)); |
| 1404 |
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_bar_reg_id)); |
| 1405 |
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_foo_reg_id)); |
| 1406 |
|
| 1407 |
g_main_context_iteration (NULL, FALSE); |
| 1408 |
g_assert_cmpint (data.num_unregistered_calls, ==, num_successful_registrations); |
| 1409 |
|
| 1410 |
/* check that we no longer export any objects - TODO: it looks like there's a bug in |
| 1411 |
* libdbus-1 here: libdbus still reports the '/foo' object; so disable the test for now |
| 1412 |
*/ |
| 1413 |
#if 0 |
| 1414 |
nodes = get_nodes_at (c, "/"); |
| 1415 |
g_assert (nodes != NULL); |
| 1416 |
g_assert_cmpint (g_strv_length (nodes), ==, 0); |
| 1417 |
g_strfreev (nodes); |
| 1418 |
#endif |
| 1419 |
|
| 1420 |
g_object_unref (c); |
| 1421 |
} |
| 1422 |
|
| 1423 |
static void |
| 1424 |
test_object_registration_with_closures (void) |
| 1425 |
{ |
| 1426 |
GError *error; |
| 1427 |
guint registration_id; |
| 1428 |
|
| 1429 |
error = NULL; |
| 1430 |
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); |
| 1431 |
g_assert_no_error (error); |
| 1432 |
g_assert (c != NULL); |
| 1433 |
|
| 1434 |
registration_id = g_dbus_connection_register_object_with_closures (c, |
| 1435 |
"/foo/boss", |
| 1436 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1437 |
g_cclosure_new (G_CALLBACK (foo_method_call), NULL, NULL), |
| 1438 |
g_cclosure_new (G_CALLBACK (foo_get_property), NULL, NULL), |
| 1439 |
g_cclosure_new (G_CALLBACK (foo_set_property), NULL, NULL), |
| 1440 |
&error); |
| 1441 |
g_assert_no_error (error); |
| 1442 |
g_assert (registration_id > 0); |
| 1443 |
|
| 1444 |
test_dispatch ("/foo/boss", FALSE); |
| 1445 |
|
| 1446 |
g_assert (g_dbus_connection_unregister_object (c, registration_id)); |
| 1447 |
|
| 1448 |
g_object_unref (c); |
| 1449 |
} |
| 1450 |
|
| 1451 |
static const GDBusInterfaceInfo test_interface_info1 = |
| 1452 |
{ |
| 1453 |
-1, |
| 1454 |
"org.example.Foo", |
| 1455 |
(GDBusMethodInfo **) NULL, |
| 1456 |
(GDBusSignalInfo **) NULL, |
| 1457 |
(GDBusPropertyInfo **) NULL, |
| 1458 |
NULL, |
| 1459 |
}; |
| 1460 |
|
| 1461 |
static const GDBusInterfaceInfo test_interface_info2 = |
| 1462 |
{ |
| 1463 |
-1, |
| 1464 |
"org.freedesktop.DBus.Properties", |
| 1465 |
(GDBusMethodInfo **) NULL, |
| 1466 |
(GDBusSignalInfo **) NULL, |
| 1467 |
(GDBusPropertyInfo **) NULL, |
| 1468 |
NULL, |
| 1469 |
}; |
| 1470 |
|
| 1471 |
static void |
| 1472 |
check_interfaces (GDBusConnection *c, |
| 1473 |
const gchar *object_path, |
| 1474 |
const gchar **interfaces) |
| 1475 |
{ |
| 1476 |
GError *error; |
| 1477 |
GDBusProxy *proxy; |
| 1478 |
gchar *xml_data; |
| 1479 |
GDBusNodeInfo *node_info; |
| 1480 |
gint i, j; |
| 1481 |
|
| 1482 |
error = NULL; |
| 1483 |
proxy = g_dbus_proxy_new_sync (c, |
| 1484 |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | |
| 1485 |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, |
| 1486 |
NULL, |
| 1487 |
g_dbus_connection_get_unique_name (c), |
| 1488 |
object_path, |
| 1489 |
"org.freedesktop.DBus.Introspectable", |
| 1490 |
NULL, |
| 1491 |
&error); |
| 1492 |
g_assert_no_error (error); |
| 1493 |
g_assert (proxy != NULL); |
| 1494 |
|
| 1495 |
/* do this async to avoid libdbus-1 deadlocks */ |
| 1496 |
xml_data = NULL; |
| 1497 |
g_dbus_proxy_call (proxy, |
| 1498 |
"Introspect", |
| 1499 |
NULL, |
| 1500 |
G_DBUS_CALL_FLAGS_NONE, |
| 1501 |
-1, |
| 1502 |
NULL, |
| 1503 |
(GAsyncReadyCallback) introspect_callback, |
| 1504 |
&xml_data); |
| 1505 |
g_main_loop_run (loop); |
| 1506 |
g_assert (xml_data != NULL); |
| 1507 |
|
| 1508 |
node_info = g_dbus_node_info_new_for_xml (xml_data, &error); |
| 1509 |
g_assert_no_error (error); |
| 1510 |
g_assert (node_info != NULL); |
| 1511 |
|
| 1512 |
g_assert (node_info->interfaces != NULL); |
| 1513 |
for (i = 0; node_info->interfaces[i]; i++) ; |
| 1514 |
#if 0 |
| 1515 |
if (g_strv_length ((gchar**)interfaces) != i - 1) |
| 1516 |
{ |
| 1517 |
g_printerr ("expected "); |
| 1518 |
for (i = 0; interfaces[i]; i++) |
| 1519 |
g_printerr ("%s ", interfaces[i]); |
| 1520 |
g_printerr ("\ngot "); |
| 1521 |
for (i = 0; node_info->interfaces[i]; i++) |
| 1522 |
g_printerr ("%s ", node_info->interfaces[i]->name); |
| 1523 |
g_printerr ("\n"); |
| 1524 |
} |
| 1525 |
#endif |
| 1526 |
g_assert_cmpint (g_strv_length ((gchar**)interfaces), ==, i - 1); |
| 1527 |
|
| 1528 |
for (i = 0; interfaces[i]; i++) |
| 1529 |
{ |
| 1530 |
for (j = 0; node_info->interfaces[j]; j++) |
| 1531 |
{ |
| 1532 |
if (strcmp (interfaces[i], node_info->interfaces[j]->name) == 0) |
| 1533 |
goto found; |
| 1534 |
} |
| 1535 |
|
| 1536 |
g_assert_not_reached (); |
| 1537 |
|
| 1538 |
found: ; |
| 1539 |
} |
| 1540 |
|
| 1541 |
g_object_unref (proxy); |
| 1542 |
g_free (xml_data); |
| 1543 |
g_dbus_node_info_unref (node_info); |
| 1544 |
} |
| 1545 |
|
| 1546 |
static void |
| 1547 |
test_registered_interfaces (void) |
| 1548 |
{ |
| 1549 |
GError *error; |
| 1550 |
guint id1, id2; |
| 1551 |
const gchar *interfaces[] = { |
| 1552 |
"org.example.Foo", |
| 1553 |
"org.freedesktop.DBus.Properties", |
| 1554 |
"org.freedesktop.DBus.Introspectable", |
| 1555 |
NULL, |
| 1556 |
}; |
| 1557 |
|
| 1558 |
error = NULL; |
| 1559 |
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); |
| 1560 |
g_assert_no_error (error); |
| 1561 |
g_assert (c != NULL); |
| 1562 |
|
| 1563 |
id1 = g_dbus_connection_register_object (c, |
| 1564 |
"/test", |
| 1565 |
(GDBusInterfaceInfo *) &test_interface_info1, |
| 1566 |
NULL, |
| 1567 |
NULL, |
| 1568 |
NULL, |
| 1569 |
&error); |
| 1570 |
g_assert_no_error (error); |
| 1571 |
g_assert (id1 > 0); |
| 1572 |
id2 = g_dbus_connection_register_object (c, |
| 1573 |
"/test", |
| 1574 |
(GDBusInterfaceInfo *) &test_interface_info2, |
| 1575 |
NULL, |
| 1576 |
NULL, |
| 1577 |
NULL, |
| 1578 |
&error); |
| 1579 |
g_assert_no_error (error); |
| 1580 |
g_assert (id2 > 0); |
| 1581 |
|
| 1582 |
check_interfaces (c, "/test", interfaces); |
| 1583 |
|
| 1584 |
g_assert (g_dbus_connection_unregister_object (c, id1)); |
| 1585 |
g_assert (g_dbus_connection_unregister_object (c, id2)); |
| 1586 |
g_object_unref (c); |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1591 |
|
| 1592 |
static void |
| 1593 |
test_async_method_call (GDBusConnection *connection, |
| 1594 |
const gchar *sender, |
| 1595 |
const gchar *object_path, |
| 1596 |
const gchar *interface_name, |
| 1597 |
const gchar *method_name, |
| 1598 |
GVariant *parameters, |
| 1599 |
GDBusMethodInvocation *invocation, |
| 1600 |
gpointer user_data) |
| 1601 |
{ |
| 1602 |
const GDBusPropertyInfo *property; |
| 1603 |
|
| 1604 |
/* Strictly speaking, this function should also expect to receive |
| 1605 |
* method calls not on the org.freedesktop.DBus.Properties interface, |
| 1606 |
* but we don't do any during this testcase, so assert that. |
| 1607 |
*/ |
| 1608 |
g_assert_cmpstr (interface_name, ==, "org.freedesktop.DBus.Properties"); |
| 1609 |
g_assert (g_dbus_method_invocation_get_method_info (invocation) == NULL); |
| 1610 |
|
| 1611 |
property = g_dbus_method_invocation_get_property_info (invocation); |
| 1612 |
|
| 1613 |
/* We should never be seeing any property calls on the com.example.Bar |
| 1614 |
* interface because it doesn't export any properties. |
| 1615 |
* |
| 1616 |
* In each case below make sure the interface is org.example.Foo. |
| 1617 |
*/ |
| 1618 |
|
| 1619 |
/* Do a whole lot of asserts to make sure that invalid calls are still |
| 1620 |
* getting properly rejected by GDBusConnection and that our |
| 1621 |
* environment is as we expect it to be. |
| 1622 |
*/ |
| 1623 |
if (g_str_equal (method_name, "Get")) |
| 1624 |
{ |
| 1625 |
const gchar *iface_name, *prop_name; |
| 1626 |
|
| 1627 |
g_variant_get (parameters, "(&s&s)", &iface_name, &prop_name); |
| 1628 |
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); |
| 1629 |
g_assert (property != NULL); |
| 1630 |
g_assert_cmpstr (prop_name, ==, property->name); |
| 1631 |
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE); |
| 1632 |
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", g_variant_new_string (prop_name))); |
| 1633 |
} |
| 1634 |
|
| 1635 |
else if (g_str_equal (method_name, "Set")) |
| 1636 |
{ |
| 1637 |
const gchar *iface_name, *prop_name; |
| 1638 |
GVariant *value; |
| 1639 |
|
| 1640 |
g_variant_get (parameters, "(&s&sv)", &iface_name, &prop_name, &value); |
| 1641 |
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); |
| 1642 |
g_assert (property != NULL); |
| 1643 |
g_assert_cmpstr (prop_name, ==, property->name); |
| 1644 |
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE); |
| 1645 |
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE (property->signature))); |
| 1646 |
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); |
| 1647 |
g_variant_unref (value); |
| 1648 |
} |
| 1649 |
|
| 1650 |
else if (g_str_equal (method_name, "GetAll")) |
| 1651 |
{ |
| 1652 |
const gchar *iface_name; |
| 1653 |
|
| 1654 |
g_variant_get (parameters, "(&s)", &iface_name); |
| 1655 |
g_assert_cmpstr (iface_name, ==, "org.example.Foo"); |
| 1656 |
g_assert (property == NULL); |
| 1657 |
g_dbus_method_invocation_return_value (invocation, |
| 1658 |
g_variant_new_parsed ("({ 'PropertyUno': < 'uno' >," |
| 1659 |
" 'NotWritable': < 'notwrite' > },)")); |
| 1660 |
} |
| 1661 |
|
| 1662 |
else |
| 1663 |
g_assert_not_reached (); |
| 1664 |
} |
| 1665 |
|
| 1666 |
static gint outstanding_cases; |
| 1667 |
|
| 1668 |
static void |
| 1669 |
ensure_result_cb (GObject *source, |
| 1670 |
GAsyncResult *result, |
| 1671 |
gpointer user_data) |
| 1672 |
{ |
| 1673 |
GDBusConnection *connection = G_DBUS_CONNECTION (source); |
| 1674 |
GVariant *reply; |
| 1675 |
|
| 1676 |
reply = g_dbus_connection_call_finish (connection, result, NULL); |
| 1677 |
|
| 1678 |
if (user_data == NULL) |
| 1679 |
{ |
| 1680 |
/* Expected an error */ |
| 1681 |
g_assert (reply == NULL); |
| 1682 |
} |
| 1683 |
else |
| 1684 |
{ |
| 1685 |
/* Expected a reply of a particular format. */ |
| 1686 |
gchar *str; |
| 1687 |
|
| 1688 |
g_assert (reply != NULL); |
| 1689 |
str = g_variant_print (reply, TRUE); |
| 1690 |
g_assert_cmpstr (str, ==, (const gchar *) user_data); |
| 1691 |
g_free (str); |
| 1692 |
|
| 1693 |
g_variant_unref (reply); |
| 1694 |
} |
| 1695 |
|
| 1696 |
g_assert_cmpint (outstanding_cases, >, 0); |
| 1697 |
outstanding_cases--; |
| 1698 |
} |
| 1699 |
|
| 1700 |
static void |
| 1701 |
test_async_case (GDBusConnection *connection, |
| 1702 |
const gchar *expected_reply, |
| 1703 |
const gchar *method, |
| 1704 |
const gchar *format_string, |
| 1705 |
...) |
| 1706 |
{ |
| 1707 |
va_list ap; |
| 1708 |
|
| 1709 |
va_start (ap, format_string); |
| 1710 |
|
| 1711 |
g_dbus_connection_call (connection, g_dbus_connection_get_unique_name (connection), "/foo", |
| 1712 |
"org.freedesktop.DBus.Properties", method, g_variant_new_va (format_string, NULL, &ap), |
| 1713 |
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, ensure_result_cb, (gpointer) expected_reply); |
| 1714 |
|
| 1715 |
va_end (ap); |
| 1716 |
|
| 1717 |
outstanding_cases++; |
| 1718 |
} |
| 1719 |
|
| 1720 |
static void |
| 1721 |
test_async_properties (void) |
| 1722 |
{ |
| 1723 |
GError *error = NULL; |
| 1724 |
guint registration_id, registration_id2; |
| 1725 |
static const GDBusInterfaceVTable vtable = { |
| 1726 |
test_async_method_call, NULL, NULL, { 0 } |
| 1727 |
}; |
| 1728 |
|
| 1729 |
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); |
| 1730 |
g_assert_no_error (error); |
| 1731 |
g_assert (c != NULL); |
| 1732 |
|
| 1733 |
registration_id = g_dbus_connection_register_object (c, |
| 1734 |
"/foo", |
| 1735 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1736 |
&vtable, NULL, NULL, &error); |
| 1737 |
g_assert_no_error (error); |
| 1738 |
g_assert (registration_id); |
| 1739 |
registration_id2 = g_dbus_connection_register_object (c, |
| 1740 |
"/foo", |
| 1741 |
(GDBusInterfaceInfo *) &foo2_interface_info, |
| 1742 |
&vtable, NULL, NULL, &error); |
| 1743 |
g_assert_no_error (error); |
| 1744 |
g_assert (registration_id); |
| 1745 |
|
| 1746 |
test_async_case (c, NULL, "random", "()"); |
| 1747 |
|
| 1748 |
/* Test a variety of error cases */ |
| 1749 |
test_async_case (c, NULL, "Get", "(si)", "wrong signature", 5); |
| 1750 |
test_async_case (c, NULL, "Get", "(ss)", "org.example.WrongInterface", "zzz"); |
| 1751 |
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NoSuchProperty"); |
| 1752 |
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NotReadable"); |
| 1753 |
|
| 1754 |
test_async_case (c, NULL, "Set", "(si)", "wrong signature", 5); |
| 1755 |
test_async_case (c, NULL, "Set", "(ssv)", "org.example.WrongInterface", "zzz", g_variant_new_string ("")); |
| 1756 |
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NoSuchProperty", g_variant_new_string ("")); |
| 1757 |
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NotWritable", g_variant_new_string ("")); |
| 1758 |
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_object_path ("/wrong")); |
| 1759 |
|
| 1760 |
test_async_case (c, NULL, "GetAll", "(si)", "wrong signature", 5); |
| 1761 |
test_async_case (c, NULL, "GetAll", "(s)", "org.example.WrongInterface"); |
| 1762 |
|
| 1763 |
/* Make sure that we get no unexpected async property calls for com.example.Foo2 */ |
| 1764 |
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo2", "zzz"); |
| 1765 |
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo2", "zzz", g_variant_new_string ("")); |
| 1766 |
test_async_case (c, "(@a{sv} {},)", "GetAll", "(s)", "org.example.Foo2"); |
| 1767 |
|
| 1768 |
/* Now do the proper things */ |
| 1769 |
test_async_case (c, "(<'PropertyUno'>,)", "Get", "(ss)", "org.example.Foo", "PropertyUno"); |
| 1770 |
test_async_case (c, "(<'NotWritable'>,)", "Get", "(ss)", "org.example.Foo", "NotWritable"); |
| 1771 |
test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_string ("")); |
| 1772 |
test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "NotReadable", g_variant_new_string ("")); |
| 1773 |
test_async_case (c, "({'PropertyUno': <'uno'>, 'NotWritable': <'notwrite'>},)", "GetAll", "(s)", "org.example.Foo"); |
| 1774 |
|
| 1775 |
while (outstanding_cases) |
| 1776 |
g_main_context_iteration (NULL, TRUE); |
| 1777 |
|
| 1778 |
g_dbus_connection_unregister_object (c, registration_id); |
| 1779 |
g_dbus_connection_unregister_object (c, registration_id2); |
| 1780 |
g_object_unref (c); |
| 1781 |
} |
| 1782 |
|
| 1783 |
typedef struct |
| 1784 |
{ |
| 1785 |
GDBusConnection *connection; /* (owned) */ |
| 1786 |
guint registration_id; |
| 1787 |
guint subtree_registration_id; |
| 1788 |
} ThreadedUnregistrationData; |
| 1789 |
|
| 1790 |
static gpointer |
| 1791 |
unregister_thread_cb (gpointer user_data) |
| 1792 |
{ |
| 1793 |
ThreadedUnregistrationData *data = user_data; |
| 1794 |
|
| 1795 |
/* Sleeping here makes the race more likely to be hit, as it balances the |
| 1796 |
* time taken to set up the thread and unregister, with the time taken to |
| 1797 |
* make and handle the D-Bus call. This will likely change with future kernel |
| 1798 |
* versions, but there isn’t a more deterministic synchronisation point that |
| 1799 |
* I can think of to use instead. */ |
| 1800 |
usleep (330); |
| 1801 |
|
| 1802 |
if (data->registration_id > 0) |
| 1803 |
g_assert_true (g_dbus_connection_unregister_object (data->connection, data->registration_id)); |
| 1804 |
|
| 1805 |
if (data->subtree_registration_id > 0) |
| 1806 |
g_assert_true (g_dbus_connection_unregister_subtree (data->connection, data->subtree_registration_id)); |
| 1807 |
|
| 1808 |
return NULL; |
| 1809 |
} |
| 1810 |
|
| 1811 |
static void |
| 1812 |
async_result_cb (GObject *source_object, |
| 1813 |
GAsyncResult *result, |
| 1814 |
gpointer user_data) |
| 1815 |
{ |
| 1816 |
GAsyncResult **result_out = user_data; |
| 1817 |
|
| 1818 |
*result_out = g_object_ref (result); |
| 1819 |
g_main_context_wakeup (NULL); |
| 1820 |
} |
| 1821 |
|
| 1822 |
/* Returns %TRUE if this iteration resolved the race with the unregistration |
| 1823 |
* first, %FALSE if the call handler was invoked first. */ |
| 1824 |
static gboolean |
| 1825 |
test_threaded_unregistration_iteration (gboolean subtree) |
| 1826 |
{ |
| 1827 |
ThreadedUnregistrationData data = { NULL, 0, 0 }; |
| 1828 |
ObjectRegistrationData object_registration_data = { 0, 0, 2 }; |
| 1829 |
GError *local_error = NULL; |
| 1830 |
GThread *unregister_thread = NULL; |
| 1831 |
const gchar *object_path; |
| 1832 |
GVariant *value = NULL; |
| 1833 |
const gchar *value_str; |
| 1834 |
GAsyncResult *call_result = NULL; |
| 1835 |
gboolean unregistration_was_first; |
| 1836 |
|
| 1837 |
data.connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &local_error); |
| 1838 |
g_assert_no_error (local_error); |
| 1839 |
g_assert_nonnull (data.connection); |
| 1840 |
|
| 1841 |
/* Register an object or a subtree */ |
| 1842 |
if (!subtree) |
| 1843 |
{ |
| 1844 |
data.registration_id = g_dbus_connection_register_object (data.connection, |
| 1845 |
"/foo/boss", |
| 1846 |
(GDBusInterfaceInfo *) &foo_interface_info, |
| 1847 |
&foo_vtable, |
| 1848 |
&object_registration_data, |
| 1849 |
on_object_unregistered, |
| 1850 |
&local_error); |
| 1851 |
g_assert_no_error (local_error); |
| 1852 |
g_assert_cmpint (data.registration_id, >, 0); |
| 1853 |
|
| 1854 |
object_path = "/foo/boss"; |
| 1855 |
} |
| 1856 |
else |
| 1857 |
{ |
| 1858 |
data.subtree_registration_id = g_dbus_connection_register_subtree (data.connection, |
| 1859 |
"/foo/boss/executives", |
| 1860 |
&subtree_vtable, |
| 1861 |
G_DBUS_SUBTREE_FLAGS_NONE, |
| 1862 |
&object_registration_data, |
| 1863 |
on_subtree_unregistered, |
| 1864 |
&local_error); |
| 1865 |
g_assert_no_error (local_error); |
| 1866 |
g_assert_cmpint (data.subtree_registration_id, >, 0); |
| 1867 |
|
| 1868 |
object_path = "/foo/boss/executives/vp0"; |
| 1869 |
} |
| 1870 |
|
| 1871 |
/* Allow the registrations to go through. */ |
| 1872 |
g_main_context_iteration (NULL, FALSE); |
| 1873 |
|
| 1874 |
/* Spawn a thread to unregister the object/subtree. This will race with |
| 1875 |
* the call we subsequently make. */ |
| 1876 |
unregister_thread = g_thread_new ("unregister-object", |
| 1877 |
unregister_thread_cb, &data); |
| 1878 |
|
| 1879 |
/* Call a method on the object (or an object in the subtree). The callback |
| 1880 |
* will be invoked in this main context. */ |
| 1881 |
g_dbus_connection_call (data.connection, |
| 1882 |
g_dbus_connection_get_unique_name (data.connection), |
| 1883 |
object_path, |
| 1884 |
"org.example.Foo", |
| 1885 |
"Method1", |
| 1886 |
g_variant_new ("(s)", "winwinwin"), |
| 1887 |
NULL, |
| 1888 |
G_DBUS_CALL_FLAGS_NONE, |
| 1889 |
-1, |
| 1890 |
NULL, |
| 1891 |
async_result_cb, |
| 1892 |
&call_result); |
| 1893 |
|
| 1894 |
while (call_result == NULL) |
| 1895 |
g_main_context_iteration (NULL, TRUE); |
| 1896 |
|
| 1897 |
value = g_dbus_connection_call_finish (data.connection, call_result, &local_error); |
| 1898 |
|
| 1899 |
/* The result of the method could either be an error (that the object doesn’t |
| 1900 |
* exist) or a valid result, depending on how the thread was scheduled |
| 1901 |
* relative to the call. */ |
| 1902 |
unregistration_was_first = (value == NULL); |
| 1903 |
if (value != NULL) |
| 1904 |
{ |
| 1905 |
g_assert_no_error (local_error); |
| 1906 |
g_assert_true (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)"))); |
| 1907 |
g_variant_get (value, "(&s)", &value_str); |
| 1908 |
g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!"); |
| 1909 |
} |
| 1910 |
else |
| 1911 |
{ |
| 1912 |
g_assert_null (value); |
| 1913 |
g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD); |
| 1914 |
} |
| 1915 |
|
| 1916 |
g_clear_pointer (&value, g_variant_unref); |
| 1917 |
g_clear_error (&local_error); |
| 1918 |
|
| 1919 |
/* Tidy up. */ |
| 1920 |
g_thread_join (g_steal_pointer (&unregister_thread)); |
| 1921 |
|
| 1922 |
g_clear_object (&call_result); |
| 1923 |
g_clear_object (&data.connection); |
| 1924 |
|
| 1925 |
return unregistration_was_first; |
| 1926 |
} |
| 1927 |
|
| 1928 |
static void |
| 1929 |
test_threaded_unregistration (gconstpointer test_data) |
| 1930 |
{ |
| 1931 |
gboolean subtree = GPOINTER_TO_INT (test_data); |
| 1932 |
guint i; |
| 1933 |
guint n_iterations_unregistration_first = 0; |
| 1934 |
guint n_iterations_call_first = 0; |
| 1935 |
|
| 1936 |
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2400"); |
| 1937 |
g_test_summary ("Test that object/subtree unregistration from one thread " |
| 1938 |
"doesn’t cause problems when racing with method callbacks " |
| 1939 |
"in another thread for that object or subtree"); |
| 1940 |
|
| 1941 |
/* Run iterations of the test until it’s likely we’ve hit the race. Limit the |
| 1942 |
* number of iterations so the test doesn’t run forever if not. The choice of |
| 1943 |
* 100 is arbitrary. */ |
| 1944 |
for (i = 0; i < 1000 && (n_iterations_unregistration_first < 100 || n_iterations_call_first < 100); i++) |
| 1945 |
{ |
| 1946 |
if (test_threaded_unregistration_iteration (subtree)) |
| 1947 |
n_iterations_unregistration_first++; |
| 1948 |
else |
| 1949 |
n_iterations_call_first++; |
| 1950 |
} |
| 1951 |
|
| 1952 |
/* If the condition below is met, we probably failed to reproduce the race. |
| 1953 |
* Don’t fail the test, though, as we can’t always control whether we hit the |
| 1954 |
* race, and spurious test failures are annoying. */ |
| 1955 |
if (n_iterations_unregistration_first < 100 || |
| 1956 |
n_iterations_call_first < 100) |
| 1957 |
g_test_skip_printf ("Failed to reproduce race (%u iterations with unregistration first, %u with call first); skipping test", |
| 1958 |
n_iterations_unregistration_first, n_iterations_call_first); |
| 1959 |
} |
| 1960 |
|
| 1961 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1962 |
|
| 1963 |
int |
| 1964 |
main (int argc, |
| 1965 |
char *argv[]) |
| 1966 |
{ |
| 1967 |
gint ret; |
| 1968 |
|
| 1969 |
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); |
| 1970 |
|
| 1971 |
/* all the tests rely on a shared main loop */ |
| 1972 |
loop = g_main_loop_new (NULL, FALSE); |
| 1973 |
|
| 1974 |
g_test_add_func ("/gdbus/object-registration", test_object_registration); |
| 1975 |
g_test_add_func ("/gdbus/object-registration-with-closures", test_object_registration_with_closures); |
| 1976 |
g_test_add_func ("/gdbus/registered-interfaces", test_registered_interfaces); |
| 1977 |
g_test_add_func ("/gdbus/async-properties", test_async_properties); |
| 1978 |
g_test_add_data_func ("/gdbus/threaded-unregistration/object", GINT_TO_POINTER (FALSE), test_threaded_unregistration); |
| 1979 |
g_test_add_data_func ("/gdbus/threaded-unregistration/subtree", GINT_TO_POINTER (TRUE), test_threaded_unregistration); |
| 1980 |
|
| 1981 |
/* TODO: check that we spit out correct introspection data */ |
| 1982 |
/* TODO: check that registering a whole subtree works */ |
| 1983 |
|
| 1984 |
ret = session_bus_run (); |
| 1985 |
|
| 1986 |
g_main_loop_unref (loop); |
| 1987 |
|
| 1988 |
return ret; |
| 1989 |
} |