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 the color (65536,65536,65536).
197 * - Set and get base color defined by NULL color.
198 * - Set base color on NULL object.
199 * - Get base color from NULL object.
201 START_TEST (test_set_color_invalid)
205 GdkColor * ret_color = g_new (GdkColor, 1);
210 /* Check that the color chooser object has been created properly */
211 fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser),
212 "hildon-color-chooser: Creation failed.");
214 /* Initialize color to check that invalid values doesn't set colors*/
215 gdk_color_parse( "#000000", &color);
216 b_color = gdk_color_copy(&color);
218 hildon_color_chooser_set_color(color_chooser,b_color);
219 gdk_color_free(b_color);
222 /* Test 1: Set the color (65536,65536,65536)*/
223 gdk_color_parse( "#000000", &color);
224 b_color = gdk_color_copy(&color);
230 b_color->green=green;
233 hildon_color_chooser_set_color(color_chooser,b_color);
234 hildon_color_chooser_get_color(color_chooser, ret_color);
236 fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue),
237 "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i",
238 ret_color->red, ret_color->green, ret_color->blue,
241 /* Test 2: Set the color NULL on color chooser*/
242 hildon_color_chooser_set_color(color_chooser,NULL);
244 /* Test 3: Set the color on NULL object*/
245 hildon_color_chooser_set_color(NULL,b_color);
247 /* Test 4: Get color from NULL object*/
248 hildon_color_chooser_get_color(NULL, ret_color);
251 gdk_color_free(b_color);
254 gdk_color_free(ret_color);
259 /* ---------- Suite creation ---------- */
261 Suite *create_hildon_color_chooser_suite()
263 /* Create the suite */
264 Suite *s = suite_create("HildonColorChooser");
266 /* Create test case for hildon_color_chooser_set_color and add it to the suite */
267 TCase *tc1 = tcase_create("set_color");
268 tcase_add_checked_fixture(tc1, fx_setup_default_color_chooser, fx_teardown_default_color_chooser);
269 tcase_add_test(tc1, test_set_color_regular);
270 tcase_add_test(tc1, test_set_color_limits);
271 tcase_add_test(tc1, test_set_color_invalid);
272 suite_add_tcase (s, tc1);
274 /* Return created suite */