summaryrefslogtreecommitdiff
path: root/test/tree2.c
diff options
context:
space:
mode:
authorAndrew Sidwell <andy@entai.co.uk>2008-07-10 10:44:04 +0000
committerAndrew Sidwell <andy@entai.co.uk>2008-07-10 10:44:04 +0000
commit4b718209bc1a27c647db1b05c9686d84c10cc742 (patch)
treed69d47d77c502967be873618f54408364377f2fc /test/tree2.c
parent2b3add00117ad5db9e0d33fd8410a86085c872b1 (diff)
downloadlibhubbub-4b718209bc1a27c647db1b05c9686d84c10cc742.tar.gz
libhubbub-4b718209bc1a27c647db1b05c9686d84c10cc742.tar.bz2
Fix the test harness' implementation of reparent_children().
svn path=/trunk/hubbub/; revision=4559
Diffstat (limited to 'test/tree2.c')
-rw-r--r--test/tree2.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/test/tree2.c b/test/tree2.c
index 4cc9322..71bd3d7 100644
--- a/test/tree2.c
+++ b/test/tree2.c
@@ -531,15 +531,36 @@ int clone_node(void *ctx, void *node, bool deep, void **result)
return 0;
}
-/* Reparent "node" to "new_parent" */
+/* Take all of the child nodes of "node" and append them to "new_parent" */
int reparent_children(void *ctx, void *node, void *new_parent)
{
- node_t *tparent = new_parent;
- node_t *tchild = node;
- void *nnode;
+ node_t *parent = new_parent;
+ node_t *old_parent = node;
- remove_child(ctx, tchild->parent, tchild, &nnode);
- append_child(ctx, tparent, tchild, &nnode);
+ node_t *insert;
+ node_t *kids;
+
+ kids = old_parent->child;
+ if (!kids) return 0;
+
+ old_parent->child = NULL;
+
+ insert = parent->child;
+ if (!insert) {
+ parent->child = kids;
+ } else {
+ while (insert->next != NULL) {
+ insert = insert->next;
+ }
+
+ insert->next = kids;
+ kids->prev = insert;
+ }
+
+ while (kids) {
+ kids->parent = parent;
+ kids = kids->next;
+ }
return 0;
}