2 * This file is a part of hildon tests
4 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <gtk/gtkmain.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
31 #include "hildon-sort-dialog.h"
33 #define SORT_KEY_0 "maemo"
34 #define SORT_KEY_1 TEST_STRING
37 /* -------------------- Fixtures -------------------- */
39 static HildonSortDialog *sort_dialog = NULL;
40 static GtkWindow * showed_window = NULL;
43 fx_setup_default_sort_dialog ()
46 gtk_init(&argc, NULL);
48 showed_window = GTK_WINDOW(create_test_window());
50 sort_dialog = HILDON_SORT_DIALOG(hildon_sort_dialog_new(showed_window));
52 show_test_window(GTK_WIDGET(showed_window));
54 show_test_window(GTK_WIDGET(sort_dialog));
56 /* Check sort_dialog object has been created properly */
57 fail_if(!HILDON_IS_SORT_DIALOG(sort_dialog),
58 "hildon-sort-dialog: Creation failed.");
62 fx_teardown_default_sort_dialog ()
65 gtk_widget_destroy (GTK_WIDGET (sort_dialog));
67 gtk_widget_destroy (GTK_WIDGET(showed_window));
71 /* -------------------- Test cases -------------------- */
73 /* ----- Test case for set/get_sort_key -----*/
76 * Purpose: Test add, set and get of sort keys.
78 * - Add 3 keys to the list, then set and get key 1
81 START_TEST (test_add_set_get_sort_key_regular)
85 /* Test1: add 3 keys, then try to set and get key 1 */
86 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0);
87 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1);
88 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2);
90 hildon_sort_dialog_set_sort_key(sort_dialog, 1);
91 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
93 "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 1, but get_sort_key returned value %d instead of 1",
94 SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key);
96 /* Test2: Unselect sort key */
97 hildon_sort_dialog_set_sort_key(sort_dialog, -1);
98 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
99 fail_if(ret_key != -1,
100 "hildon-sort-dialog: Set sort key to -1, but get_sort_key returned value %d instead of -1",
109 * - Get of current key after dialog construction (empty list of keys)
110 * - Add 3 keys to the list, then set and get keys 0 and 2
112 START_TEST (test_add_set_get_sort_key_limits)
116 /* Test1: Get current key after construction */
117 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
118 fail_if(ret_key != -1,
119 "hildon-sort-dialog: After dialog construction current sort key index is %d instead of -1",
122 /* Test2: Add 3 keys, then set and get keys 0 and 2 */
123 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0);
124 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1);
125 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2);
127 hildon_sort_dialog_set_sort_key(sort_dialog, 0);
128 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
129 fail_if(ret_key != 0,
130 "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 0, but get_sort_key returned value %d instead of 0",
131 SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key);
133 hildon_sort_dialog_set_sort_key(sort_dialog, 2);
134 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
135 fail_if(ret_key != 2,
136 "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 2, but get_sort_key returned value %d instead of 2",
137 SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key);
142 * Purpose: Check handling of invalid values regarding the sort keys management
144 * - Set of key with empty key list
145 * - Set negative key, lower than -1
146 * - Set of key outside the range of a non empty key list
147 * - Set a duplicated key and check it is filtered
148 * - Add NULL sort key.
149 * - Add key with NULL object
150 * - Set key with NULL object
151 * - Get key with NULL object
153 START_TEST (test_add_set_get_sort_key_invalid)
157 /* Test1: Set of a key with an empty key list */
158 hildon_sort_dialog_set_sort_key(sort_dialog, 5);
159 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
160 fail_if(ret_key != -1,
161 "hildon-sort-dialog: Set sort key to 5 when the list of keys is empty, then retrieved current sort key and result was %d instead of -1",
164 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0);
165 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1);
166 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2);
168 /* Test2: Set negative key lower than -1 */
169 hildon_sort_dialog_set_sort_key(sort_dialog, 1);
170 hildon_sort_dialog_set_sort_key(sort_dialog, -3);
171 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
172 fail_if(ret_key != 1,
173 "hildon-sort-dialog: Set sort key to 1 when list of keys has 3 elements, then set sort key again to an invalid value of -3, then retrieved current sort key and result was %d instead of 1",
176 /* Test3: Set of a positive key outside the range of a non empty key list */
177 hildon_sort_dialog_set_sort_key(sort_dialog, 8);
178 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
179 fail_if(ret_key != -1,
180 "hildon-sort-dialog: Set sort key to 8 when the list of keys has 3 elements, then retrieved current sort key and result was %d instead of -1",
183 /* This test breaks, because after setting an invalid positive value, get_sort_key returns -1 instead of
184 the last valid value set. I considered this an error because it does not the same when the invalid index is
185 negative (in that case it preserves the last valid index set) */
186 hildon_sort_dialog_set_sort_key(sort_dialog, 1);
187 hildon_sort_dialog_set_sort_key(sort_dialog, 8);
188 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
189 /* fail_if(ret_key != 1,
190 "hildon-sort-dialog: Set sort key to 1 when the list of keys has 3 elements, then set sort key again to an invalid index value of 8, then retrieved current sort key and result was %d instead of 1",
193 fail_if(ret_key != -1,
194 "hildon-sort-dialog: Set sort key to 1 when the list of keys has 3 elements, then set sort key again to an invalid index value of 8, then retrieved current sort key and result was %d instead of 1",
197 /* Test4: Add duplicated key */
198 hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0);
199 hildon_sort_dialog_set_sort_key(sort_dialog, 3);
200 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
201 fail_if(ret_key != 3,
202 "hildon-sort-dialog: Addition of duplicated sort keys is allowed.");
204 /* Test5: Add NULL key */
205 hildon_sort_dialog_add_sort_key(sort_dialog, NULL);
206 hildon_sort_dialog_set_sort_key(sort_dialog, 4);
207 ret_key = hildon_sort_dialog_get_sort_key(sort_dialog);
208 fail_if(ret_key == 4,
209 "hildon-sort-dialog: Addition of NULL sort key is allowed.");
211 /* Test6: add key to a NULL object */
212 hildon_sort_dialog_add_sort_key(NULL, SORT_KEY_0);
214 /* Test7: set key in a NULL object */
215 hildon_sort_dialog_set_sort_key(NULL, 0);
217 /* Test8: get key in a NULL object */
218 hildon_sort_dialog_get_sort_key(NULL);
222 /* ---------- Suite creation ---------- */
224 Suite *create_hildon_sort_dialog_suite()
226 /* Create the suite */
227 Suite *s = suite_create("HildonSortDialog");
229 /* Create test cases */
230 TCase *tc1 = tcase_create("add_get_set_sort_key");
232 /* Create test case for adding, getting and setting a sort key and add it to the suite */
233 tcase_add_checked_fixture(tc1, fx_setup_default_sort_dialog, fx_teardown_default_sort_dialog);
234 tcase_add_test(tc1, test_add_set_get_sort_key_regular);
235 tcase_add_test(tc1, test_add_set_get_sort_key_limits);
236 tcase_add_test(tc1, test_add_set_get_sort_key_invalid);
237 suite_add_tcase (s, tc1);
239 /* Return created suite */