1
/*******************************************************************************
2
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
3
** 10 20 30 40 50 60 70 80
7
** test-stack.c - unit-tests for stack class
9
** Copyright 2009 Canonical Ltd.
12
** Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
13
** David Barth <david.barth@canonical.com>
15
** This program is free software: you can redistribute it and/or modify it
16
** under the terms of the GNU General Public License version 3, as published
17
** by the Free Software Foundation.
19
** This program is distributed in the hope that it will be useful, but
20
** WITHOUT ANY WARRANTY; without even the implied warranties of
21
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
22
** PURPOSE. See the GNU General Public License for more details.
24
** You should have received a copy of the GNU General Public License along
25
** with this program. If not, see <http://www.gnu.org/licenses/>.
27
*******************************************************************************/
40
Defaults* defaults = defaults_new ();
41
Observer* observer = observer_new ();
43
stack = stack_new (defaults, observer);
44
g_assert (stack != NULL);
52
Defaults* defaults = defaults_new ();
53
Observer* observer = observer_new ();
55
stack = stack_new (defaults, observer);
64
Defaults* defaults = defaults_new ();
65
Observer* observer = observer_new ();
66
Bubble* bubble = bubble_new (defaults);
68
guint replaced_id = -1;
70
stack = stack_new (defaults, observer);
71
id = stack_push_bubble (stack, bubble);
75
replaced_id = stack_push_bubble (stack, bubble);
77
g_assert (replaced_id == id);
79
g_object_unref (G_OBJECT (stack));
86
Defaults* defaults = defaults_new ();
87
Observer* observer = observer_new ();
93
stack = stack_new (defaults, observer);
95
// check if stack_is_slot_vacant() can take "crap" without crashing
96
g_assert_cmpint (stack_is_slot_vacant (NULL, SLOT_TOP), ==, FALSE);
97
g_assert_cmpint (stack_is_slot_vacant (stack, 832), ==, FALSE);
98
g_assert_cmpint (stack_is_slot_vacant (NULL, 4321), ==, FALSE);
100
// check if stack_get_slot_position can take "crap" without crashing
101
stack_get_slot_position (NULL, SLOT_TOP, 0, &x, &y);
102
g_assert_cmpint (x, ==, -1);
103
g_assert_cmpint (y, ==, -1);
104
stack_get_slot_position (stack, 4711, 0, &x, &y);
105
g_assert_cmpint (x, ==, -1);
106
g_assert_cmpint (y, ==, -1);
107
stack_get_slot_position (NULL, 42, 0, NULL, NULL);
109
// check if stack_allocate_slot() can take "crap" without crashing
110
one = bubble_new (defaults);
111
two = bubble_new (defaults);
112
g_assert_cmpint (stack_allocate_slot (NULL, one, SLOT_TOP), ==, FALSE);
113
g_assert_cmpint (stack_allocate_slot (stack, NULL, SLOT_TOP), ==, FALSE);
114
g_assert_cmpint (stack_allocate_slot (stack, one, 4711), ==, FALSE);
116
// check if stack_free_slot() can take "crap" without crashing
117
g_assert_cmpint (stack_free_slot (NULL, two), ==, FALSE);
118
g_assert_cmpint (stack_free_slot (stack, NULL), ==, FALSE);
120
// initially both slots should be empty
121
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, VACANT);
122
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, VACANT);
123
g_object_unref (one);
124
g_object_unref (two);
126
// fill top slot, verify it's occupied, free it, verify again
127
one = bubble_new (defaults);
128
g_assert_cmpint (stack_allocate_slot (stack, one, SLOT_TOP), ==, TRUE);
129
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, OCCUPIED);
130
g_assert_cmpint (stack_free_slot (stack, one), ==, TRUE);
131
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, VACANT);
132
g_object_unref (one);
134
// fill bottom slot, verify it's occupied, free it, verify again
135
two = bubble_new (defaults);
136
g_assert_cmpint (stack_allocate_slot (stack, two, SLOT_BOTTOM), ==, TRUE);
137
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, OCCUPIED);
138
g_assert_cmpint (stack_free_slot (stack, two), ==, TRUE);
139
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, VACANT);
140
g_object_unref (two);
142
// try to free vacant slots
143
one = bubble_new (defaults);
144
two = bubble_new (defaults);
145
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, VACANT);
146
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, VACANT);
147
g_assert_cmpint (stack_free_slot (stack, one), ==, FALSE);
148
g_assert_cmpint (stack_free_slot (stack, two), ==, FALSE);
149
g_object_unref (one);
150
g_object_unref (two);
152
// allocate top slot, verify, try to allocate top slot again
153
one = bubble_new (defaults);
154
two = bubble_new (defaults);
155
g_assert_cmpint (stack_allocate_slot (stack, one, SLOT_TOP), ==, TRUE);
156
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, OCCUPIED);
157
g_assert_cmpint (stack_allocate_slot (stack, two, SLOT_TOP), ==, FALSE);
158
g_assert_cmpint (stack_free_slot (stack, one), ==, TRUE);
159
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_TOP), ==, VACANT);
160
g_object_unref (one);
161
g_object_unref (two);
163
// allocate bottom slot, verify, try to allocate bottom slot again
164
one = bubble_new (defaults);
165
two = bubble_new (defaults);
166
g_assert_cmpint (stack_allocate_slot (stack, one, SLOT_BOTTOM), ==, TRUE);
167
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, OCCUPIED);
168
g_assert_cmpint (stack_allocate_slot (stack, two, SLOT_BOTTOM), ==, FALSE);
169
g_assert_cmpint (stack_free_slot (stack, one), ==, TRUE);
170
g_assert_cmpint (stack_is_slot_vacant (stack, SLOT_BOTTOM), ==, VACANT);
171
g_object_unref (one);
172
g_object_unref (two);
174
// check if we can get reasonable values from stack_get_slot_position()
175
// FIXME: disabled this test for the moment, hopefully it works within
176
// a real environment
177
/*stack_get_slot_position (stack, SLOT_TOP, &x, &y);
178
g_assert_cmpint (x, >, -1);
179
g_assert_cmpint (y, >, -1);
180
stack_get_slot_position (stack, SLOT_BOTTOM, &x, &y);
181
g_assert_cmpint (x, >, -1);
182
g_assert_cmpint (y, >, -1);*/
184
g_object_unref (G_OBJECT (stack));
188
test_stack_create_test_suite (void)
190
GTestSuite *ts = NULL;
192
ts = g_test_create_suite ("stack");
194
#define TC(x) g_test_create_case(#x, 0, NULL, NULL, x, NULL)
196
g_test_suite_add(ts, TC(test_stack_new));
197
g_test_suite_add(ts, TC(test_stack_del));
198
g_test_suite_add(ts, TC(test_stack_push));
199
g_test_suite_add(ts, TC(test_stack_slots));