summaryrefslogtreecommitdiff
path: root/tests/check_switcher-util.c
blob: e37f8e4ab1c111cef02436155470dc5bde0a04dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdlib.h>
#include <check.h>
#include <stdio.h>

#include <compiz.h>

#include "../src/switcher-util.h"

WindowTree *tree;
WindowList *list;

CompWindow *a, *b, *c, *d;

static Bool testCompare (CompWindow *a, CompWindow *b) 
{
    printf("In testCompare\n");
    return a == b;
}

START_TEST (test_listCreate)
{
    list = newWindowList ();
    fail_unless (list->nWindows == 0,
		 "Window list count not set correctly on creation");
    fail_unless (list->w != NULL,
		 "Window array not allocated successfully");
    fail_unless (list->windowsSize == 32,
		 "Window array size set incorrectly");
}
END_TEST

START_TEST (test_treeCreate)
{
    fail_unless (tree->windows->nWindows == 0 && tree->windows->w != NULL,
		 "Failed to initialise WindowList on WindowTree creation");
    fail_unless (tree->children != NULL,
		 "Children array not allocated on creation of WindowTree");
    fail_unless (tree->childrenSize == 4,
		 "Size of childrenArray not set correctly");
}
END_TEST

START_TEST (test_addToList)
{
    list = newWindowList ();
    
    fail_unless (addWindowToList (list, a),
		 "addWindowToList returned FALSE");

    fail_unless (list->nWindows == 1,
		 "Window list size not updated correctly");
    fail_unless (list->w[0] == a,
		 "Wrong window added to list");
}
END_TEST

/*
START_TEST (test_addToTree)
{
    fail_unless (addWindowToTree (tree, a, testCompare),
		 "addWindowToTree returned FALSE");
    
    fail_unless (tree->windows->nWindows == 1,
		 "Window not added to tree");
    fail_unless (tree->windows->w[0] == a,
		 "Incorrect window added to tree");
}
END_TEST
*/

Suite *
switcher_util_suite (void)
{
  Suite *s = suite_create ("Switcher Util");

  /* Core test case */
  TCase *tc_core = tcase_create ("Core");
  tcase_add_checked_fixture (tc_core, setup, teardown);
  tcase_add_test (tc_core, test_listCreate);
  tcase_add_test (tc_core, test_treeCreate);
  suite_add_tcase (s, tc_core);

  /* Add windows to tree test cases */
  TCase *tc_addToList = tcase_create ("Add To List");
  tcase_add_test (tc_addToList, test_addToList);
  suite_add_tcase (s, tc_addToList);

  return s;
}

int
main (void)
{
  int number_failed;
  Suite *s = switcher_util_suite ();
  SRunner *sr = srunner_create (s);
  srunner_run_all (sr, CK_NORMAL);
  number_failed = srunner_ntests_failed (sr);
  srunner_free (sr);
  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}