2 * EGLib Unit Test Driver
5 * Aaron Bockover (abockover@novell.com)
7 * (C) 2006 Novell, Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 #if defined(HAVE_UNISTD_H)
41 #define DRIVER_NAME "EGlib"
44 typedef struct _StringArray
{
50 string_array_append(StringArray
*array
, gchar
*string
)
53 array
= g_new0(StringArray
, 1);
55 array
->strings
= g_malloc(sizeof(gchar
*) * 2);
58 array
->strings
= g_realloc(array
->strings
, sizeof(gchar
*)
59 * (array
->length
+ 1));
62 array
->strings
[array
->length
- 1] = string
;
63 array
->strings
[array
->length
] = NULL
;
68 gint global_passed
= 0, global_tests
= 0;
71 string_array_free(StringArray
*array
)
73 g_free(array
->strings
);
77 static void print_help(char *s
)
81 printf("Usage: %s [OPTION]... [TESTGROUP]...\n\n", s
);
82 printf("OPTIONS are:\n");
83 printf(" -h, --help show this help\n");
84 printf(" -t, --time time the tests\n");
85 printf(" -i, --iterations number of times to run tests\n");
86 printf(" -q, --quiet do not print test results; "
87 "final time always prints\n");
88 printf(" -n, --no-labels print final time without labels, "
89 "nice for scripts\n");
90 printf(" -d, --debug do not run tests, "
91 "debug the driver itself for valgrind\n\n");
92 printf("TESTGROUPS available:\n");
94 for(i
= 0; test_groups
[i
].name
!= NULL
; i
++) {
95 if(test_groups
[i
].handler
!= fake_tests_init
) {
96 printf(" %s\n", test_groups
[i
].name
);
103 gint
main(gint argc
, gchar
**argv
)
105 gint i
, j
, c
, iterations
= 1;
106 StringArray
*tests_to_run
= NULL
;
108 gboolean report_time
= FALSE
;
109 gboolean quiet
= FALSE
;
110 gboolean global_failure
= FALSE
;
111 gboolean no_final_time_labels
= FALSE
;
112 gboolean debug
= FALSE
;
114 static struct option long_options
[] = {
115 {"help", no_argument
, 0, 'h'},
116 {"time", no_argument
, 0, 't'},
117 {"quiet", no_argument
, 0, 'q'},
118 {"iterations", required_argument
, 0, 'i'},
119 {"debug", no_argument
, 0, 'd'},
120 {"no-labels", no_argument
, 0, 'n'},
124 while((c
= getopt_long(argc
, argv
, "dhtqni:", long_options
, NULL
)) != -1) { switch(c
) {
132 iterations
= atoi(optarg
);
138 no_final_time_labels
= TRUE
;
146 for(i
= optind
; i
< argc
; i
++) {
147 if(argv
[i
][0] == '-') {
151 tests_to_run
= string_array_append(tests_to_run
, argv
[i
]);
154 time_start
= get_timestamp();
156 for(j
= 0; test_groups
[j
].name
!= NULL
; j
++) {
161 if(tests_to_run
!= NULL
) {
165 for(k
= 0; k
< tests_to_run
->length
; k
++) {
166 gchar
*user
= tests_to_run
->strings
[k
];
167 const gchar
*table
= test_groups
[j
].name
;
168 size_t user_len
= strlen(user
);
169 size_t table_len
= strlen(table
);
171 if(strncmp(user
, table
, table_len
) == 0) {
172 if(user_len
> table_len
&& user
[table_len
] != ':') {
177 group
= tests_to_run
->strings
[k
];
185 gchar
**split
= NULL
;
187 if(debug
&& test_groups
[j
].handler
!= fake_tests_init
) {
188 printf("Skipping %s, in driver debug mode\n",
189 test_groups
[j
].name
);
191 } else if(!debug
&& test_groups
[j
].handler
== fake_tests_init
) {
196 split
= eg_strsplit(group
, ":", -1);
199 for(m
= 0; split
[m
] != NULL
; m
++) {
201 tests
= strdup(split
[m
]);
209 passed
= run_group(&(test_groups
[j
]),
210 iterations
, quiet
, report_time
, tests
);
216 if(!passed
&& !global_failure
) {
217 global_failure
= TRUE
;
223 gdouble pass_percentage
= ((gdouble
)global_passed
/ (gdouble
)global_tests
) * 100.0;
224 printf("=============================\n");
225 printf("Overall result: %s : %d / %d (%g%%)\n", global_failure
? "FAILED" : "OK", global_passed
, global_tests
, pass_percentage
);
229 gdouble duration
= get_timestamp() - time_start
;
230 if(no_final_time_labels
) {
231 printf("%g\n", duration
);
233 printf("%s Total Time: %g\n", DRIVER_NAME
, duration
);
237 if(tests_to_run
!= NULL
) {
238 string_array_free(tests_to_run
);
241 return global_tests
- global_passed
;