summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-26 13:16:13 +1000
committerChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-26 13:16:13 +1000
commit638b96f1009247e24d550b51ace7950ea90bd4b3 (patch)
treec5c0faaf0ef5719096d30c199dd539f6b4b9e089
parentf952189170ba78df51206a2184dc032af0db8dc3 (diff)
downloadradial-switcher-638b96f1009247e24d550b51ace7950ea90bd4b3.tar.gz
radial-switcher-638b96f1009247e24d550b51ace7950ea90bd4b3.tar.bz2
Write, and make work, a unittest for making a tree with grouped windows
-rw-r--r--src/switcher-util.c22
-rw-r--r--tests/check_switcher-util.c24
2 files changed, 45 insertions, 1 deletions
diff --git a/src/switcher-util.c b/src/switcher-util.c
index 88f8770..b599995 100644
--- a/src/switcher-util.c
+++ b/src/switcher-util.c
@@ -91,6 +91,7 @@ newWindowTree (void)
ret->windows = newWindowList();
ret->childrenSize = 4;
ret->children = malloc (sizeof (WindowTree *) * 4);
+ memset(ret->children, NULL, sizeof (WindowTree *) * 4);
return ret;
}
@@ -123,6 +124,27 @@ addWindowToTree (WindowTree *node,
CompWindow *w,
WindowCmpProc isSameGroup)
{
+ for (int i = 0; i < node->windows->nWindows; ++i)
+ {
+ if ((*isSameGroup) (node->windows->w[i], w))
+ {
+ if (!node->children[i])
+ {
+ node->children[i] = newWindowTree ();
+ if (!node->children[i])
+ return FALSE;
+ }
+ return addWindowToTree (node->children[i], w, isSameGroup);
+ }
+ }
+ if (node->childrenSize <= node->windows->nWindows)
+ {
+ node->children = realloc (node->children, sizeof (WindowTree *) *\
+ (node->childrenSize + 32));
+ if (!node->children)
+ return FALSE;
+ node->childrenSize += 32;
+ }
return addWindowToList(node->windows, w);
}
diff --git a/tests/check_switcher-util.c b/tests/check_switcher-util.c
index 0a122a3..2716366 100644
--- a/tests/check_switcher-util.c
+++ b/tests/check_switcher-util.c
@@ -119,7 +119,28 @@ START_TEST (test_addMultipleToFlatTree)
fail_unless(tree->windows->nWindows == 500,
"Number of windows not updated correctly");
}
-END_TEST
+END_TEST
+
+START_TEST (test_addGroupedWindows)
+{
+ a = 0x5;
+ b = 0x3;
+ c = 0x3;
+
+ fail_unless (addWindowToTree (tree, a, &testCompare),
+ "addWindowToTree returned FALSE");
+ fail_unless (addWindowToTree (tree, b, &testCompare),
+ "addWindowToTree returned FALSE");
+ fail_unless (addWindowToTree (tree, c, &testCompare),
+ "addWindowToTree returned FALSE");
+
+ fail_unless (tree->windows->w[0] == a && tree->windows->w[1] == b,
+ "Top level windows failed to add properly");
+ fail_unless (tree->children[1]->windows->w[0] == c,
+ "Child window failed to add properly");
+}
+END_TEST
+
Suite *
switcher_util_suite (void)
@@ -145,6 +166,7 @@ switcher_util_suite (void)
tcase_add_checked_fixture (tc_addToTree, setup, teardown);
tcase_add_test (tc_addToTree, test_addToTree);
tcase_add_test (tc_addToTree, test_addMultipleToFlatTree);
+ tcase_add_test (tc_addToTree, test_addGroupedWindows);
suite_add_tcase (s, tc_addToTree);
return s;