2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkhbox.h>
27 #include <glib/gprintf.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30 #include "hildon-color-button.h"
32 /* -------------------- Fixtures -------------------- */
33 static HildonColorButton *color_button = NULL;
34 static GtkWidget *showed_window = NULL;
37 fx_setup_default_color_button()
40 gtk_init(&argc, NULL);
42 color_button = HILDON_COLOR_BUTTON(hildon_color_button_new());
43 /* Check that the color button object has been created properly */
45 showed_window = create_test_window ();
47 /* This packs the widget into the window (a gtk container). */
48 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (color_button));
50 /* Displays the widget and the window */
51 show_all_test_window (showed_window);
54 fail_if(!HILDON_IS_COLOR_BUTTON(color_button),
55 "hildon-color-button: Creation failed.");
60 fx_teardown_default_color_button()
63 /* Destroy the widget and the window */
64 gtk_widget_destroy(GTK_WIDGET(showed_window));
68 /* -------------------- Test cases -------------------- */
70 /* ----- Test case for set_color -----*/
72 * Purpose: Check that a regular color can be set safely
74 * - Set color defined by (255, 255, 255) and pixel = 255
75 * - Set color defined by (10, 20, 30) and pixel = 10
76 * - Set color defined by (20, 10, 30) and pixel = 10
77 * - Set color defined by (30, 10, 20) and pixel = 20
80 START_TEST (test_set_color_regular)
84 GdkColor * ret_color = g_new (GdkColor, 1);
90 b_color = gdk_color_copy(&color);
92 /* Test 1: Set color defined by (255,255,255)*/
101 b_color->pixel=pixel;
103 hildon_color_button_set_color(color_button,b_color);
104 hildon_color_button_get_color(color_button, ret_color);
106 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
107 (blue != ret_color->blue) || (pixel != ret_color->pixel),
108 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
109 pixel, ret_color->red, ret_color->green,
110 ret_color->blue, ret_color->pixel);
112 /* Test 2: Set color defined by (10,20,30)*/
119 b_color->green=green;
121 b_color->pixel=pixel;
123 hildon_color_button_set_color(color_button,b_color);
124 hildon_color_button_get_color(color_button, ret_color);
126 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
127 (blue != ret_color->blue) || (pixel != ret_color->pixel),
128 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
129 pixel, ret_color->red, ret_color->green,
130 ret_color->blue, ret_color->pixel);
132 /* Test 3: Set color defined by (20,10,30)*/
139 b_color->green=green;
141 b_color->pixel=pixel;
143 hildon_color_button_set_color(color_button,b_color);
144 hildon_color_button_get_color(color_button, ret_color);
146 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
147 (blue != ret_color->blue) || (pixel != ret_color->pixel),
148 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
149 pixel, ret_color->red, ret_color->green,
150 ret_color->blue, ret_color->pixel);
152 /* Test 4: Set color defined by (30,10,20)*/
159 b_color->green=green;
161 b_color->pixel=pixel;
163 hildon_color_button_set_color(color_button,b_color);
164 hildon_color_button_get_color(color_button, ret_color);
166 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
167 (blue != ret_color->blue) || (pixel != ret_color->pixel),
168 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
169 pixel, ret_color->red, ret_color->green,
170 ret_color->blue, ret_color->pixel);
173 gdk_color_free(b_color);
176 gdk_color_free(ret_color);
181 * Purpose: Check that a limits values on color components can be set safely.
183 * - Set color defined by (0, 0, 0) and pixel = 0
184 * - Set color defined by (G_MAXUINT16, G_MAXUINT16, G_MAXUINT16) and pixel = G_MAXUINT32
185 * - Set color defined by (G_MAXUINT16, 0, 0) and pixel = G_MAXUINT32
186 * - Set color defined by (0, G_MAXUINT16, 0) and pixel = 0
187 * - Set color defined by (0, 0, G_MAXUINT16) and pixel = G_MAXUINT32
190 START_TEST (test_set_color_limits)
194 GdkColor * ret_color = g_new (GdkColor, 1);
200 b_color = gdk_color_copy(&color);
202 /* Test 1: Set color defined by (0,0,0)*/
209 b_color->green=green;
211 b_color->pixel=pixel;
213 hildon_color_button_set_color(color_button,b_color);
214 hildon_color_button_get_color(color_button, ret_color);
216 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
217 (blue != ret_color->blue) || (pixel != ret_color->pixel),
218 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
219 pixel, ret_color->red, ret_color->green,
220 ret_color->blue, ret_color->pixel);
222 /* Test 2: Set color defined by (G_MAXUINT16,G_MAXUINT16,G_MAXUINT16)*/
228 b_color->pixel=pixel;
230 b_color->green=green;
233 hildon_color_button_set_color(color_button,b_color);
234 hildon_color_button_get_color(color_button, ret_color);
236 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
237 (blue != ret_color->blue) || (pixel != ret_color->pixel),
238 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
239 pixel, ret_color->red, ret_color->green,
240 ret_color->blue, ret_color->pixel);
242 /* Test 3: Set color defined by (G_MAXUINT16,0,0)*/
249 b_color->green=green;
251 b_color->pixel=pixel;
253 hildon_color_button_set_color(color_button,b_color);
254 hildon_color_button_get_color(color_button, ret_color);
256 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
257 (blue != ret_color->blue) || (pixel != ret_color->pixel),
258 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
259 pixel, ret_color->red, ret_color->green,
260 ret_color->blue, ret_color->pixel);
262 /* Test 4: Set color defined by (0,G_MAXUINT16,0)*/
269 b_color->green=green;
271 b_color->pixel=pixel;
273 hildon_color_button_set_color(color_button,b_color);
274 hildon_color_button_get_color(color_button, ret_color);
276 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
277 (blue != ret_color->blue) || (pixel != ret_color->pixel),
278 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
279 pixel, ret_color->red, ret_color->green,
280 ret_color->blue, ret_color->pixel);
282 /* Test 5: Set color defined by (0,0,G_MAXUINT16)*/
289 b_color->green=green;
291 b_color->pixel=pixel;
293 hildon_color_button_set_color(color_button,b_color);
294 hildon_color_button_get_color(color_button, ret_color);
296 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
297 (blue != ret_color->blue) || (pixel != ret_color->pixel),
298 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
299 pixel, ret_color->red, ret_color->green,
300 ret_color->blue, ret_color->pixel);
303 gdk_color_free(b_color);
306 gdk_color_free(ret_color);
311 * Purpose: Check that a limits values on color components can be set safely.
313 * - Set color defined by (0, 0, 0) on NULL object.
314 * - Get color from NULL object.
315 * - Set color defined by (0, 0, 0) on GtkHBox object.
316 * - Get a color from GtkHBox object.
319 START_TEST (test_set_color_invalid)
323 GdkColor * ret_color = g_new (GdkColor, 1);
324 GtkWidget *aux_object = NULL;
329 b_color = gdk_color_copy(&color);
336 b_color->green=green;
340 /* Test 1: Set color defined by (0,0,0) on NULL object*/
341 hildon_color_button_set_color(NULL,b_color);
343 /* Test 2: Get color from NULL object*/
344 hildon_color_button_get_color(NULL, ret_color);
346 /* Test 3: Set color defined by (0, 0, 0) on GtkHBox object. */
347 aux_object = gtk_hbox_new (TRUE, 0);
348 hildon_color_button_set_color((HildonColorButton *) (aux_object), b_color);
349 gdk_color_free(b_color);
351 /* Test 4: Get color from GtkHBox object. */
353 ret_color->green = 99;
354 ret_color->blue = 99;
355 hildon_color_button_get_color((HildonColorButton *) (aux_object), ret_color);
357 if (ret_color->red != 99 ||
358 ret_color->green != 99 ||
359 ret_color->blue != 99)
361 gtk_widget_destroy(aux_object);
362 fail ("hildon-color-button: get_color must not modify the color when launched on invalid widget");
365 gtk_widget_destroy(aux_object);
369 /* ---------- Suite creation ---------- */
371 Suite *create_hildon_color_button_suite()
373 /* Create the suite */
374 Suite *s = suite_create("HildonColorButton");
376 /* Create test cases */
377 TCase *tc1 = tcase_create("set_color");
379 /* Create test case for hildon_color_button_set_color and add it to the suite */
380 tcase_add_checked_fixture(tc1, fx_setup_default_color_button, fx_teardown_default_color_button);
381 tcase_add_test(tc1, test_set_color_regular);
382 tcase_add_test(tc1, test_set_color_limits);
383 tcase_add_test(tc1, test_set_color_invalid);
384 suite_add_tcase(s, tc1);
386 /* Return created suite */