Adding the color button and color chooser examples. Fixing the color-returning functi...
[hildon] / tests / check_test.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
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.
10  *
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.
15  *
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
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <X11/Xlibint.h>
26 #include <gtk/gtk.h>
27 #include <check.h>
28 #include <gconf/gconf-client.h>
29
30 #include "test_suites.h"
31
32 /* Define environment checking results defines */
33 #define ENVIRONMENT_X_ERROR       1
34 #define ENVIRONMENT_MAEMO_ERROR   2
35 #define ENVIRONMENT_OK            3
36
37 /* This is used for the Gconf availability check */
38 #define GCONF_TEST_PATH "/hildon/tests/flag"
39
40 /* ------------------------ Helper functions ------------------------ */
41
42 /**
43  * Creates the list of suites to be run.
44  */
45 static SRunner *
46 configure_tests(gint environment)
47 {
48   SRunner *sr;
49   
50   /* Create srunner object with the first test suite */
51   sr = srunner_create(create_hildon_range_editor_suite());
52   srunner_add_suite(sr, create_hildon_number_editor_suite());
53   srunner_add_suite(sr, create_hildon_time_editor_suite());
54   srunner_add_suite(sr, create_hildon_time_picker_suite());
55   srunner_add_suite(sr, create_hildon_date_editor_suite());
56   srunner_add_suite(sr, create_hildon_weekday_picker_suite());
57   srunner_add_suite(sr, create_hildon_controlbar_suite());
58   srunner_add_suite(sr, create_hildon_color_button_suite());
59   srunner_add_suite(sr, create_hildon_color_chooser_suite());
60   srunner_add_suite(sr, create_hildon_seekbar_suite());
61   /* srunner_add_suite(sr, create_hildon_dialoghelp_suite()); */
62   srunner_add_suite(sr, create_hildon_calendar_popup_suite());
63   srunner_add_suite(sr, create_hildon_caption_suite());
64   srunner_add_suite(sr, create_hildon_defines_suite());
65   srunner_add_suite(sr, create_hildon_find_toolbar_suite());
66   /* srunner_add_suite(sr, create_hildon_name_password_dialog_suite());
67   srunner_add_suite(sr, create_hildon_get_password_dialog_suite());
68   srunner_add_suite(sr, create_hildon_set_password_dialog_suite()); */
69   srunner_add_suite(sr, create_hildon_sort_dialog_suite());
70   srunner_add_suite(sr, create_hildon_code_dialog_suite());
71   srunner_add_suite(sr, create_hildon_note_suite());
72   srunner_add_suite(sr, create_hildon_volumebar_suite());
73   srunner_add_suite(sr, create_hildon_volumebar_range_suite());
74   srunner_add_suite(sr, create_hildon_wizard_dialog_suite());
75   /* srunner_add_suite(sr, create_hildon_scroll_area_suite()); */
76   srunner_add_suite(sr, create_hildon_banner_suite());
77   srunner_add_suite(sr, create_hildon_font_selection_dialog_suite());
78   srunner_add_suite(sr, create_hildon_window_suite());
79   srunner_add_suite(sr, create_hildon_composite_widget_suite());
80
81   /* Disable tests that need maemo environment to be up if it is not running */
82   if (environment != ENVIRONMENT_MAEMO_ERROR)
83     {
84       /* srunner_add_suite(sr, create_hildon_system_sound_suite()); */
85       /* srunner_add_suite(sr, create_hildon_color_selector_suite()); */
86       srunner_add_suite(sr, create_hildon_program_suite());
87     }
88  
89   return sr;
90 }
91
92
93 /**
94  * Checks environment configuration for tests execution
95  */
96 static gint 
97 check_environment()
98 {
99   Display *display = NULL;
100   GConfClient *client = NULL;
101   GError *gconf_error = NULL;
102
103   /* Check X server availability */
104   if ((display = XOpenDisplay(NULL)) == NULL)
105     return ENVIRONMENT_X_ERROR;
106   else
107     XCloseDisplay(display);
108
109   /* Check maemo environment is up. We do this checking gconf is available */
110   g_type_init();
111   client = gconf_client_get_default();
112   gconf_client_get(client, GCONF_TEST_PATH ,&gconf_error);
113   if (gconf_error)
114     return ENVIRONMENT_MAEMO_ERROR;
115
116   /* Environment is ok */
117   return ENVIRONMENT_OK;
118 }
119
120 /**
121  * --------------------------------------------------------------------------
122  * Main program
123  * --------------------------------------------------------------------------
124  */
125 int main(void)
126 {
127   int nf = 0;
128   gint environment = 0;
129
130   /* Show test start header */
131   printf("\n");
132   printf("******************************************************************\n");
133   printf(" Executing hildon-libs unit tests.... \n");
134   printf("******************************************************************\n\n");
135
136   /* Check environment is ok to run the tests */
137   environment = check_environment();
138   if (environment == ENVIRONMENT_X_ERROR)
139     {
140       printf("\n-------------------------- ERROR ------------------------------------");
141       printf("\nNo X server found. Check you have an X server up and running and the");
142       printf("\nDISPLAY environment variable set properly.");
143       printf("\n---------------------------------------------------------------------\n");
144       return EXIT_FAILURE;
145     }
146   else if (environment == ENVIRONMENT_MAEMO_ERROR)
147     {
148       printf("\n------------------------- WARNING -----------------------------------");
149       printf("\nMaemo environment is not running. Some tests that depend on Gconf and");
150       printf("\nDbus will be disabled. To fix this you should startup the environment");
151       printf("\nexecuting \"af-sb-init.sh start\" before running the tests.");
152       printf("\n---------------------------------------------------------------------\n");
153     }
154
155   /* Configure test suites to be executed */
156   SRunner *sr = configure_tests(environment);
157
158   /* Run tests */
159   srunner_run_all(sr, CK_NORMAL);//CK_VERBOSE);
160
161   /* Retrieve number of failed tests */
162   nf = srunner_ntests_failed(sr);
163
164   /* Free resouces */
165   srunner_free(sr);
166
167   /* Return global success or failure */
168   return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 
169 }