EFL 1.7 svn doobies
[profile/ivi/efreet.git] / src / tests / efreet_suite.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <stdlib.h>
6 #include <stdio.h>
7
8 #include <Efreet.h>
9
10 #include "efreet_suite.h"
11
12 typedef struct _Efreet_Test_Case Efreet_Test_Case;
13
14 struct _Efreet_Test_Case
15 {
16    const char *test_case;
17    void      (*build)(TCase *tc);
18 };
19
20 static const Efreet_Test_Case etc[] = {
21   { "Efreet", efreet_test_efreet },
22   { "Efreet Cache", efreet_test_efreet_cache },
23   { NULL, NULL }
24 };
25
26 static void
27 _list_tests(void)
28 {
29   const Efreet_Test_Case *itr;
30
31    itr = etc;
32    fputs("Available Test Cases:\n", stderr);
33    for (; itr->test_case; itr++)
34      fprintf(stderr, "\t%s\n", itr->test_case);
35 }
36
37 static Eina_Bool
38 _use_test(int argc, const char **argv, const char *test_case)
39 {
40    if (argc < 1)
41      return 1;
42
43    for (; argc > 0; argc--, argv++)
44      if (strcmp(test_case, *argv) == 0)
45        return 1;
46    return 0;
47 }
48
49 static Suite *
50 efreet_suite_build(int argc, const char **argv)
51 {
52    TCase *tc;
53    Suite *s;
54    int i;
55
56    s = suite_create("Efreet");
57
58    for (i = 0; etc[i].test_case; ++i)
59      {
60         if (!_use_test(argc, argv, etc[i].test_case)) continue;
61         tc = tcase_create(etc[i].test_case);
62
63         etc[i].build(tc);
64
65         suite_add_tcase(s, tc);
66         tcase_set_timeout(tc, 0);
67      }
68
69    return s;
70 }
71
72 int
73 main(int argc, char **argv)
74 {
75    Suite *s;
76    SRunner *sr;
77    int i, failed_count;
78
79    for (i = 1; i < argc; i++)
80      if ((strcmp(argv[i], "-h") == 0) ||
81          (strcmp(argv[i], "--help") == 0))
82        {
83           fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
84                   argv[0]);
85           _list_tests();
86           return 0;
87        }
88      else if ((strcmp(argv[i], "-l") == 0) ||
89               (strcmp(argv[i], "--list") == 0))
90        {
91           _list_tests();
92           return 0;
93        }
94
95    s = efreet_suite_build(argc - 1, (const char **)argv + 1);
96    sr = srunner_create(s);
97
98    srunner_run_all(sr, CK_NORMAL);
99    failed_count = srunner_ntests_failed(sr);
100    srunner_free(sr);
101
102    return (failed_count == 0) ? 0 : 255;
103 }