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 <gtk/gtkhbox.h>
29 #include <glib/gprintf.h>
30 #include "test_suites.h"
31 #include "check_utils.h"
32 #include "hildon-color-button.h"
34 /* -------------------- Fixtures -------------------- */
35 static HildonColorButton *color_button = NULL;
36 static GtkWidget *showed_window = NULL;
39 fx_setup_default_color_button()
42 gtk_init(&argc, NULL);
44 color_button = HILDON_COLOR_BUTTON(hildon_color_button_new());
45 /* Check that the color button object has been created properly */
47 showed_window = create_test_window ();
49 /* This packs the widget into the window (a gtk container). */
50 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (color_button));
52 /* Displays the widget and the window */
53 show_all_test_window (showed_window);
56 fail_if(!HILDON_IS_COLOR_BUTTON(color_button),
57 "hildon-color-button: Creation failed.");
62 fx_teardown_default_color_button()
65 /* Destroy the widget and the window */
66 gtk_widget_destroy(GTK_WIDGET(showed_window));
70 /* -------------------- Test cases -------------------- */
72 /* ----- Test case for set_color -----*/
74 * Purpose: Check that a regular color can be set safely
76 * - Set color defined by (255, 255, 255) and pixel = 255
77 * - Set color defined by (10, 20, 30) and pixel = 10
78 * - Set color defined by (20, 10, 30) and pixel = 10
79 * - Set color defined by (30, 10, 20) and pixel = 20
82 START_TEST (test_set_color_regular)
86 GdkColor * ret_color = g_new (GdkColor, 1);
92 b_color = gdk_color_copy(&color);
94 /* Test 1: Set color defined by (255,255,255)*/
101 b_color->green=green;
103 b_color->pixel=pixel;
105 hildon_color_button_set_color(color_button,b_color);
106 hildon_color_button_get_color(color_button, ret_color);
108 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
109 (blue != ret_color->blue) || (pixel != ret_color->pixel),
110 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
111 pixel, ret_color->red, ret_color->green,
112 ret_color->blue, ret_color->pixel);
114 /* Test 2: Set color defined by (10,20,30)*/
121 b_color->green=green;
123 b_color->pixel=pixel;
125 hildon_color_button_set_color(color_button,b_color);
126 hildon_color_button_get_color(color_button, ret_color);
128 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
129 (blue != ret_color->blue) || (pixel != ret_color->pixel),
130 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
131 pixel, ret_color->red, ret_color->green,
132 ret_color->blue, ret_color->pixel);
134 /* Test 3: Set color defined by (20,10,30)*/
141 b_color->green=green;
143 b_color->pixel=pixel;
145 hildon_color_button_set_color(color_button,b_color);
146 hildon_color_button_get_color(color_button, ret_color);
148 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
149 (blue != ret_color->blue) || (pixel != ret_color->pixel),
150 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
151 pixel, ret_color->red, ret_color->green,
152 ret_color->blue, ret_color->pixel);
154 /* Test 4: Set color defined by (30,10,20)*/
161 b_color->green=green;
163 b_color->pixel=pixel;
165 hildon_color_button_set_color(color_button,b_color);
166 hildon_color_button_get_color(color_button, ret_color);
168 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
169 (blue != ret_color->blue) || (pixel != ret_color->pixel),
170 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
171 pixel, ret_color->red, ret_color->green,
172 ret_color->blue, ret_color->pixel);
175 gdk_color_free(b_color);
178 gdk_color_free(ret_color);
183 * Purpose: Check that a limits values on color components can be set safely.
185 * - Set color defined by (0, 0, 0) and pixel = 0
186 * - Set color defined by (G_MAXUINT16, G_MAXUINT16, G_MAXUINT16) and pixel = G_MAXUINT32
187 * - Set color defined by (G_MAXUINT16, 0, 0) and pixel = G_MAXUINT32
188 * - Set color defined by (0, G_MAXUINT16, 0) and pixel = 0
189 * - Set color defined by (0, 0, G_MAXUINT16) and pixel = G_MAXUINT32
192 START_TEST (test_set_color_limits)
196 GdkColor * ret_color = g_new (GdkColor, 1);
202 b_color = gdk_color_copy(&color);
204 /* Test 1: Set color defined by (0,0,0)*/
211 b_color->green=green;
213 b_color->pixel=pixel;
215 hildon_color_button_set_color(color_button,b_color);
216 hildon_color_button_get_color(color_button, ret_color);
218 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
219 (blue != ret_color->blue) || (pixel != ret_color->pixel),
220 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
221 pixel, ret_color->red, ret_color->green,
222 ret_color->blue, ret_color->pixel);
224 /* Test 2: Set color defined by (G_MAXUINT16,G_MAXUINT16,G_MAXUINT16)*/
230 b_color->pixel=pixel;
232 b_color->green=green;
235 hildon_color_button_set_color(color_button,b_color);
236 hildon_color_button_get_color(color_button, ret_color);
238 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
239 (blue != ret_color->blue) || (pixel != ret_color->pixel),
240 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
241 pixel, ret_color->red, ret_color->green,
242 ret_color->blue, ret_color->pixel);
244 /* Test 3: Set color defined by (G_MAXUINT16,0,0)*/
251 b_color->green=green;
253 b_color->pixel=pixel;
255 hildon_color_button_set_color(color_button,b_color);
256 hildon_color_button_get_color(color_button, ret_color);
258 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
259 (blue != ret_color->blue) || (pixel != ret_color->pixel),
260 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
261 pixel, ret_color->red, ret_color->green,
262 ret_color->blue, ret_color->pixel);
264 /* Test 4: Set color defined by (0,G_MAXUINT16,0)*/
271 b_color->green=green;
273 b_color->pixel=pixel;
275 hildon_color_button_set_color(color_button,b_color);
276 hildon_color_button_get_color(color_button, ret_color);
278 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
279 (blue != ret_color->blue) || (pixel != ret_color->pixel),
280 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
281 pixel, ret_color->red, ret_color->green,
282 ret_color->blue, ret_color->pixel);
284 /* Test 5: Set color defined by (0,0,G_MAXUINT16)*/
291 b_color->green=green;
293 b_color->pixel=pixel;
295 hildon_color_button_set_color(color_button,b_color);
296 hildon_color_button_get_color(color_button, ret_color);
298 fail_if ((red != ret_color->red) || (green != ret_color->green) ||
299 (blue != ret_color->blue) || (pixel != ret_color->pixel),
300 "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d",
301 pixel, ret_color->red, ret_color->green,
302 ret_color->blue, ret_color->pixel);
305 gdk_color_free(b_color);
308 gdk_color_free(ret_color);
313 * Purpose: Check that a limits values on color components can be set safely.
315 * - Set color defined by (0, 0, 0) on NULL object.
316 * - Get color from NULL object.
317 * - Set color defined by (0, 0, 0) on GtkHBox object.
318 * - Get a color from GtkHBox object.
321 START_TEST (test_set_color_invalid)
325 GdkColor * ret_color = g_new (GdkColor, 1);
326 GtkWidget *aux_object = NULL;
331 b_color = gdk_color_copy(&color);
338 b_color->green=green;
342 /* Test 1: Set color defined by (0,0,0) on NULL object*/
343 hildon_color_button_set_color(NULL,b_color);
345 /* Test 2: Get color from NULL object*/
346 hildon_color_button_get_color(NULL, ret_color);
348 /* Test 3: Set color defined by (0, 0, 0) on GtkHBox object. */
349 aux_object = gtk_hbox_new (TRUE, 0);
350 hildon_color_button_set_color((HildonColorButton *) (aux_object), b_color);
351 gdk_color_free(b_color);
353 /* Test 4: Get color from GtkHBox object. */
355 ret_color->green = 99;
356 ret_color->blue = 99;
357 hildon_color_button_get_color((HildonColorButton *) (aux_object), ret_color);
359 if (ret_color->red != 99 ||
360 ret_color->green != 99 ||
361 ret_color->blue != 99)
363 gtk_widget_destroy(aux_object);
364 fail ("hildon-color-button: get_color must not modify the color when launched on invalid widget");
367 gtk_widget_destroy(aux_object);
371 /* ---------- Suite creation ---------- */
373 Suite *create_hildon_color_button_suite()
375 /* Create the suite */
376 Suite *s = suite_create("HildonColorButton");
378 /* Create test cases */
379 TCase *tc1 = tcase_create("set_color");
381 /* Create test case for hildon_color_button_set_color and add it to the suite */
382 tcase_add_checked_fixture(tc1, fx_setup_default_color_button, fx_teardown_default_color_button);
383 tcase_add_test(tc1, test_set_color_regular);
384 tcase_add_test(tc1, test_set_color_limits);
385 tcase_add_test(tc1, test_set_color_invalid);
386 suite_add_tcase(s, tc1);
388 /* Return created suite */