Eo: add autotools tests. I have plenty of errors with the unit tests on Windows
[profile/ivi/eobj.git] / src / tests / eo_suite / eo_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 "Eo.h"
9 #include "eo_suite.h"
10
11 typedef struct _Eo_Test_Case Eo_Test_Case;
12
13 struct _Eo_Test_Case
14 {
15    const char *test_case;
16    void      (*build)(TCase *tc);
17 };
18
19 static const Eo_Test_Case etc[] = {
20   { "Eo init", eo_test_init },
21   { "Eo general", eo_test_general },
22   { "Eo class errors", eo_test_class_errors },
23   { NULL, NULL }
24 };
25
26 static void
27 _list_tests(void)
28 {
29   const Eo_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 static Eina_Bool
37 _use_test(int argc, const char **argv, const char *test_case)
38 {
39    if (argc < 1)
40      return 1;
41
42    for (; argc > 0; argc--, argv++)
43      if (strcmp(test_case, *argv) == 0)
44        return 1;
45    return 0;
46 }
47
48 static Suite *
49 eo_suite_build(int argc, const char **argv)
50 {
51    TCase *tc;
52    Suite *s;
53    int i;
54
55    s = suite_create("Eo");
56
57    for (i = 0; etc[i].test_case; ++i)
58      {
59         if (!_use_test(argc, argv, etc[i].test_case)) continue;
60         tc = tcase_create(etc[i].test_case);
61
62         etc[i].build(tc);
63
64         suite_add_tcase(s, tc);
65         tcase_set_timeout(tc, 0);
66      }
67
68    return s;
69 }
70
71 int
72 main(int argc, char **argv)
73 {
74    Suite *s;
75    SRunner *sr;
76    int i, failed_count;
77    eo_init();
78    setenv("CK_FORK", "no", 0);
79
80    for (i = 1; i < argc; i++)
81      if ((strcmp(argv[i], "-h") == 0) ||
82          (strcmp(argv[i], "--help") == 0))
83        {
84           fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
85                   argv[0]);
86           _list_tests();
87           return 0;
88        }
89      else if ((strcmp(argv[i], "-l") == 0) ||
90               (strcmp(argv[i], "--list") == 0))
91        {
92           _list_tests();
93           return 0;
94        }
95
96    s = eo_suite_build(argc - 1, (const char **)argv + 1);
97    sr = srunner_create(s);
98
99    srunner_run_all(sr, CK_ENV);
100    failed_count = srunner_ntests_failed(sr);
101    srunner_free(sr);
102
103    eo_shutdown();
104
105    return (failed_count == 0) ? 0 : 255;
106 }