eet-cxx: add implementation for eet C++.
[platform/upstream/efl.git] / src / tests / eet_cxx / eet_cxx_suite.cc
1
2 #include "Eet.hh"
3 #include <Eina.h>
4
5 #include <cassert>
6 #include <algorithm>
7
8 #include <check.h>
9
10 void eet_test_descriptors(TCase* tc);
11
12 typedef struct _Eet_Test_Case Eet_Test_Case;
13 struct _Eet_Test_Case
14 {
15    const char *test_case;
16    void (*build)(TCase *tc);
17 };
18
19 static const Eet_Test_Case etc[] = {
20    { "Descriptors", eet_test_descriptors },
21    { NULL, NULL }
22 };
23
24 static void
25 _list_tests(void)
26 {
27    const Eet_Test_Case *itr = etc;
28       fputs("Available Test Cases:\n", stderr);
29    for (; itr->test_case; itr++)
30       fprintf(stderr, "\t%s\n", itr->test_case);
31 }
32
33 static Eina_Bool
34 _use_test(int argc, const char **argv, const char *test_case)
35 {
36    if (argc < 1)
37       return 1;
38
39    for (; argc > 0; argc--, argv++)
40       if (strcmp(test_case, *argv) == 0)
41          return 1;
42
43    return 0;
44 }
45
46 Suite *
47 eet_build_suite(int argc, const char **argv)
48 {
49    TCase *tc;
50    Suite *s;
51    int i;
52
53    s = suite_create("Eet C++");
54
55    for (i = 0; etc[i].test_case; ++i)
56      {
57         if (!_use_test(argc, argv, etc[i].test_case))
58            continue;
59
60         tc = tcase_create(etc[i].test_case);
61         tcase_set_timeout(tc, 0);
62
63         etc[i].build(tc);
64         suite_add_tcase(s, tc);
65      }
66
67    return s;
68 }
69
70 int main(int argc, char* argv[])
71 {
72    Suite *s;
73    SRunner *sr;
74    int i, failed_count;
75
76    for (i = 1; i < argc; i++)
77       if ((strcmp(argv[i], "-h") == 0) ||
78           (strcmp(argv[i], "--help") == 0))
79         {
80            fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
81                    argv[0]);
82            _list_tests();
83            return 0;
84         }
85       else if ((strcmp(argv[i], "-l") == 0) ||
86                (strcmp(argv[i], "--list") == 0))
87         {
88            _list_tests();
89            return 0;
90         }
91
92    putenv(const_cast<char*>("EFL_RUN_IN_TREE=1"));
93
94    s = eet_build_suite(argc - 1, (const char **)argv + 1);
95    sr = srunner_create(s);
96
97    srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
98
99    srunner_run_all(sr, CK_ENV);
100    failed_count = srunner_ntests_failed(sr);
101    srunner_free(sr);
102
103    return (failed_count == 0) ? 0 : 255;
104 }