1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-object-tree.c DBusObjectTree (internals of DBusConnection)
4 * Copyright (C) 2003 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "dbus-object-tree.h"
24 #include "dbus-connection-internal.h"
25 #include "dbus-internals.h"
26 #include "dbus-hash.h"
27 #include "dbus-protocol.h"
28 #include "dbus-string.h"
33 * @defgroup DBusObjectTree A hierarchy of objects with container-contained relationship
34 * @ingroup DBusInternals
35 * @brief DBusObjectTree is used by DBusConnection to track the object tree
37 * Types and functions related to DBusObjectTree. These
38 * are all library-internal.
43 /** Subnode of the object hierarchy */
44 typedef struct DBusObjectSubtree DBusObjectSubtree;
46 static DBusObjectSubtree* _dbus_object_subtree_new (const char *name,
47 const DBusObjectPathVTable *vtable,
49 static DBusObjectSubtree* _dbus_object_subtree_ref (DBusObjectSubtree *subtree);
50 static void _dbus_object_subtree_unref (DBusObjectSubtree *subtree);
53 * Internals of DBusObjectTree
57 int refcount; /**< Reference count */
58 DBusConnection *connection; /**< Connection this tree belongs to */
60 DBusObjectSubtree *root; /**< Root of the tree ("/" node) */
64 * Struct representing a single registered subtree handler, or node
65 * that's a parent of a registered subtree handler. If
66 * message_function != NULL there's actually a handler at this node.
68 struct DBusObjectSubtree
70 DBusAtomic refcount; /**< Reference count */
71 DBusObjectSubtree *parent; /**< Parent node */
72 DBusObjectPathUnregisterFunction unregister_function; /**< Function to call on unregister */
73 DBusObjectPathMessageFunction message_function; /**< Function to handle messages */
74 void *user_data; /**< Data for functions */
75 DBusObjectSubtree **subtrees; /**< Child nodes */
76 int n_subtrees; /**< Number of child nodes */
77 unsigned int subtrees_sorted : 1; /**< Whether children are sorted */
78 unsigned int invoke_as_fallback : 1; /**< Whether to invoke message_function when child nodes don't handle the message */
79 char name[1]; /**< Allocated as large as necessary */
83 * Creates a new object tree, representing a mapping from paths
86 * @param connection the connection this tree belongs to
87 * @returns the new tree or #NULL if no memory
90 _dbus_object_tree_new (DBusConnection *connection)
94 /* the connection passed in here isn't fully constructed,
95 * so don't do anything more than store a pointer to
99 tree = dbus_new0 (DBusObjectTree, 1);
104 tree->connection = connection;
105 tree->root = _dbus_object_subtree_new ("/", NULL, NULL);
106 if (tree->root == NULL)
108 tree->root->invoke_as_fallback = TRUE;
122 * Increment the reference count
123 * @param tree the object tree
124 * @returns the object tree
127 _dbus_object_tree_ref (DBusObjectTree *tree)
129 _dbus_assert (tree->refcount > 0);
137 * Decrement the reference count
138 * @param tree the object tree
141 _dbus_object_tree_unref (DBusObjectTree *tree)
143 _dbus_assert (tree->refcount > 0);
147 if (tree->refcount == 0)
149 _dbus_object_tree_free_all_unlocked (tree);
156 subtree_cmp (DBusObjectSubtree *subtree_a,
157 DBusObjectSubtree *subtree_b)
159 return strcmp (subtree_a->name, subtree_b->name);
163 subtree_qsort_cmp (const void *a,
166 DBusObjectSubtree **subtree_a_p = (void*) a;
167 DBusObjectSubtree **subtree_b_p = (void*) b;
169 return subtree_cmp (*subtree_a_p, *subtree_b_p);
173 ensure_sorted (DBusObjectSubtree *subtree)
175 if (subtree->subtrees && !subtree->subtrees_sorted)
177 qsort (subtree->subtrees,
179 sizeof (DBusObjectSubtree*),
181 subtree->subtrees_sorted = TRUE;
185 /** Set to 1 to get a bunch of debug spew about finding the
188 #define VERBOSE_FIND 0
190 static DBusObjectSubtree*
191 find_subtree_recurse (DBusObjectSubtree *subtree,
193 dbus_bool_t create_if_not_found,
194 int *index_in_parent,
195 dbus_bool_t *exact_match)
198 dbus_bool_t return_deepest_match;
200 return_deepest_match = exact_match != NULL;
202 _dbus_assert (!(return_deepest_match && create_if_not_found));
207 _dbus_verbose (" path exhausted, returning %s\n",
210 if (exact_match != NULL)
216 _dbus_verbose (" searching children of %s for %s\n",
217 subtree->name, path[0]);
220 ensure_sorted (subtree);
222 /* FIXME we should do a binary search here instead
227 while (i < subtree->n_subtrees)
231 v = strcmp (path[0], subtree->subtrees[i]->name);
234 _dbus_verbose (" %s cmp %s = %d\n",
235 path[0], subtree->subtrees[i]->name,
244 _dbus_verbose (" storing parent index %d\n", i);
246 *index_in_parent = i;
249 if (return_deepest_match)
251 DBusObjectSubtree *next;
253 next = find_subtree_recurse (subtree->subtrees[i],
254 &path[1], create_if_not_found,
255 index_in_parent, exact_match);
257 subtree->invoke_as_fallback)
260 _dbus_verbose (" no deeper match found, returning %s\n",
263 if (exact_match != NULL)
264 *exact_match = FALSE;
271 return find_subtree_recurse (subtree->subtrees[i],
272 &path[1], create_if_not_found,
273 index_in_parent, exact_match);
285 _dbus_verbose (" no match found, current tree %s, create_if_not_found = %d\n",
286 subtree->name, create_if_not_found);
289 if (create_if_not_found)
291 DBusObjectSubtree* child;
292 DBusObjectSubtree **new_subtrees;
296 _dbus_verbose (" creating subtree %s\n",
300 child = _dbus_object_subtree_new (path[0],
305 /* FIXME we should do the "double alloc each time" standard thing */
306 new_n_subtrees = subtree->n_subtrees + 1;
307 new_subtrees = dbus_realloc (subtree->subtrees,
308 new_n_subtrees * sizeof (DBusObjectSubtree*));
309 if (new_subtrees == NULL)
311 child->unregister_function = NULL;
312 child->message_function = NULL;
313 _dbus_object_subtree_unref (child);
317 new_subtrees[subtree->n_subtrees] = child;
319 *index_in_parent = subtree->n_subtrees;
320 subtree->subtrees_sorted = FALSE;
321 subtree->n_subtrees = new_n_subtrees;
322 subtree->subtrees = new_subtrees;
324 child->parent = subtree;
326 return find_subtree_recurse (child,
327 &path[1], create_if_not_found,
328 index_in_parent, exact_match);
332 if (exact_match != NULL)
333 *exact_match = FALSE;
334 return (return_deepest_match && subtree->invoke_as_fallback) ? subtree : NULL;
338 static DBusObjectSubtree*
339 find_subtree (DBusObjectTree *tree,
341 int *index_in_parent)
343 DBusObjectSubtree *subtree;
346 _dbus_verbose ("Looking for exact registered subtree\n");
349 subtree = find_subtree_recurse (tree->root, path, FALSE, index_in_parent, NULL);
351 if (subtree && subtree->message_function == NULL)
357 static DBusObjectSubtree*
358 lookup_subtree (DBusObjectTree *tree,
362 _dbus_verbose ("Looking for subtree\n");
364 return find_subtree_recurse (tree->root, path, FALSE, NULL, NULL);
367 static DBusObjectSubtree*
368 find_handler (DBusObjectTree *tree,
370 dbus_bool_t *exact_match)
373 _dbus_verbose ("Looking for deepest handler\n");
375 _dbus_assert (exact_match != NULL);
376 return find_subtree_recurse (tree->root, path, FALSE, NULL, exact_match);
379 static DBusObjectSubtree*
380 ensure_subtree (DBusObjectTree *tree,
384 _dbus_verbose ("Ensuring subtree\n");
386 return find_subtree_recurse (tree->root, path, TRUE, NULL, NULL);
390 * Registers a new subtree in the global object tree.
392 * @param tree the global object tree
393 * @param fallback #TRUE to handle messages to children of this path
394 * @param path NULL-terminated array of path elements giving path to subtree
395 * @param vtable the vtable used to traverse this subtree
396 * @param user_data user data to pass to methods in the vtable
397 * @returns #FALSE if not enough memory
400 _dbus_object_tree_register (DBusObjectTree *tree,
401 dbus_bool_t fallback,
403 const DBusObjectPathVTable *vtable,
406 DBusObjectSubtree *subtree;
408 _dbus_assert (tree != NULL);
409 _dbus_assert (vtable->message_function != NULL);
410 _dbus_assert (path != NULL);
412 subtree = ensure_subtree (tree, path);
416 #ifndef DBUS_DISABLE_CHECKS
417 if (subtree->message_function != NULL)
419 _dbus_warn ("A handler is already registered for the path starting with path[0] = \"%s\"\n",
420 path[0] ? path[0] : "null");
424 _dbus_assert (subtree->message_function == NULL);
427 subtree->message_function = vtable->message_function;
428 subtree->unregister_function = vtable->unregister_function;
429 subtree->user_data = user_data;
430 subtree->invoke_as_fallback = fallback != FALSE;
436 * Unregisters an object subtree that was registered with the
439 * @param tree the global object tree
440 * @param path path to the subtree (same as the one passed to _dbus_object_tree_register())
443 _dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
447 DBusObjectSubtree *subtree;
448 DBusObjectPathUnregisterFunction unregister_function;
450 DBusConnection *connection;
452 _dbus_assert (path != NULL);
454 subtree = find_subtree (tree, path, &i);
456 #ifndef DBUS_DISABLE_CHECKS
459 _dbus_warn ("Attempted to unregister path (path[0] = %s path[1] = %s) which isn't registered\n",
460 path[0] ? path[0] : "null",
461 path[1] ? path[1] : "null");
465 _dbus_assert (subtree != NULL);
468 _dbus_assert (subtree->parent == NULL ||
469 (i >= 0 && subtree->parent->subtrees[i] == subtree));
471 subtree->message_function = NULL;
473 unregister_function = subtree->unregister_function;
474 user_data = subtree->user_data;
476 subtree->unregister_function = NULL;
477 subtree->user_data = NULL;
479 /* If we have no subtrees of our own, remove from
480 * our parent (FIXME could also be more aggressive
481 * and remove our parent if it becomes empty)
483 if (subtree->parent && subtree->n_subtrees == 0)
485 /* assumes a 0-byte memmove is OK */
486 memmove (&subtree->parent->subtrees[i],
487 &subtree->parent->subtrees[i+1],
488 (subtree->parent->n_subtrees - i - 1) *
489 sizeof (subtree->parent->subtrees[0]));
490 subtree->parent->n_subtrees -= 1;
492 subtree->parent = NULL;
494 _dbus_object_subtree_unref (subtree);
498 connection = tree->connection;
500 /* Unlock and call application code */
501 #ifdef DBUS_BUILD_TESTS
505 _dbus_connection_ref_unlocked (connection);
506 _dbus_connection_unlock (connection);
509 if (unregister_function)
510 (* unregister_function) (connection, user_data);
512 #ifdef DBUS_BUILD_TESTS
515 dbus_connection_unref (connection);
519 free_subtree_recurse (DBusConnection *connection,
520 DBusObjectSubtree *subtree)
522 /* Delete them from the end, for slightly
523 * more robustness against odd reentrancy.
525 while (subtree->n_subtrees > 0)
527 DBusObjectSubtree *child;
529 child = subtree->subtrees[subtree->n_subtrees - 1];
530 subtree->subtrees[subtree->n_subtrees - 1] = NULL;
531 subtree->n_subtrees -= 1;
532 child->parent = NULL;
534 free_subtree_recurse (connection, child);
537 /* Call application code */
538 if (subtree->unregister_function)
539 (* subtree->unregister_function) (connection,
542 subtree->message_function = NULL;
543 subtree->unregister_function = NULL;
544 subtree->user_data = NULL;
546 /* Now free ourselves */
547 _dbus_object_subtree_unref (subtree);
551 * Free all the handlers in the tree. Lock on tree's connection
554 * @param tree the object tree
557 _dbus_object_tree_free_all_unlocked (DBusObjectTree *tree)
560 free_subtree_recurse (tree->connection,
566 _dbus_object_tree_list_registered_unlocked (DBusObjectTree *tree,
567 const char **parent_path,
568 char ***child_entries)
570 DBusObjectSubtree *subtree;
573 _dbus_assert (parent_path != NULL);
574 _dbus_assert (child_entries != NULL);
576 *child_entries = NULL;
578 subtree = lookup_subtree (tree, parent_path);
581 retval = dbus_new0 (char *, 1);
586 retval = dbus_new0 (char*, subtree->n_subtrees + 1);
590 while (i < subtree->n_subtrees)
592 retval[i] = _dbus_strdup (subtree->subtrees[i]->name);
593 if (retval[i] == NULL)
595 dbus_free_string_array (retval);
605 *child_entries = retval;
606 return retval != NULL;
609 static DBusHandlerResult
610 handle_default_introspect_and_unlock (DBusObjectTree *tree,
611 DBusMessage *message,
615 DBusHandlerResult result;
619 DBusMessageIter iter;
620 const char *v_STRING;
621 dbus_bool_t already_unlocked;
623 /* We have the connection lock here */
625 already_unlocked = FALSE;
627 _dbus_verbose (" considering default Introspect() handler...\n");
631 if (!dbus_message_is_method_call (message,
632 DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE,
635 #ifdef DBUS_BUILD_TESTS
636 if (tree->connection)
638 _dbus_connection_unlock (tree->connection);
640 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
643 _dbus_verbose (" using default Introspect() handler!\n");
645 if (!_dbus_string_init (&xml))
647 #ifdef DBUS_BUILD_TESTS
648 if (tree->connection)
650 _dbus_connection_unlock (tree->connection);
652 return DBUS_HANDLER_RESULT_NEED_MEMORY;
655 result = DBUS_HANDLER_RESULT_NEED_MEMORY;
658 if (!_dbus_object_tree_list_registered_unlocked (tree, path, &children))
661 if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
664 if (!_dbus_string_append (&xml, "<node>\n"))
668 while (children[i] != NULL)
670 if (!_dbus_string_append_printf (&xml, " <node name=\"%s\"/>\n",
677 if (!_dbus_string_append (&xml, "</node>\n"))
680 reply = dbus_message_new_method_return (message);
684 dbus_message_iter_init_append (reply, &iter);
685 v_STRING = _dbus_string_get_const_data (&xml);
686 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &v_STRING))
689 #ifdef DBUS_BUILD_TESTS
690 if (tree->connection)
693 if (!_dbus_connection_send_and_unlock (tree->connection, reply, NULL))
697 result = DBUS_HANDLER_RESULT_HANDLED;
700 #ifdef DBUS_BUILD_TESTS
701 if (tree->connection)
704 if (!already_unlocked)
705 _dbus_connection_unlock (tree->connection);
708 _dbus_string_free (&xml);
709 dbus_free_string_array (children);
711 dbus_message_unref (reply);
717 * Tries to dispatch a message by directing it to handler for the
718 * object path listed in the message header, if any. Messages are
719 * dispatched first to the registered handler that matches the largest
720 * number of path elements; that is, message to /foo/bar/baz would go
721 * to the handler for /foo/bar before the one for /foo.
723 * @todo thread problems
725 * @param tree the global object tree
726 * @param message the message to dispatch
727 * @returns whether message was handled successfully
730 _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
731 DBusMessage *message)
734 dbus_bool_t exact_match;
737 DBusHandlerResult result;
738 DBusObjectSubtree *subtree;
741 _dbus_verbose ("Dispatch of message by object path\n");
745 if (!dbus_message_get_path_decomposed (message, &path))
747 #ifdef DBUS_BUILD_TESTS
748 if (tree->connection)
750 _dbus_connection_unlock (tree->connection);
752 _dbus_verbose ("No memory to get decomposed path\n");
754 return DBUS_HANDLER_RESULT_NEED_MEMORY;
759 #ifdef DBUS_BUILD_TESTS
760 if (tree->connection)
762 _dbus_connection_unlock (tree->connection);
764 _dbus_verbose ("No path field in message\n");
765 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
768 /* Find the deepest path that covers the path in the message */
769 subtree = find_handler (tree, (const char**) path, &exact_match);
771 /* Build a list of all paths that cover the path in the message */
775 while (subtree != NULL)
777 if (subtree->message_function != NULL && (exact_match || subtree->invoke_as_fallback))
779 _dbus_object_subtree_ref (subtree);
781 /* run deepest paths first */
782 if (!_dbus_list_append (&list, subtree))
784 result = DBUS_HANDLER_RESULT_NEED_MEMORY;
785 _dbus_object_subtree_unref (subtree);
786 goto free_and_return;
791 subtree = subtree->parent;
794 _dbus_verbose ("%d handlers in the path tree for this message\n",
795 _dbus_list_get_length (&list));
797 /* Invoke each handler in the list */
799 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
801 link = _dbus_list_get_first_link (&list);
804 DBusList *next = _dbus_list_get_next_link (&list, link);
805 subtree = link->data;
807 /* message_function is NULL if we're unregistered
810 if (subtree->message_function)
812 DBusObjectPathMessageFunction message_function;
815 message_function = subtree->message_function;
816 user_data = subtree->user_data;
819 _dbus_verbose (" (invoking a handler)\n");
822 #ifdef DBUS_BUILD_TESTS
823 if (tree->connection)
825 _dbus_connection_unlock (tree->connection);
827 /* FIXME you could unregister the subtree in another thread
828 * before we invoke the callback, and I can't figure out a
829 * good way to solve this.
832 result = (* message_function) (tree->connection,
836 #ifdef DBUS_BUILD_TESTS
837 if (tree->connection)
839 _dbus_connection_lock (tree->connection);
841 if (result != DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
842 goto free_and_return;
850 if (result == DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
852 /* This hardcoded default handler does a minimal Introspect()
854 result = handle_default_introspect_and_unlock (tree, message,
855 (const char**) path);
859 #ifdef DBUS_BUILD_TESTS
860 if (tree->connection)
862 _dbus_connection_unlock (tree->connection);
867 link = _dbus_list_get_first_link (&list);
868 _dbus_object_subtree_unref (link->data);
869 _dbus_list_remove_link (&list, link);
872 dbus_free_string_array (path);
878 * Allocates a subtree object.
880 * @param name name to duplicate.
881 * @returns newly-allocated subtree
883 static DBusObjectSubtree*
884 allocate_subtree_object (const char *name)
887 DBusObjectSubtree *subtree;
888 const size_t front_padding = _DBUS_STRUCT_OFFSET (DBusObjectSubtree, name);
890 _dbus_assert (name != NULL);
894 subtree = dbus_malloc (front_padding + (len + 1));
899 memcpy (subtree->name, name, len + 1);
904 static DBusObjectSubtree*
905 _dbus_object_subtree_new (const char *name,
906 const DBusObjectPathVTable *vtable,
909 DBusObjectSubtree *subtree;
911 subtree = allocate_subtree_object (name);
915 _dbus_assert (name != NULL);
917 subtree->parent = NULL;
921 subtree->message_function = vtable->message_function;
922 subtree->unregister_function = vtable->unregister_function;
926 subtree->message_function = NULL;
927 subtree->unregister_function = NULL;
930 subtree->user_data = user_data;
931 subtree->refcount.value = 1;
932 subtree->subtrees = NULL;
933 subtree->n_subtrees = 0;
934 subtree->subtrees_sorted = TRUE;
935 subtree->invoke_as_fallback = FALSE;
948 static DBusObjectSubtree *
949 _dbus_object_subtree_ref (DBusObjectSubtree *subtree)
951 _dbus_assert (subtree->refcount.value > 0);
952 _dbus_atomic_inc (&subtree->refcount);
958 _dbus_object_subtree_unref (DBusObjectSubtree *subtree)
960 _dbus_assert (subtree->refcount.value > 0);
962 if (_dbus_atomic_dec (&subtree->refcount) == 1)
964 _dbus_assert (subtree->unregister_function == NULL);
965 _dbus_assert (subtree->message_function == NULL);
967 dbus_free (subtree->subtrees);
973 * Lists the registered fallback handlers and object path handlers at
974 * the given parent_path. The returned array should be freed with
975 * dbus_free_string_array().
977 * @param tree the object tree
978 * @param parent_path the path to list the child handlers of
979 * @param child_entries returns #NULL-terminated array of children
980 * @returns #FALSE if no memory to allocate the child entries
983 _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
984 const char **parent_path,
985 char ***child_entries)
989 result = _dbus_object_tree_list_registered_unlocked (tree,
993 #ifdef DBUS_BUILD_TESTS
994 if (tree->connection)
996 _dbus_connection_unlock (tree->connection);
1002 /** Set to 1 to get a bunch of spew about disassembling the path string */
1003 #define VERBOSE_DECOMPOSE 0
1006 * Decompose an object path. A path of just "/" is
1007 * represented as an empty vector of strings.
1008 * The path need not be nul terminated.
1010 * @param data the path data
1011 * @param len the length of the path string
1012 * @param path address to store new object path
1013 * @param path_len length of stored path
1016 _dbus_decompose_path (const char* data,
1025 _dbus_assert (data != NULL);
1027 #if VERBOSE_DECOMPOSE
1028 _dbus_verbose ("Decomposing path \"%s\"\n",
1033 if (len > 1) /* if path is not just "/" */
1044 retval = dbus_new0 (char*, n_components + 1);
1050 if (n_components == 0)
1054 while (comp < n_components)
1056 _dbus_assert (i < len);
1062 while (j < len && data[j] != '/')
1065 /* Now [i, j) is the path component */
1066 _dbus_assert (i < j);
1067 _dbus_assert (data[i] != '/');
1068 _dbus_assert (j == len || data[j] == '/');
1070 #if VERBOSE_DECOMPOSE
1071 _dbus_verbose (" (component in [%d,%d))\n",
1075 retval[comp] = _dbus_memdup (&data[i], j - i + 1);
1076 if (retval[comp] == NULL)
1078 dbus_free_string_array (retval);
1081 retval[comp][j-i] = '\0';
1082 #if VERBOSE_DECOMPOSE
1083 _dbus_verbose (" (component %d = \"%s\")\n",
1084 comp, retval[comp]);
1090 _dbus_assert (i == len);
1094 *path_len = n_components;
1101 #ifdef DBUS_BUILD_TESTS
1102 #include "dbus-test.h"
1106 flatten_path (const char **path)
1111 if (!_dbus_string_init (&str))
1114 if (path[0] == NULL)
1116 if (!_dbus_string_append_byte (&str, '/'))
1126 if (!_dbus_string_append_byte (&str, '/'))
1129 if (!_dbus_string_append (&str, path[i]))
1136 if (!_dbus_string_steal_data (&str, &s))
1139 _dbus_string_free (&str);
1144 _dbus_string_free (&str);
1156 /* Returns TRUE if container is a parent of child
1158 static StrComparison
1159 path_contains (const char **container,
1165 while (child[i] != NULL)
1169 if (container[i] == NULL)
1170 return STR_PREFIX; /* container ran out, child continues;
1171 * thus the container is a parent of the
1175 _dbus_assert (container[i] != NULL);
1176 _dbus_assert (child[i] != NULL);
1178 v = strcmp (container[i], child[i]);
1181 return STR_DIFFERENT; /* they overlap until here and then are different,
1188 /* Child ran out; if container also did, they are equal;
1189 * otherwise, the child is a parent of the container.
1191 if (container[i] == NULL)
1194 return STR_DIFFERENT;
1199 spew_subtree_recurse (DBusObjectSubtree *subtree,
1207 _dbus_verbose (" ");
1211 _dbus_verbose ("%s (%d children)\n",
1212 subtree->name, subtree->n_subtrees);
1215 while (i < subtree->n_subtrees)
1217 spew_subtree_recurse (subtree->subtrees[i], indent + 2);
1224 spew_tree (DBusObjectTree *tree)
1226 spew_subtree_recurse (tree->root, 0);
1231 * Callback data used in tests
1235 const char **path; /**< Path */
1236 dbus_bool_t handler_fallback; /**< true if the handler may be called as fallback */
1237 dbus_bool_t message_handled; /**< Gets set to true if message handler called */
1238 dbus_bool_t handler_unregistered; /**< gets set to true if handler is unregistered */
1243 test_unregister_function (DBusConnection *connection,
1246 TreeTestData *ttd = user_data;
1248 ttd->handler_unregistered = TRUE;
1251 static DBusHandlerResult
1252 test_message_function (DBusConnection *connection,
1253 DBusMessage *message,
1256 TreeTestData *ttd = user_data;
1258 ttd->message_handled = TRUE;
1260 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1264 do_register (DBusObjectTree *tree,
1266 dbus_bool_t fallback,
1268 TreeTestData *tree_test_data)
1270 DBusObjectPathVTable vtable = { test_unregister_function,
1271 test_message_function, NULL };
1273 tree_test_data[i].message_handled = FALSE;
1274 tree_test_data[i].handler_unregistered = FALSE;
1275 tree_test_data[i].handler_fallback = fallback;
1276 tree_test_data[i].path = path;
1278 if (!_dbus_object_tree_register (tree, fallback, path,
1280 &tree_test_data[i]))
1287 do_test_dispatch (DBusObjectTree *tree,
1290 TreeTestData *tree_test_data,
1293 DBusMessage *message;
1295 DBusHandlerResult result;
1300 flat = flatten_path (path);
1304 message = dbus_message_new_method_call (NULL,
1306 "org.freedesktop.TestInterface",
1309 if (message == NULL)
1313 while (j < n_test_data)
1315 tree_test_data[j].message_handled = FALSE;
1319 result = _dbus_object_tree_dispatch_and_unlock (tree, message);
1320 if (result == DBUS_HANDLER_RESULT_NEED_MEMORY)
1323 _dbus_assert (tree_test_data[i].message_handled);
1326 while (j < n_test_data)
1328 if (tree_test_data[j].message_handled)
1330 if (tree_test_data[j].handler_fallback)
1331 _dbus_assert (path_contains (tree_test_data[j].path,
1332 path) != STR_DIFFERENT);
1334 _dbus_assert (path_contains (tree_test_data[j].path, path) == STR_EQUAL);
1338 if (tree_test_data[j].handler_fallback)
1339 _dbus_assert (path_contains (tree_test_data[j].path,
1340 path) == STR_DIFFERENT);
1342 _dbus_assert (path_contains (tree_test_data[j].path, path) != STR_EQUAL);
1348 dbus_message_unref (message);
1354 dbus_message_unref (message);
1359 string_array_length (const char **array)
1362 for (i = 0; array[i]; i++) ;
1369 const char *result[20];
1370 } DecomposePathTest;
1372 static DecomposePathTest decompose_tests[] = {
1373 { "/foo", { "foo", NULL } },
1374 { "/foo/bar", { "foo", "bar", NULL } },
1376 { "/a/b", { "a", "b", NULL } },
1377 { "/a/b/c", { "a", "b", "c", NULL } },
1378 { "/a/b/c/d", { "a", "b", "c", "d", NULL } },
1379 { "/foo/bar/q", { "foo", "bar", "q", NULL } },
1380 { "/foo/bar/this/is/longer", { "foo", "bar", "this", "is", "longer", NULL } }
1384 run_decompose_tests (void)
1389 while (i < _DBUS_N_ELEMENTS (decompose_tests))
1395 if (!_dbus_decompose_path (decompose_tests[i].path,
1396 strlen (decompose_tests[i].path),
1397 &result, &result_len))
1400 expected_len = string_array_length (decompose_tests[i].result);
1402 if (result_len != (int) string_array_length ((const char**)result) ||
1403 expected_len != result_len ||
1404 path_contains (decompose_tests[i].result,
1405 (const char**) result) != STR_EQUAL)
1407 int real_len = string_array_length ((const char**)result);
1408 _dbus_warn ("Expected decompose of %s to have len %d, returned %d, appears to have %d\n",
1409 decompose_tests[i].path, expected_len, result_len,
1411 _dbus_warn ("Decompose resulted in elements: { ");
1413 while (i < real_len)
1415 _dbus_warn ("\"%s\"%s", result[i],
1416 (i + 1) == real_len ? "" : ", ");
1420 _dbus_assert_not_reached ("path decompose failed\n");
1423 dbus_free_string_array (result);
1432 object_tree_test_iteration (void *data)
1434 const char *path0[] = { NULL };
1435 const char *path1[] = { "foo", NULL };
1436 const char *path2[] = { "foo", "bar", NULL };
1437 const char *path3[] = { "foo", "bar", "baz", NULL };
1438 const char *path4[] = { "foo", "bar", "boo", NULL };
1439 const char *path5[] = { "blah", NULL };
1440 const char *path6[] = { "blah", "boof", NULL };
1441 const char *path7[] = { "blah", "boof", "this", "is", "really", "long", NULL };
1442 const char *path8[] = { "childless", NULL };
1443 DBusObjectTree *tree;
1444 TreeTestData tree_test_data[9];
1446 dbus_bool_t exact_match;
1448 if (!run_decompose_tests ())
1453 tree = _dbus_object_tree_new (NULL);
1457 if (!do_register (tree, path0, TRUE, 0, tree_test_data))
1460 _dbus_assert (find_subtree (tree, path0, NULL));
1461 _dbus_assert (!find_subtree (tree, path1, NULL));
1462 _dbus_assert (!find_subtree (tree, path2, NULL));
1463 _dbus_assert (!find_subtree (tree, path3, NULL));
1464 _dbus_assert (!find_subtree (tree, path4, NULL));
1465 _dbus_assert (!find_subtree (tree, path5, NULL));
1466 _dbus_assert (!find_subtree (tree, path6, NULL));
1467 _dbus_assert (!find_subtree (tree, path7, NULL));
1468 _dbus_assert (!find_subtree (tree, path8, NULL));
1470 _dbus_assert (find_handler (tree, path0, &exact_match) && exact_match);
1471 _dbus_assert (find_handler (tree, path1, &exact_match) == tree->root && !exact_match);
1472 _dbus_assert (find_handler (tree, path2, &exact_match) == tree->root && !exact_match);
1473 _dbus_assert (find_handler (tree, path3, &exact_match) == tree->root && !exact_match);
1474 _dbus_assert (find_handler (tree, path4, &exact_match) == tree->root && !exact_match);
1475 _dbus_assert (find_handler (tree, path5, &exact_match) == tree->root && !exact_match);
1476 _dbus_assert (find_handler (tree, path6, &exact_match) == tree->root && !exact_match);
1477 _dbus_assert (find_handler (tree, path7, &exact_match) == tree->root && !exact_match);
1478 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->root && !exact_match);
1480 if (!do_register (tree, path1, TRUE, 1, tree_test_data))
1483 _dbus_assert (find_subtree (tree, path0, NULL));
1484 _dbus_assert (find_subtree (tree, path1, NULL));
1485 _dbus_assert (!find_subtree (tree, path2, NULL));
1486 _dbus_assert (!find_subtree (tree, path3, NULL));
1487 _dbus_assert (!find_subtree (tree, path4, NULL));
1488 _dbus_assert (!find_subtree (tree, path5, NULL));
1489 _dbus_assert (!find_subtree (tree, path6, NULL));
1490 _dbus_assert (!find_subtree (tree, path7, NULL));
1491 _dbus_assert (!find_subtree (tree, path8, NULL));
1493 _dbus_assert (find_handler (tree, path0, &exact_match) && exact_match);
1494 _dbus_assert (find_handler (tree, path1, &exact_match) && exact_match);
1495 _dbus_assert (find_handler (tree, path2, &exact_match) && !exact_match);
1496 _dbus_assert (find_handler (tree, path3, &exact_match) && !exact_match);
1497 _dbus_assert (find_handler (tree, path4, &exact_match) && !exact_match);
1498 _dbus_assert (find_handler (tree, path5, &exact_match) == tree->root && !exact_match);
1499 _dbus_assert (find_handler (tree, path6, &exact_match) == tree->root && !exact_match);
1500 _dbus_assert (find_handler (tree, path7, &exact_match) == tree->root && !exact_match);
1501 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->root && !exact_match);
1503 if (!do_register (tree, path2, TRUE, 2, tree_test_data))
1506 _dbus_assert (find_subtree (tree, path1, NULL));
1507 _dbus_assert (find_subtree (tree, path2, NULL));
1508 _dbus_assert (!find_subtree (tree, path3, NULL));
1509 _dbus_assert (!find_subtree (tree, path4, NULL));
1510 _dbus_assert (!find_subtree (tree, path5, NULL));
1511 _dbus_assert (!find_subtree (tree, path6, NULL));
1512 _dbus_assert (!find_subtree (tree, path7, NULL));
1513 _dbus_assert (!find_subtree (tree, path8, NULL));
1515 if (!do_register (tree, path3, TRUE, 3, tree_test_data))
1518 _dbus_assert (find_subtree (tree, path0, NULL));
1519 _dbus_assert (find_subtree (tree, path1, NULL));
1520 _dbus_assert (find_subtree (tree, path2, NULL));
1521 _dbus_assert (find_subtree (tree, path3, NULL));
1522 _dbus_assert (!find_subtree (tree, path4, NULL));
1523 _dbus_assert (!find_subtree (tree, path5, NULL));
1524 _dbus_assert (!find_subtree (tree, path6, NULL));
1525 _dbus_assert (!find_subtree (tree, path7, NULL));
1526 _dbus_assert (!find_subtree (tree, path8, NULL));
1528 if (!do_register (tree, path4, TRUE, 4, tree_test_data))
1531 _dbus_assert (find_subtree (tree, path0, NULL));
1532 _dbus_assert (find_subtree (tree, path1, NULL));
1533 _dbus_assert (find_subtree (tree, path2, NULL));
1534 _dbus_assert (find_subtree (tree, path3, NULL));
1535 _dbus_assert (find_subtree (tree, path4, NULL));
1536 _dbus_assert (!find_subtree (tree, path5, NULL));
1537 _dbus_assert (!find_subtree (tree, path6, NULL));
1538 _dbus_assert (!find_subtree (tree, path7, NULL));
1539 _dbus_assert (!find_subtree (tree, path8, NULL));
1541 if (!do_register (tree, path5, TRUE, 5, tree_test_data))
1544 _dbus_assert (find_subtree (tree, path0, NULL));
1545 _dbus_assert (find_subtree (tree, path1, NULL));
1546 _dbus_assert (find_subtree (tree, path2, NULL));
1547 _dbus_assert (find_subtree (tree, path3, NULL));
1548 _dbus_assert (find_subtree (tree, path4, NULL));
1549 _dbus_assert (find_subtree (tree, path5, NULL));
1550 _dbus_assert (!find_subtree (tree, path6, NULL));
1551 _dbus_assert (!find_subtree (tree, path7, NULL));
1552 _dbus_assert (!find_subtree (tree, path8, NULL));
1554 _dbus_assert (find_handler (tree, path0, &exact_match) == tree->root && exact_match);
1555 _dbus_assert (find_handler (tree, path1, &exact_match) != tree->root && exact_match);
1556 _dbus_assert (find_handler (tree, path2, &exact_match) != tree->root && exact_match);
1557 _dbus_assert (find_handler (tree, path3, &exact_match) != tree->root && exact_match);
1558 _dbus_assert (find_handler (tree, path4, &exact_match) != tree->root && exact_match);
1559 _dbus_assert (find_handler (tree, path5, &exact_match) != tree->root && exact_match);
1560 _dbus_assert (find_handler (tree, path6, &exact_match) != tree->root && !exact_match);
1561 _dbus_assert (find_handler (tree, path7, &exact_match) != tree->root && !exact_match);
1562 _dbus_assert (find_handler (tree, path8, &exact_match) == tree->root && !exact_match);
1564 if (!do_register (tree, path6, TRUE, 6, tree_test_data))
1567 _dbus_assert (find_subtree (tree, path0, NULL));
1568 _dbus_assert (find_subtree (tree, path1, NULL));
1569 _dbus_assert (find_subtree (tree, path2, NULL));
1570 _dbus_assert (find_subtree (tree, path3, NULL));
1571 _dbus_assert (find_subtree (tree, path4, NULL));
1572 _dbus_assert (find_subtree (tree, path5, NULL));
1573 _dbus_assert (find_subtree (tree, path6, NULL));
1574 _dbus_assert (!find_subtree (tree, path7, NULL));
1575 _dbus_assert (!find_subtree (tree, path8, NULL));
1577 if (!do_register (tree, path7, TRUE, 7, tree_test_data))
1580 _dbus_assert (find_subtree (tree, path0, NULL));
1581 _dbus_assert (find_subtree (tree, path1, NULL));
1582 _dbus_assert (find_subtree (tree, path2, NULL));
1583 _dbus_assert (find_subtree (tree, path3, NULL));
1584 _dbus_assert (find_subtree (tree, path4, NULL));
1585 _dbus_assert (find_subtree (tree, path5, NULL));
1586 _dbus_assert (find_subtree (tree, path6, NULL));
1587 _dbus_assert (find_subtree (tree, path7, NULL));
1588 _dbus_assert (!find_subtree (tree, path8, NULL));
1590 if (!do_register (tree, path8, TRUE, 8, tree_test_data))
1593 _dbus_assert (find_subtree (tree, path0, NULL));
1594 _dbus_assert (find_subtree (tree, path1, NULL));
1595 _dbus_assert (find_subtree (tree, path2, NULL));
1596 _dbus_assert (find_subtree (tree, path3, NULL));
1597 _dbus_assert (find_subtree (tree, path4, NULL));
1598 _dbus_assert (find_subtree (tree, path5, NULL));
1599 _dbus_assert (find_subtree (tree, path6, NULL));
1600 _dbus_assert (find_subtree (tree, path7, NULL));
1601 _dbus_assert (find_subtree (tree, path8, NULL));
1603 _dbus_assert (find_handler (tree, path0, &exact_match) == tree->root && exact_match);
1604 _dbus_assert (find_handler (tree, path1, &exact_match) != tree->root && exact_match);
1605 _dbus_assert (find_handler (tree, path2, &exact_match) != tree->root && exact_match);
1606 _dbus_assert (find_handler (tree, path3, &exact_match) != tree->root && exact_match);
1607 _dbus_assert (find_handler (tree, path4, &exact_match) != tree->root && exact_match);
1608 _dbus_assert (find_handler (tree, path5, &exact_match) != tree->root && exact_match);
1609 _dbus_assert (find_handler (tree, path6, &exact_match) != tree->root && exact_match);
1610 _dbus_assert (find_handler (tree, path7, &exact_match) != tree->root && exact_match);
1611 _dbus_assert (find_handler (tree, path8, &exact_match) != tree->root && exact_match);
1613 /* test the list_registered function */
1616 const char *root[] = { NULL };
1617 char **child_entries;
1620 _dbus_object_tree_list_registered_unlocked (tree, path1, &child_entries);
1621 if (child_entries != NULL)
1623 nb = string_array_length ((const char**)child_entries);
1624 _dbus_assert (nb == 1);
1625 dbus_free_string_array (child_entries);
1628 _dbus_object_tree_list_registered_unlocked (tree, path2, &child_entries);
1629 if (child_entries != NULL)
1631 nb = string_array_length ((const char**)child_entries);
1632 _dbus_assert (nb == 2);
1633 dbus_free_string_array (child_entries);
1636 _dbus_object_tree_list_registered_unlocked (tree, path8, &child_entries);
1637 if (child_entries != NULL)
1639 nb = string_array_length ((const char**)child_entries);
1640 _dbus_assert (nb == 0);
1641 dbus_free_string_array (child_entries);
1644 _dbus_object_tree_list_registered_unlocked (tree, root, &child_entries);
1645 if (child_entries != NULL)
1647 nb = string_array_length ((const char**)child_entries);
1648 _dbus_assert (nb == 3);
1649 dbus_free_string_array (child_entries);
1653 /* Check that destroying tree calls unregister funcs */
1654 _dbus_object_tree_unref (tree);
1657 while (i < (int) _DBUS_N_ELEMENTS (tree_test_data))
1659 _dbus_assert (tree_test_data[i].handler_unregistered);
1660 _dbus_assert (!tree_test_data[i].message_handled);
1664 /* Now start again and try the individual unregister function */
1665 tree = _dbus_object_tree_new (NULL);
1669 if (!do_register (tree, path0, TRUE, 0, tree_test_data))
1671 if (!do_register (tree, path1, TRUE, 1, tree_test_data))
1673 if (!do_register (tree, path2, TRUE, 2, tree_test_data))
1675 if (!do_register (tree, path3, TRUE, 3, tree_test_data))
1677 if (!do_register (tree, path4, TRUE, 4, tree_test_data))
1679 if (!do_register (tree, path5, TRUE, 5, tree_test_data))
1681 if (!do_register (tree, path6, TRUE, 6, tree_test_data))
1683 if (!do_register (tree, path7, TRUE, 7, tree_test_data))
1685 if (!do_register (tree, path8, TRUE, 8, tree_test_data))
1688 _dbus_object_tree_unregister_and_unlock (tree, path0);
1690 _dbus_assert (!find_subtree (tree, path0, NULL));
1691 _dbus_assert (find_subtree (tree, path1, NULL));
1692 _dbus_assert (find_subtree (tree, path2, NULL));
1693 _dbus_assert (find_subtree (tree, path3, NULL));
1694 _dbus_assert (find_subtree (tree, path4, NULL));
1695 _dbus_assert (find_subtree (tree, path5, NULL));
1696 _dbus_assert (find_subtree (tree, path6, NULL));
1697 _dbus_assert (find_subtree (tree, path7, NULL));
1698 _dbus_assert (find_subtree (tree, path8, NULL));
1700 _dbus_object_tree_unregister_and_unlock (tree, path1);
1702 _dbus_assert (!find_subtree (tree, path0, NULL));
1703 _dbus_assert (!find_subtree (tree, path1, NULL));
1704 _dbus_assert (find_subtree (tree, path2, NULL));
1705 _dbus_assert (find_subtree (tree, path3, NULL));
1706 _dbus_assert (find_subtree (tree, path4, NULL));
1707 _dbus_assert (find_subtree (tree, path5, NULL));
1708 _dbus_assert (find_subtree (tree, path6, NULL));
1709 _dbus_assert (find_subtree (tree, path7, NULL));
1710 _dbus_assert (find_subtree (tree, path8, NULL));
1712 _dbus_object_tree_unregister_and_unlock (tree, path2);
1714 _dbus_assert (!find_subtree (tree, path0, NULL));
1715 _dbus_assert (!find_subtree (tree, path1, NULL));
1716 _dbus_assert (!find_subtree (tree, path2, NULL));
1717 _dbus_assert (find_subtree (tree, path3, NULL));
1718 _dbus_assert (find_subtree (tree, path4, NULL));
1719 _dbus_assert (find_subtree (tree, path5, NULL));
1720 _dbus_assert (find_subtree (tree, path6, NULL));
1721 _dbus_assert (find_subtree (tree, path7, NULL));
1722 _dbus_assert (find_subtree (tree, path8, NULL));
1724 _dbus_object_tree_unregister_and_unlock (tree, path3);
1726 _dbus_assert (!find_subtree (tree, path0, NULL));
1727 _dbus_assert (!find_subtree (tree, path1, NULL));
1728 _dbus_assert (!find_subtree (tree, path2, NULL));
1729 _dbus_assert (!find_subtree (tree, path3, NULL));
1730 _dbus_assert (find_subtree (tree, path4, NULL));
1731 _dbus_assert (find_subtree (tree, path5, NULL));
1732 _dbus_assert (find_subtree (tree, path6, NULL));
1733 _dbus_assert (find_subtree (tree, path7, NULL));
1734 _dbus_assert (find_subtree (tree, path8, NULL));
1736 _dbus_object_tree_unregister_and_unlock (tree, path4);
1738 _dbus_assert (!find_subtree (tree, path0, NULL));
1739 _dbus_assert (!find_subtree (tree, path1, NULL));
1740 _dbus_assert (!find_subtree (tree, path2, NULL));
1741 _dbus_assert (!find_subtree (tree, path3, NULL));
1742 _dbus_assert (!find_subtree (tree, path4, NULL));
1743 _dbus_assert (find_subtree (tree, path5, NULL));
1744 _dbus_assert (find_subtree (tree, path6, NULL));
1745 _dbus_assert (find_subtree (tree, path7, NULL));
1746 _dbus_assert (find_subtree (tree, path8, NULL));
1748 _dbus_object_tree_unregister_and_unlock (tree, path5);
1750 _dbus_assert (!find_subtree (tree, path0, NULL));
1751 _dbus_assert (!find_subtree (tree, path1, NULL));
1752 _dbus_assert (!find_subtree (tree, path2, NULL));
1753 _dbus_assert (!find_subtree (tree, path3, NULL));
1754 _dbus_assert (!find_subtree (tree, path4, NULL));
1755 _dbus_assert (!find_subtree (tree, path5, NULL));
1756 _dbus_assert (find_subtree (tree, path6, NULL));
1757 _dbus_assert (find_subtree (tree, path7, NULL));
1758 _dbus_assert (find_subtree (tree, path8, NULL));
1760 _dbus_object_tree_unregister_and_unlock (tree, path6);
1762 _dbus_assert (!find_subtree (tree, path0, NULL));
1763 _dbus_assert (!find_subtree (tree, path1, NULL));
1764 _dbus_assert (!find_subtree (tree, path2, NULL));
1765 _dbus_assert (!find_subtree (tree, path3, NULL));
1766 _dbus_assert (!find_subtree (tree, path4, NULL));
1767 _dbus_assert (!find_subtree (tree, path5, NULL));
1768 _dbus_assert (!find_subtree (tree, path6, NULL));
1769 _dbus_assert (find_subtree (tree, path7, NULL));
1770 _dbus_assert (find_subtree (tree, path8, NULL));
1772 _dbus_object_tree_unregister_and_unlock (tree, path7);
1774 _dbus_assert (!find_subtree (tree, path0, NULL));
1775 _dbus_assert (!find_subtree (tree, path1, NULL));
1776 _dbus_assert (!find_subtree (tree, path2, NULL));
1777 _dbus_assert (!find_subtree (tree, path3, NULL));
1778 _dbus_assert (!find_subtree (tree, path4, NULL));
1779 _dbus_assert (!find_subtree (tree, path5, NULL));
1780 _dbus_assert (!find_subtree (tree, path6, NULL));
1781 _dbus_assert (!find_subtree (tree, path7, NULL));
1782 _dbus_assert (find_subtree (tree, path8, NULL));
1784 _dbus_object_tree_unregister_and_unlock (tree, path8);
1786 _dbus_assert (!find_subtree (tree, path0, NULL));
1787 _dbus_assert (!find_subtree (tree, path1, NULL));
1788 _dbus_assert (!find_subtree (tree, path2, NULL));
1789 _dbus_assert (!find_subtree (tree, path3, NULL));
1790 _dbus_assert (!find_subtree (tree, path4, NULL));
1791 _dbus_assert (!find_subtree (tree, path5, NULL));
1792 _dbus_assert (!find_subtree (tree, path6, NULL));
1793 _dbus_assert (!find_subtree (tree, path7, NULL));
1794 _dbus_assert (!find_subtree (tree, path8, NULL));
1797 while (i < (int) _DBUS_N_ELEMENTS (tree_test_data))
1799 _dbus_assert (tree_test_data[i].handler_unregistered);
1800 _dbus_assert (!tree_test_data[i].message_handled);
1804 /* Register it all again, and test dispatch */
1806 if (!do_register (tree, path0, TRUE, 0, tree_test_data))
1808 if (!do_register (tree, path1, FALSE, 1, tree_test_data))
1810 if (!do_register (tree, path2, TRUE, 2, tree_test_data))
1812 if (!do_register (tree, path3, TRUE, 3, tree_test_data))
1814 if (!do_register (tree, path4, TRUE, 4, tree_test_data))
1816 if (!do_register (tree, path5, TRUE, 5, tree_test_data))
1818 if (!do_register (tree, path6, FALSE, 6, tree_test_data))
1820 if (!do_register (tree, path7, TRUE, 7, tree_test_data))
1822 if (!do_register (tree, path8, TRUE, 8, tree_test_data))
1829 if (!do_test_dispatch (tree, path0, 0, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1831 if (!do_test_dispatch (tree, path1, 1, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1833 if (!do_test_dispatch (tree, path2, 2, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1835 if (!do_test_dispatch (tree, path3, 3, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1837 if (!do_test_dispatch (tree, path4, 4, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1839 if (!do_test_dispatch (tree, path5, 5, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1841 if (!do_test_dispatch (tree, path6, 6, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1843 if (!do_test_dispatch (tree, path7, 7, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1845 if (!do_test_dispatch (tree, path8, 8, tree_test_data, _DBUS_N_ELEMENTS (tree_test_data)))
1852 _dbus_object_tree_ref (tree);
1853 _dbus_object_tree_unref (tree);
1854 _dbus_object_tree_unref (tree);
1861 * @ingroup DBusObjectTree
1862 * Unit test for DBusObjectTree
1863 * @returns #TRUE on success.
1866 _dbus_object_tree_test (void)
1868 _dbus_test_oom_handling ("object tree",
1869 object_tree_test_iteration,
1875 #endif /* DBUS_BUILD_TESTS */