Ensure HildonAppMenu size is correct after rotation
[hildon] / tests / check-hildon-color-chooser.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24 #include <stdlib.h>
25 #include <check.h>
26 #include <gtk/gtkmain.h>
27 #include <glib/gprintf.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30
31 #include <hildon/hildon-color-chooser.h>
32 #include <hildon/hildon-window.h>
33
34 #define MAX_COLOR 65535
35
36 /* -------------------- Fixtures -------------------- */
37 static HildonColorChooser *color_chooser = NULL;
38 static GtkWindow * cs_window;
39
40 static void 
41 fx_setup_default_color_chooser ()
42 {
43   int argc = 0;
44   gtk_init(&argc, NULL);
45   
46   cs_window = GTK_WINDOW(create_test_window());
47
48   /* Check window object has been created properly */
49   fail_if(!HILDON_IS_WINDOW(cs_window),
50          "hildon-color-chooser: Window creation failed.");  
51
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.");  
56
57   gtk_container_add (GTK_CONTAINER(cs_window), GTK_WIDGET (color_chooser));
58
59   show_all_test_window(GTK_WIDGET(cs_window));
60   show_all_test_window(GTK_WIDGET(color_chooser));
61
62 }
63
64 static void 
65 fx_teardown_default_color_chooser ()
66 {    
67   gtk_widget_destroy (GTK_WIDGET (color_chooser)); 
68   gtk_widget_destroy (GTK_WIDGET (cs_window));
69  
70 }
71
72 /* -------------------- Test cases -------------------- */
73
74 /* ----- Test case for set_color -----*/
75
76 /**
77  * Purpose: Check that regular base colors are set and get properly
78  * Cases considered:
79  *    - Set the color #33CC33.
80  */
81 START_TEST (test_set_color_regular)
82 {
83   GdkColor color;
84   GdkColor * b_color;
85   GdkColor * ret_color = g_new (GdkColor, 1);    
86    
87   /* Test 1: Set the color #33CC33*/
88   gdk_color_parse( "#33CC33", &color);
89   b_color = gdk_color_copy(&color);
90
91   hildon_color_chooser_set_color(color_chooser,b_color);
92   hildon_color_chooser_get_color(color_chooser, ret_color);    
93
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);
99
100   if (b_color)
101     gdk_color_free(b_color);
102
103   if (ret_color)
104     gdk_color_free(ret_color);
105 }
106 END_TEST
107
108 /**
109  * Purpose: Check that limits base colors are set and get properly
110  * Cases considered:
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.
115  */
116 START_TEST (test_set_color_limits)
117 {
118   GdkColor color;
119   GdkColor * b_color;
120   GdkColor * ret_color = g_new (GdkColor, 1);
121
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.");   
125     
126   /* Test 1: Set the color #000000 */
127   gdk_color_parse( "#000000", &color);
128   b_color = gdk_color_copy(&color);
129
130   hildon_color_chooser_set_color(color_chooser,b_color);
131   hildon_color_chooser_get_color(color_chooser, ret_color);    
132
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);
138
139   gdk_color_free(b_color);
140
141
142   /* Test 2: Set the color #FFFFFF */
143   gdk_color_parse( "#000000", &color);
144   b_color = gdk_color_copy(&color);
145
146   hildon_color_chooser_set_color(color_chooser,b_color);
147   hildon_color_chooser_get_color(color_chooser, ret_color);    
148
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);
154
155   gdk_color_free(b_color);
156
157
158   /* Test 3: Set the color #FF0000 */
159   gdk_color_parse( "#FF0000", &color);
160   b_color = gdk_color_copy(&color);
161
162   hildon_color_chooser_set_color(color_chooser,b_color);
163   hildon_color_chooser_get_color(color_chooser, ret_color);    
164
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);
170
171   gdk_color_free(b_color);
172
173   /* Test 4: Set the color to #0000FF*/
174   gdk_color_parse( "#0000FF", &color);
175   b_color = gdk_color_copy(&color);
176
177   hildon_color_chooser_set_color(color_chooser,b_color);
178   hildon_color_chooser_get_color(color_chooser, ret_color);    
179
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);
185
186   if (b_color)
187     gdk_color_free(b_color);
188
189   if (ret_color)
190     gdk_color_free(ret_color);
191 }
192 END_TEST
193 /**
194  * Purpose: Check that invalid base colors are set and get properly
195  * Cases considered:
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.
200  */
201 START_TEST (test_set_color_invalid)
202 {
203   GdkColor color;
204   GdkColor * b_color;
205   GdkColor * ret_color = g_new (GdkColor, 1);
206   guint red;
207   guint green;
208   guint blue;
209
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.");
213    
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);
217
218   hildon_color_chooser_set_color(color_chooser,b_color);
219   gdk_color_free(b_color);
220
221
222   /* Test 1: Set the color (65536,65536,65536)*/
223   gdk_color_parse( "#000000", &color);
224   b_color = gdk_color_copy(&color);
225   red = MAX_COLOR+1;
226   green = MAX_COLOR+1;
227   blue = MAX_COLOR+1;
228     
229   b_color->red=red;
230   b_color->green=green;
231   b_color->blue=blue;
232     
233   hildon_color_chooser_set_color(color_chooser,b_color);
234   hildon_color_chooser_get_color(color_chooser, ret_color);    
235
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,
239            0, 0, 0);
240     
241   /* Test 2: Set the color NULL on color chooser*/
242   hildon_color_chooser_set_color(color_chooser,NULL);
243
244   /* Test 3: Set the color on NULL object*/
245   hildon_color_chooser_set_color(NULL,b_color);
246
247   /* Test 4: Get color from NULL object*/
248   hildon_color_chooser_get_color(NULL, ret_color);
249
250   if (b_color)
251     gdk_color_free(b_color);
252
253   if (ret_color)
254     gdk_color_free(ret_color);
255 }
256 END_TEST
257
258
259 /* ---------- Suite creation ---------- */
260
261 Suite *create_hildon_color_chooser_suite()
262 {
263   /* Create the suite */
264   Suite *s = suite_create("HildonColorChooser");
265
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);
273
274   /* Return created suite */
275   return s;             
276 }