EFL 1.7 svn doobies
[profile/ivi/efreet.git] / src / tests / main.c
1 #include "Efreet.h"
2 /* no logging */
3 #define EFREET_MODULE_LOG_DOM
4 #include "efreet_private.h"
5 #include "Efreet_Mime.h"
6 #include "config.h"
7 #include <Ecore.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 int ef_cb_efreet_data_home(void);
13 int ef_cb_efreet_config_home(void);
14 int ef_cb_efreet_cache_home(void);
15 int ef_cb_efreet_data_dirs(void);
16 int ef_cb_efreet_config_dirs(void);
17 int ef_cb_efreet_icon_theme(void);
18 int ef_cb_efreet_icon_theme_list(void);
19 int ef_cb_efreet_icon_match(void);
20 int ef_cb_ini_parse(void);
21 int ef_cb_ini_long_line(void);
22 int ef_cb_ini_garbage(void);
23 #if DEFAULT_VISIBILITY
24 int ef_cb_locale(void);
25 #endif
26 int ef_cb_desktop_parse(void);
27 int ef_cb_desktop_save(void);
28 int ef_cb_desktop_command_get(void);
29 int ef_cb_desktop_type_parse(void);
30 #if 0
31 int ef_cb_desktop_file_id(void);
32 #endif
33 int ef_cb_menu_get(void);
34 int ef_cb_menu_with_slashes(void);
35 int ef_cb_menu_save(void);
36 #if 0
37 int ef_cb_menu_edit(void);
38 #endif
39 int ef_cb_utils(void);
40 int ef_mime_cb_get(void);
41
42 typedef struct Efreet_Test Efreet_Test;
43 struct Efreet_Test
44 {
45     char *name;
46     int (*cb)(void);
47 };
48
49 static Efreet_Test tests[] = {
50     {"Data Home", ef_cb_efreet_data_home},
51     {"Config Home", ef_cb_efreet_config_home},
52     {"Cache Home", ef_cb_efreet_cache_home},
53     {"Data Directories", ef_cb_efreet_data_dirs},
54     {"Config Directories", ef_cb_efreet_config_dirs},
55     {"Icon Theme Basic", ef_cb_efreet_icon_theme},
56     {"Icon Theme List", ef_cb_efreet_icon_theme_list},
57     {"Icon Matching", ef_cb_efreet_icon_match},
58     {"INI Parsing", ef_cb_ini_parse},
59     {"INI Long Line Parsing", ef_cb_ini_long_line},
60     {"INI Garbage Parsing", ef_cb_ini_garbage},
61 #if DEFAULT_VISIBILITY
62     {"Locale Parsing", ef_cb_locale},
63 #endif
64     {"Desktop Parsing", ef_cb_desktop_parse},
65     {"Desktop Type Parsing", ef_cb_desktop_type_parse},
66     {"Desktop Save", ef_cb_desktop_save},
67     {"Desktop Command", ef_cb_desktop_command_get},
68 #if 0
69     {"Desktop File ID", ef_cb_desktop_file_id},
70 #endif
71     {"Menu Parsing", ef_cb_menu_get},
72     {"Menu Incorrect Names", ef_cb_menu_with_slashes},
73     {"Menu Save", ef_cb_menu_save},
74 #if 0
75     {"Menu Edit", ef_cb_menu_edit},
76 #endif
77     {"Utils", ef_cb_utils},
78     {"Mime", ef_mime_cb_get},
79     {NULL, NULL}
80 };
81
82 extern char **environ;
83 static Eina_List *environment = NULL;
84
85 void
86 environment_store(void)
87 {
88     char *env;
89     char **e;
90 #ifdef HAVE_CLEARENV
91     EINA_LIST_FREE(environment, env)
92         free(env);
93     for (e = environ; *e; e++)
94         environment = eina_list_append(environment, strdup(*e));
95 #endif   
96 }
97
98 void
99 environment_restore(void)
100 {
101     Eina_List *l;
102     char *e;
103     if (!environment) return;
104 #ifdef HAVE_CLEARENV
105     clearenv();
106     EINA_LIST_FOREACH(environment, l, e)
107         putenv(e);
108 #endif
109 }
110
111 int
112 main(int argc, char ** argv)
113 {
114     int i, passed = 0, num_tests = 0;
115     Eina_List *run = NULL;
116     double total;
117     char *env;
118
119     eina_init();
120     ecore_init();
121
122     total = ecore_time_get();
123     if (argc > 1)
124     {
125         for (i = 1; i < argc; i++)
126         {
127             if ((!strcmp(argv[i], "-h")) ||
128                 (!strcmp(argv[i], "--help")))
129             {
130                 for (i = 0; tests[i].name; i++)
131                 {
132                     printf("%s\n", tests[i].name);
133                 }
134                 return 1;
135             }
136             run = eina_list_append(run, argv[i]);
137         }
138     }
139
140     efreet_cache_update = 0;
141     environment_store();
142     for (i = 0; tests[i].name; i++)
143     {
144         int ret;
145         double start;
146
147         /* we've been given specific tests and it isn't in the list */
148         if (run && !eina_list_search_unsorted(run, EINA_COMPARE_CB(strcasecmp),
149                                                         tests[i].name))
150             continue;
151
152         if (!efreet_init())
153         {
154             printf("Error initializing Efreet\n");
155             continue;
156         }
157
158         num_tests ++;
159
160         printf("%s:\t\t", tests[i].name);
161         fflush(stdout);
162         start = ecore_time_get();
163         ret = tests[i].cb();
164         printf("%s in %.3f seconds\n", (ret ? "PASSED" : "FAILED"),
165                                             ecore_time_get() - start);
166         passed += ret;
167
168         efreet_shutdown();
169         environment_restore();
170     }
171
172     printf("\n-----------------\n");
173 #ifdef HAVE_CLEARENV
174     clearenv();
175     EINA_LIST_FREE(environment, env)
176         free(env);
177 #endif    
178     printf("Passed %d of %d tests.\n", passed, num_tests);
179
180     while (run)
181         run = eina_list_remove_list(run, run);
182
183     printf("Total run: %.3f seconds\n", ecore_time_get() - total);
184
185     ecore_shutdown();
186     eina_shutdown();
187     return 0;
188 }