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/hildon-color-chooser.h>
32 #include <hildon/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 /* Test 1: Set the color #000000 */
127 gdk_color_parse( "#000000", &color);
128 b_color = gdk_color_copy(&color);
130 hildon_color_chooser_set_color(color_chooser,b_color);
131 hildon_color_chooser_get_color(color_chooser, ret_color);
133 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
134 (b_color->blue != ret_color->blue),
135 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
136 ret_color->red, ret_color->green, ret_color->blue,
137 b_color->red, b_color->green, b_color->blue);
139 gdk_color_free(b_color);
142 /* Test 2: Set the color #FFFFFF */
143 gdk_color_parse( "#000000", &color);
144 b_color = gdk_color_copy(&color);
146 hildon_color_chooser_set_color(color_chooser,b_color);
147 hildon_color_chooser_get_color(color_chooser, ret_color);
149 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
150 (b_color->blue != ret_color->blue),
151 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
152 ret_color->red, ret_color->green, ret_color->blue,
153 b_color->red, b_color->green, b_color->blue);
155 gdk_color_free(b_color);
158 /* Test 3: Set the color #FF0000 */
159 gdk_color_parse( "#FF0000", &color);
160 b_color = gdk_color_copy(&color);
162 hildon_color_chooser_set_color(color_chooser,b_color);
163 hildon_color_chooser_get_color(color_chooser, ret_color);
165 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
166 (b_color->blue != ret_color->blue),
167 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
168 ret_color->red, ret_color->green, ret_color->blue,
169 b_color->red, b_color->green, b_color->blue);
171 gdk_color_free(b_color);
173 /* Test 4: Set the color to #0000FF*/
174 gdk_color_parse( "#0000FF", &color);
175 b_color = gdk_color_copy(&color);
177 hildon_color_chooser_set_color(color_chooser,b_color);
178 hildon_color_chooser_get_color(color_chooser, ret_color);
180 fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) ||
181 (b_color->blue != ret_color->blue),
182 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
183 ret_color->red, ret_color->green, ret_color->blue,
184 b_color->red, b_color->green, b_color->blue);
187 gdk_color_free(b_color);
190 gdk_color_free(ret_color);
194 * Purpose: Check that invalid base colors are set and get properly
196 * - Set and get base color defined by #00FFFF and pixel 0.
197 * - Set and get base color defined by #0ABCDE and pixel 0.
198 * - Set and get base color defined by #FF00FF and pixel 0.
199 * - Set the color (65536,65536,65536).
200 * - Set and get base color defined by NULL color.
201 * - Set base color on NULL object.
202 * - Get base color from NULL object.
204 START_TEST (test_set_color_invalid)
208 GdkColor * ret_color = g_new (GdkColor, 1);
213 /* Check that the color chooser object has been created properly */
214 fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser),
215 "hildon-color-chooser: Creation failed.");
217 /* Initialize color to check that invalid values doesn't set colors*/
218 gdk_color_parse( "#000000", &color);
219 b_color = gdk_color_copy(&color);
221 hildon_color_chooser_set_color(color_chooser,b_color);
222 gdk_color_free(b_color);
224 /* Test 1: Set the color #00FFFF*/
225 gdk_color_parse( "#00FFFF", &color);
226 b_color = gdk_color_copy(&color);
228 hildon_color_chooser_set_color(color_chooser,b_color);
229 hildon_color_chooser_get_color(color_chooser,ret_color);
231 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
232 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
233 ret_color->red, ret_color->green, ret_color->blue,
236 gdk_color_free(b_color);
238 /* Test 2: Set the color #FFFFFF */
239 gdk_color_parse( "#0ABCDE", &color);
240 b_color = gdk_color_copy(&color);
242 hildon_color_chooser_set_color(color_chooser,b_color);
243 hildon_color_chooser_get_color(color_chooser,ret_color);
245 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
246 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
247 ret_color->red, ret_color->green, ret_color->blue,
250 gdk_color_free(b_color);
252 /* Test 2: Set the color #FF00FF */
253 gdk_color_parse( "#FF00FF", &color);
254 b_color = gdk_color_copy(&color);
256 hildon_color_chooser_set_color(color_chooser,b_color);
257 hildon_color_chooser_get_color(color_chooser,ret_color);
259 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
260 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
261 ret_color->red, ret_color->green, ret_color->blue,
264 gdk_color_free(b_color);
266 /* Test 3: Set the color (65536,65536,65536)*/
267 gdk_color_parse( "#000000", &color);
268 b_color = gdk_color_copy(&color);
274 b_color->green=green;
277 hildon_color_chooser_set_color(color_chooser,b_color);
278 hildon_color_chooser_get_color(color_chooser, ret_color);
280 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
281 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
282 ret_color->red, ret_color->green, ret_color->blue,
285 /* Test 5: Set the color NULL on color chooser*/
286 hildon_color_chooser_set_color(color_chooser,NULL);
288 /* Test 6: Set the color on NULL object*/
289 hildon_color_chooser_set_color(NULL,b_color);
291 /* Test 7: Get color from NULL object*/
292 hildon_color_chooser_get_color(NULL, ret_color);
295 gdk_color_free(b_color);
298 gdk_color_free(ret_color);
303 /* ---------- Suite creation ---------- */
305 Suite *create_hildon_color_chooser_suite()
307 /* Create the suite */
308 Suite *s = suite_create("HildonColorChooser");
310 /* Create test case for hildon_color_chooser_set_color and add it to the suite */
311 TCase *tc1 = tcase_create("set_color");
312 tcase_add_checked_fixture(tc1, fx_setup_default_color_chooser, fx_teardown_default_color_chooser);
313 tcase_add_test(tc1, test_set_color_regular);
314 tcase_add_test(tc1, test_set_color_limits);
315 tcase_add_test(tc1, test_set_color_invalid);
316 suite_add_tcase (s, tc1);
318 /* Return created suite */