Added support for Instant Messaging, fixed mem leaks, documentation.
[libgcal.git] / utests / utest.c
blob3a0b3e65d5b55934f02752cb7e276d9c1c662be0
1 /**
2 * @file utest.c
3 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
4 * @date Mon Mar 3 20:14:13 2008
6 * @brief Unit test module.
8 * All units goes here (they are useful to help refine the API of library
9 * and also provide a way to validate/document the code).
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
16 #include <check.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include "utest_gcal.h"
20 #include "utest_xpath.h"
21 #include "utest_edit.h"
22 #include "utest_contact.h"
23 #include "utest_debug.h"
24 #include "utest_query.h"
25 #include "utest_userapi.h"
26 #include "utest_xmlmode.h"
27 #include "utest_screw.h"
29 static Suite *core_suite(void)
31 char *test_var;
32 Suite *s;
34 s = suite_create("core");
35 test_var = getenv("GCALTEST");
37 if (test_var) {
38 if (!(strcmp(test_var, "gcal")))
39 suite_add_tcase(s, gcal_tcase_create());
40 else if (!(strcmp(test_var, "xpath")))
41 suite_add_tcase(s, xpath_tcase_create());
42 else if (!(strcmp(test_var, "edit")))
43 suite_add_tcase(s, edit_tcase_create());
44 else if (!(strcmp(test_var, "contact")))
45 suite_add_tcase(s, gcontact_tcase_create());
46 else if (!(strcmp(test_var, "debug")))
47 suite_add_tcase(s, gcaldebug_tcase_create());
48 else if (!(strcmp(test_var, "query")))
49 suite_add_tcase(s, gcal_query_tcase_create());
50 else
51 goto all;
53 goto exit;
56 all:
57 suite_add_tcase(s, gcal_tcase_create());
58 suite_add_tcase(s, xpath_tcase_create());
59 suite_add_tcase(s, edit_tcase_create());
60 suite_add_tcase(s, gcontact_tcase_create());
61 suite_add_tcase(s, gcaldebug_tcase_create());
62 suite_add_tcase(s, gcal_query_tcase_create());
63 exit:
64 return s;
68 static Suite *user_api(void)
70 Suite *s;
71 s = suite_create("userapi");
72 suite_add_tcase(s, gcal_userapi());
73 return s;
76 static Suite *xml_api(void)
78 Suite *s;
79 s = suite_create("xmlapi");
80 suite_add_tcase(s, xmlmode_tcase_create());
81 return s;
85 static Suite *screw_api(void)
87 Suite *s;
88 s = suite_create("screwapi");
89 suite_add_tcase(s, gcal_screw());
90 return s;
94 static void run_and_clean(SRunner *runner)
96 /* TODO: use it to determine exit status */
97 int number_failed;
98 if (!runner)
99 return;
101 srunner_run_all(runner, CK_VERBOSE);
102 number_failed = srunner_ntests_failed(runner);
103 srunner_free(runner);
107 int main(void)
109 char *env_var;
110 Suite *s, *sapi, *sxml, *s_screw;
111 SRunner *core, *userapi, *xmlapi, *screwtest;
113 s = sapi = sxml = s_screw = NULL;
114 core = userapi = xmlapi = screwtest = NULL;
116 env_var = getenv("GCAL");
117 if (env_var) {
118 if (!strcmp("core", env_var)) {
119 /* Core internals */
120 s = core_suite();
121 core = srunner_create(s);
122 } else if(!strcmp("user", env_var)) {
123 sapi = user_api();
124 userapi = srunner_create(sapi);
125 /* I will not fork the userapi, since I need to
126 * save a variable
127 * between each running test.
129 srunner_set_fork_status(userapi, CK_NOFORK);
131 } else if (!strcmp("xml", env_var)) {
132 /* This one tests for XML api mode */
133 sxml = xml_api();
134 xmlapi = srunner_create(sxml);
135 } else if (!strcmp("screw", env_var)) {
136 /* Tests trying to break libgcal */
137 s_screw = screw_api();
138 screwtest = srunner_create(s_screw);
140 } else { /* Run all tests */
141 s = core_suite();
142 core = srunner_create(s);
144 sapi = user_api();
145 userapi = srunner_create(sapi);
146 srunner_set_fork_status(userapi, CK_NOFORK);
148 sxml = xml_api();
149 xmlapi = srunner_create(sxml);
151 s_screw = screw_api();
152 screwtest = srunner_create(s_screw);
155 run_and_clean(core);
156 run_and_clean(userapi);
157 run_and_clean(xmlapi);
158 run_and_clean(screwtest);
160 /* TODO: use number of failures to decide exit status, it can
161 * be either EXIT_FAILURE or ...
163 return EXIT_SUCCESS;