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
26 #include <gtk/gtkmain.h>
27 #include <glib/gprintf.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
31 #include "hildon-color-chooser.h"
32 #include "hildon-window.h"
34 #define MAX_COLOR 65535
36 /* -------------------- Fixtures -------------------- */
37 static HildonColorChooser *color_chooser = NULL;
38 static GtkWindow * cs_window;
41 fx_setup_default_color_chooser ()
44 gtk_init(&argc, NULL);
46 cs_window = GTK_WINDOW(create_test_window());
48 /* Check window object has been created properly */
49 fail_if(!HILDON_IS_WINDOW(cs_window),
50 "hildon-color-chooser: Window creation failed.");
52 color_chooser = HILDON_COLOR_CHOOSER(hildon_color_chooser_new());
53 /* Check that the color chooser object has been created properly */
54 fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser),
55 "hildon-color-chooser: Creation failed.");
57 gtk_container_add (GTK_CONTAINER(cs_window), GTK_WIDGET (color_chooser));
59 show_all_test_window(GTK_WIDGET(cs_window));
60 show_all_test_window(GTK_WIDGET(color_chooser));
65 fx_teardown_default_color_chooser ()
67 gtk_widget_destroy (GTK_WIDGET (color_chooser));
68 gtk_widget_destroy (GTK_WIDGET (cs_window));
72 /* -------------------- Test cases -------------------- */
74 /* ----- Test case for set_color -----*/
77 * Purpose: Check that regular base colors are set and get properly
79 * - Set the color #33CC33.
81 START_TEST (test_set_color_regular)
85 GdkColor * ret_color = g_new (GdkColor, 1);
87 /* Test 1: Set the color #33CC33*/
88 gdk_color_parse( "#33CC33", &color);
89 b_color = gdk_color_copy(&color);
91 hildon_color_chooser_set_color(color_chooser,b_color);
92 hildon_color_chooser_get_color(color_chooser, ret_color);
94 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
95 (b_color->blue != ret_color->blue),
96 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
97 ret_color->red, ret_color->green, ret_color->blue,
98 b_color->red, b_color->green, b_color->blue);
101 gdk_color_free(b_color);
104 gdk_color_free(ret_color);
109 * Purpose: Check that limits base colors are set and get properly
111 * - Set and get base color defined by #000000.
112 * - Set and get base color defined by #FFFFFF.
113 * - Set and get base color defined by #FF0000.
114 * - Set and get base color defined by #0000FF.
116 START_TEST (test_set_color_limits)
120 GdkColor * ret_color = g_new (GdkColor, 1);
122 /* Check that the color chooser object has been created properly */
123 fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser),
124 "hildon-color-chooser: Creation failed.");
126 b_color = gdk_color_copy(&color);
128 /* Test 1: Set the color #000000 */
129 gdk_color_parse( "#000000", &color);
130 b_color = gdk_color_copy(&color);
132 hildon_color_chooser_set_color(color_chooser,b_color);
133 hildon_color_chooser_get_color(color_chooser, ret_color);
135 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
136 (b_color->blue != ret_color->blue),
137 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
138 ret_color->red, ret_color->green, ret_color->blue,
139 b_color->red, b_color->green, b_color->blue);
141 gdk_color_free(b_color);
144 /* Test 2: Set the color #FFFFFF */
145 gdk_color_parse( "#000000", &color);
146 b_color = gdk_color_copy(&color);
148 hildon_color_chooser_set_color(color_chooser,b_color);
149 hildon_color_chooser_get_color(color_chooser, ret_color);
151 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
152 (b_color->blue != ret_color->blue),
153 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
154 ret_color->red, ret_color->green, ret_color->blue,
155 b_color->red, b_color->green, b_color->blue);
157 gdk_color_free(b_color);
160 /* Test 3: Set the color #FF0000 */
161 gdk_color_parse( "#FF0000", &color);
162 b_color = gdk_color_copy(&color);
164 hildon_color_chooser_set_color(color_chooser,b_color);
165 hildon_color_chooser_get_color(color_chooser, ret_color);
167 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
168 (b_color->blue != ret_color->blue),
169 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
170 ret_color->red, ret_color->green, ret_color->blue,
171 b_color->red, b_color->green, b_color->blue);
173 gdk_color_free(b_color);
175 /* Test 4: Set the color to #0000FF*/
176 gdk_color_parse( "#0000FF", &color);
177 b_color = gdk_color_copy(&color);
179 hildon_color_chooser_set_color(color_chooser,b_color);
180 hildon_color_chooser_get_color(color_chooser, ret_color);
182 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
183 (b_color->blue != ret_color->blue),
184 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
185 ret_color->red, ret_color->green, ret_color->blue,
186 b_color->red, b_color->green, b_color->blue);
189 gdk_color_free(b_color);
192 gdk_color_free(ret_color);
196 * Purpose: Check that invalid base colors are set and get properly
198 * - Set and get base color defined by #00FFFF and pixel 0.
199 * - Set and get base color defined by #0ABCDE and pixel 0.
200 * - Set and get base color defined by #FF00FF and pixel 0.
201 * - Set the color (65536,65536,65536).
202 * - Set and get base color defined by NULL color.
203 * - Set base color on NULL object.
204 * - Get base color from NULL object.
206 START_TEST (test_set_color_invalid)
210 GdkColor * ret_color = g_new (GdkColor, 1);
215 /* Check that the color chooser object has been created properly */
216 fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser),
217 "hildon-color-chooser: Creation failed.");
219 b_color = gdk_color_copy(&color);
221 /* Initialize color to check that invalid values doesn't set colors*/
222 gdk_color_parse( "#000000", &color);
223 b_color = gdk_color_copy(&color);
225 hildon_color_chooser_set_color(color_chooser,b_color);
226 gdk_color_free(b_color);
228 /* Test 1: Set the color #00FFFF*/
229 gdk_color_parse( "#00FFFF", &color);
230 b_color = gdk_color_copy(&color);
232 hildon_color_chooser_set_color(color_chooser,b_color);
233 hildon_color_chooser_get_color(color_chooser,ret_color);
235 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
236 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
237 ret_color->red, ret_color->green, ret_color->blue,
240 gdk_color_free(b_color);
242 /* Test 2: Set the color #FFFFFF */
243 gdk_color_parse( "#0ABCDE", &color);
244 b_color = gdk_color_copy(&color);
246 hildon_color_chooser_set_color(color_chooser,b_color);
247 hildon_color_chooser_get_color(color_chooser,ret_color);
249 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
250 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
251 ret_color->red, ret_color->green, ret_color->blue,
254 gdk_color_free(b_color);
256 /* Test 2: Set the color #FF00FF */
257 gdk_color_parse( "#FF00FF", &color);
258 b_color = gdk_color_copy(&color);
260 hildon_color_chooser_set_color(color_chooser,b_color);
261 hildon_color_chooser_get_color(color_chooser,ret_color);
263 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
264 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
265 ret_color->red, ret_color->green, ret_color->blue,
268 gdk_color_free(b_color);
270 /* Test 3: Set the color (65536,65536,65536)*/
271 gdk_color_parse( "#000000", &color);
272 b_color = gdk_color_copy(&color);
278 b_color->green=green;
281 hildon_color_chooser_set_color(color_chooser,b_color);
282 hildon_color_chooser_get_color(color_chooser, ret_color);
284 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
285 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
286 ret_color->red, ret_color->green, ret_color->blue,
289 /* Test 5: Set the color NULL on color chooser*/
290 hildon_color_chooser_set_color(color_chooser,NULL);
292 /* Test 6: Set the color on NULL object*/
293 hildon_color_chooser_set_color(NULL,b_color);
295 /* Test 7: Get color from NULL object*/
296 hildon_color_chooser_get_color(NULL, ret_color);
299 gdk_color_free(b_color);
302 gdk_color_free(ret_color);
307 /* ---------- Suite creation ---------- */
309 Suite *create_hildon_color_chooser_suite()
311 /* Create the suite */
312 Suite *s = suite_create("HildonColorChooser");
314 /* Create test case for hildon_color_chooser_set_color and add it to the suite */
315 TCase *tc1 = tcase_create("set_color");
316 tcase_add_checked_fixture(tc1, fx_setup_default_color_chooser, fx_teardown_default_color_chooser);
317 tcase_add_test(tc1, test_set_color_regular);
318 tcase_add_test(tc1, test_set_color_limits);
319 tcase_add_test(tc1, test_set_color_invalid);
320 suite_add_tcase (s, tc1);
322 /* Return created suite */