summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-26 16:26:25 +1000
committerChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-26 16:26:25 +1000
commitb3459c74eafd8f91ab3ac4a5140eb52ec44c6aa8 (patch)
treead937c74ffd57956e5a8c7617cd25b780db9b277
parent638b96f1009247e24d550b51ace7950ea90bd4b3 (diff)
downloadradial-switcher-master.tar.gz
radial-switcher-master.tar.bz2
Test the addition of many grouped windows to a tree, and that the resulting tree structure is correctHEADmaster
-rw-r--r--src/switcher-util.c25
-rw-r--r--src/switcher-util.h2
-rw-r--r--tests/check_switcher-util.c71
3 files changed, 78 insertions, 20 deletions
diff --git a/src/switcher-util.c b/src/switcher-util.c
index b599995..ddd8b7f 100644
--- a/src/switcher-util.c
+++ b/src/switcher-util.c
@@ -26,6 +26,8 @@
**/
#include <stdlib.h>
+#include <string.h>
+
#include <compiz.h>
#include "switcher-util.h"
@@ -91,7 +93,7 @@ newWindowTree (void)
ret->windows = newWindowList();
ret->childrenSize = 4;
ret->children = malloc (sizeof (WindowTree *) * 4);
- memset(ret->children, NULL, sizeof (WindowTree *) * 4);
+ memset(ret->children, 0, sizeof (WindowTree *) * 4);
return ret;
}
@@ -122,27 +124,32 @@ destroyWindowTree (WindowTree *node)
Bool
addWindowToTree (WindowTree *node,
CompWindow *w,
- WindowCmpProc isSameGroup)
+ WindowCmpProc *isSameGroup)
{
- for (int i = 0; i < node->windows->nWindows; ++i)
+ if (*isSameGroup)
{
- if ((*isSameGroup) (node->windows->w[i], w))
+ for (int i = 0; i < node->windows->nWindows; ++i)
{
- if (!node->children[i])
+ if ((**isSameGroup) (node->windows->w[i], w))
{
- node->children[i] = newWindowTree ();
if (!node->children[i])
- return FALSE;
+ {
+ node->children[i] = newWindowTree ();
+ if (!node->children[i])
+ return FALSE;
+ }
+ return addWindowToTree (node->children[i], w, isSameGroup + 1);
}
- return addWindowToTree (node->children[i], w, isSameGroup);
}
}
if (node->childrenSize <= node->windows->nWindows)
{
- node->children = realloc (node->children, sizeof (WindowTree *) *\
+ node->children = realloc (node->children, sizeof (WindowTree *) * \
(node->childrenSize + 32));
if (!node->children)
return FALSE;
+ memset (node->children + node->childrenSize, 0,
+ sizeof (WindowTree *) * 32);
node->childrenSize += 32;
}
return addWindowToList(node->windows, w);
diff --git a/src/switcher-util.h b/src/switcher-util.h
index 303fa7e..eb0c608 100644
--- a/src/switcher-util.h
+++ b/src/switcher-util.h
@@ -85,7 +85,7 @@ void destroyWindowTree (WindowTree *node);
**/
Bool addWindowToTree (WindowTree *node,
CompWindow *w,
- WindowCmpProc isSameGroup);
+ WindowCmpProc *isSameGroup);
/**
* Create a WindowTree from a list of windows.
diff --git a/tests/check_switcher-util.c b/tests/check_switcher-util.c
index 2716366..c8e986e 100644
--- a/tests/check_switcher-util.c
+++ b/tests/check_switcher-util.c
@@ -10,11 +10,21 @@ WindowTree *tree;
WindowList *list;
CompWindow *a, *b, *c, *d;
+WindowCmpProc *compare;
+
+static Bool testCompare (CompWindow *a, CompWindow *b)
+{
+ return a == b;
+}
void setup ()
{
+ int i;
list = newWindowList ();
tree = newWindowTree ();
+ compare = malloc (sizeof (WindowCmpProc) * 2);
+ compare[0] = &testCompare;
+ compare[1] = NULL;
a = 0x5;
b = 0x4;
c = 0x4;
@@ -24,11 +34,7 @@ void setup ()
void teardown ()
{
destroyWindowList (list);
-}
-
-static Bool testCompare (CompWindow *a, CompWindow *b)
-{
- return a == b;
+ free (compare);
}
START_TEST (test_listCreate)
@@ -90,7 +96,7 @@ END_TEST
START_TEST (test_addToTree)
{
- fail_unless (addWindowToTree (tree, a, &testCompare),
+ fail_unless (addWindowToTree (tree, a, compare),
"addWindowToTree returned FALSE");
fail_unless (tree->windows->nWindows == 1,
@@ -109,7 +115,7 @@ START_TEST (test_addMultipleToFlatTree)
array[i] = (CompWindow *)i;
for (i = 0; i < 500; ++i)
- fail_unless (addWindowToTree (tree, array[i], &testCompare),
+ fail_unless (addWindowToTree (tree, array[i], compare),
"addWindowToTree returned FALSE");
for (i = 0; i < 500; ++i)
@@ -127,11 +133,11 @@ START_TEST (test_addGroupedWindows)
b = 0x3;
c = 0x3;
- fail_unless (addWindowToTree (tree, a, &testCompare),
+ fail_unless (addWindowToTree (tree, a, compare),
"addWindowToTree returned FALSE");
- fail_unless (addWindowToTree (tree, b, &testCompare),
+ fail_unless (addWindowToTree (tree, b, compare),
"addWindowToTree returned FALSE");
- fail_unless (addWindowToTree (tree, c, &testCompare),
+ fail_unless (addWindowToTree (tree, c, compare),
"addWindowToTree returned FALSE");
fail_unless (tree->windows->w[0] == a && tree->windows->w[1] == b,
@@ -141,6 +147,49 @@ START_TEST (test_addGroupedWindows)
}
END_TEST
+START_TEST (test_addManyGroupedWindows)
+{
+ CompWindow *array[500];
+ int i,j;
+
+ for (i = 0; i < 500; ++i)
+ array[i] = (CompWindow *) (i % 10);
+
+ for (i = 0; i < 500; ++i)
+ fail_unless (addWindowToTree (tree, array[i], compare),
+ "addWindowToTree returned FALSE");
+
+ fail_unless (tree->windows->nWindows == 10,
+ "Incorrect number of groups created");
+}
+END_TEST
+
+START_TEST (test_correctTreeStructure)
+{
+ CompWindow *array[500];
+ int i,j;
+
+ for (i = 0; i < 500; ++i)
+ array[i] = (CompWindow *) (i % 10);
+
+ for (i = 0; i < 500; ++i)
+ fail_unless (addWindowToTree (tree, array[i], compare),
+ "addWindowToTree returned FALSE");
+
+ for (i = 0; i < tree->windows->nWindows; ++i)
+ {
+ fail_unless (tree->windows->w[i] == (CompWindow *) i,
+ "Top-level window added in wrong order");
+ fail_unless (tree->children[i]->windows->nWindows == 49,
+ "Incorrect number of subwindows");
+ for (j = 0 ; j < 50-1; ++j)
+ {
+ fail_unless (tree->children[i]->windows->w[j] == (CompWindow *)i,
+ "Incorrect window in subgroup");
+ }
+ }
+}
+END_TEST
Suite *
switcher_util_suite (void)
@@ -167,6 +216,8 @@ switcher_util_suite (void)
tcase_add_test (tc_addToTree, test_addToTree);
tcase_add_test (tc_addToTree, test_addMultipleToFlatTree);
tcase_add_test (tc_addToTree, test_addGroupedWindows);
+ tcase_add_test (tc_addToTree, test_addManyGroupedWindows);
+ tcase_add_test (tc_addToTree, test_correctTreeStructure);
suite_add_tcase (s, tc_addToTree);
return s;