Changing the license headers and all the licesing stuff to LGPL version 2 OR LATER.
[hildon] / tests / check-hildon-helper.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
25 #include <stdlib.h>
26 #include <check.h>
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtklabel.h>
29 #include "test_suites.h"
30 #include "hildon-helper.h"
31
32 /* -------------------- Fixtures -------------------- */
33
34 static void 
35 fx_setup_default_helper ()
36 {
37   int argc = 0;
38
39   gtk_init(&argc, NULL);
40 }
41
42 static void 
43 fx_teardown_default_helper ()
44 {
45 }
46 /* -------------------- Test cases -------------------- */
47
48 /* ----- Test case for hildon_helper_set_logical_font -----*/
49
50 /**
51  * Purpose: test setting a new logical font to a GtkWidget
52  * Cases considered:
53  *    - Set the font name "TimesNewRoman"
54  */
55 START_TEST (test_hildon_helper_set_logical_font_regular)
56 {
57   GtkWidget *label = NULL;
58   gulong signum = G_MAXULONG;
59
60   label = gtk_label_new ("test label");
61
62   signum = hildon_helper_set_logical_font (label, "TimesNewRoman");
63   gtk_widget_destroy (GTK_WIDGET (label));
64
65   fail_if (signum <= 0,
66            "hildon-helper: the returned signal id is %ul and should be > 0",
67            signum);
68 }
69 END_TEST
70
71 /**
72  * Purpose: test setting a logical font with invalid parameters
73  * Cases considered:
74  *    - Set the font name "TimesNewRoman" to a NULL Widget
75  *    - Set a NULL font name to a valid Widget
76  */
77 START_TEST (test_hildon_helper_set_logical_font_invalid)
78 {
79   GtkWidget *label = NULL;
80   gulong signum = G_MAXULONG;
81
82   /* Test 1 */
83   signum = hildon_helper_set_logical_font (NULL, "TimesNewRoman");
84   fail_if (signum != 0,
85            "hildon-helper: the returned signal id is %ul and should be 0",
86            signum);
87
88   /* Test 2 */
89   label = gtk_label_new ("test label");
90
91   signum = hildon_helper_set_logical_font (label, NULL);
92   gtk_widget_destroy (GTK_WIDGET (label));
93
94   fail_if (signum != 0,
95            "hildon-helper: the returned signal id is %ul and should be 0",
96            signum);
97 }
98 END_TEST
99
100
101 /* ----- Test case for hildon_helper_set_logical_color -----*/
102
103 /**
104  * Purpose: test setting a new logical color to a GtkWidget
105  * Cases considered:
106  *    - Set the logical color "Blue"
107  */
108 START_TEST (test_hildon_helper_set_logical_color_regular)
109 {
110   GtkWidget *label = NULL;
111   gulong signum = G_MAXULONG;
112
113   label = gtk_label_new ("test label");
114
115   signum = hildon_helper_set_logical_color (label, 
116                                                 GTK_RC_BG, 
117                                                 GTK_STATE_NORMAL, 
118                                                 "Blue");
119   gtk_widget_destroy (GTK_WIDGET (label));
120
121   fail_if (signum <= 0,
122            "hildon-helper: the returned signal id is %ul and should be > 0",
123            signum);
124 }
125 END_TEST
126
127 /**
128  * Purpose: test setting a logical color with invalid parameters
129  * Cases considered:
130  *    - Set the color name "Blue" to a NULL Widget
131  *    - Set a NULL color name to a valid Widget
132  */
133 START_TEST (test_hildon_helper_set_logical_color_invalid)
134 {
135   GtkWidget *label = NULL;
136   gulong signum = G_MAXULONG;
137
138   /* Test 1 */
139   signum = hildon_helper_set_logical_color (NULL,
140                                                 GTK_RC_BG, 
141                                                 GTK_STATE_NORMAL, 
142                                                 "Blue");
143   fail_if (signum != 0,
144            "hildon-helper: the returned signal id is %ul and should be 0",
145            signum);
146
147   /* Create the widget */
148   label = gtk_label_new ("test label");
149
150   /* Test 2 */
151   signum = hildon_helper_set_logical_color (label,
152                                                 GTK_RC_BG, 
153                                                 GTK_STATE_NORMAL, 
154                                                 NULL);
155   gtk_widget_destroy (GTK_WIDGET (label));
156
157   fail_if (signum != 0,
158            "hildon-helper: the returned signal id is %ul and should be 0",
159            signum);
160 }
161 END_TEST
162
163
164
165 /* ---------- Suite creation ---------- */
166
167 Suite *create_hildon_helper_suite()
168 {
169   /* Create the suite */
170   Suite *s = suite_create("Hildonhelper");
171
172   /* Create test cases */
173   TCase *tc1 = tcase_create("hildon_helper_set_logical_font");
174   TCase *tc2 = tcase_create("hildon_helper_set_logical_color");
175
176   /* Create test case for set_logical_font and add it to the suite */
177   tcase_add_checked_fixture(tc1, fx_setup_default_helper, fx_teardown_default_helper);
178   tcase_add_test(tc1, test_hildon_helper_set_logical_font_regular);
179   tcase_add_test(tc1, test_hildon_helper_set_logical_font_invalid);
180   suite_add_tcase (s, tc1);
181
182   /* Create test case for set_logical_color and add it to the suite */
183   tcase_add_checked_fixture(tc2, fx_setup_default_helper, fx_teardown_default_helper);
184   tcase_add_test(tc2, test_hildon_helper_set_logical_color_regular);
185   tcase_add_test(tc2, test_hildon_helper_set_logical_color_invalid);
186   suite_add_tcase (s, tc2);
187
188   /* Return created suite */
189   return s;             
190 }