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