diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/tests/eina_suite.c | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_suite.c b/libraries/eina/src/tests/eina_suite.c new file mode 100644 index 0000000..9b748fc --- /dev/null +++ b/libraries/eina/src/tests/eina_suite.c | |||
@@ -0,0 +1,177 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include "eina_suite.h" | ||
24 | #include "Eina.h" | ||
25 | #include <stdio.h> | ||
26 | #include <string.h> | ||
27 | |||
28 | typedef struct _Eina_Test_Case Eina_Test_Case; | ||
29 | struct _Eina_Test_Case | ||
30 | { | ||
31 | const char *test_case; | ||
32 | void (*build)(TCase *tc); | ||
33 | }; | ||
34 | |||
35 | static const Eina_Test_Case etc[] = { | ||
36 | { "FixedPoint", eina_test_fp }, | ||
37 | { "Array", eina_test_array }, | ||
38 | { "Binary Share", eina_test_binshare }, | ||
39 | { "String Share", eina_test_stringshare }, | ||
40 | { "UString Share", eina_test_ustringshare }, | ||
41 | { "Log", eina_test_log }, | ||
42 | { "Error", eina_test_error }, | ||
43 | { "Magic", eina_test_magic }, | ||
44 | { "Inlist", eina_test_inlist }, | ||
45 | { "Lazy alloc", eina_test_lalloc }, | ||
46 | { "Main", eina_test_main }, | ||
47 | { "Counter", eina_test_counter }, | ||
48 | { "Hash", eina_test_hash }, | ||
49 | { "List", eina_test_list }, | ||
50 | { "CList", eina_test_clist }, | ||
51 | { "Iterator", eina_test_iterator }, | ||
52 | { "Accessor", eina_test_accessor }, | ||
53 | { "Module", eina_test_module }, | ||
54 | { "Convert", eina_test_convert }, | ||
55 | { "Rbtree", eina_test_rbtree }, | ||
56 | { "File", eina_test_file }, | ||
57 | { "Benchmark", eina_test_benchmark }, | ||
58 | { "Mempool", eina_test_mempool }, | ||
59 | { "Rectangle", eina_test_rectangle }, | ||
60 | { "Matrix Sparse", eina_test_matrixsparse }, | ||
61 | { "Eina Tiler", eina_test_tiler }, | ||
62 | { "Eina Strbuf", eina_test_strbuf }, | ||
63 | { "Eina Binbuf", eina_test_binbuf }, | ||
64 | { "String", eina_test_str }, | ||
65 | { "Unicode String", eina_test_ustr }, | ||
66 | { "QuadTree", eina_test_quadtree }, | ||
67 | { "Sched", eina_test_sched }, | ||
68 | { "Simple Xml Parser", eina_test_simple_xml_parser}, | ||
69 | { NULL, NULL } | ||
70 | }; | ||
71 | |||
72 | static void | ||
73 | _list_tests(void) | ||
74 | { | ||
75 | const Eina_Test_Case *itr = etc; | ||
76 | fputs("Available Test Cases:\n", stderr); | ||
77 | for (; itr->test_case; itr++) | ||
78 | fprintf(stderr, "\t%s\n", itr->test_case); | ||
79 | } | ||
80 | |||
81 | static Eina_Bool | ||
82 | _use_test(int argc, const char **argv, const char *test_case) | ||
83 | { | ||
84 | if (argc < 1) | ||
85 | return 1; | ||
86 | |||
87 | for (; argc > 0; argc--, argv++) | ||
88 | if (strcmp(test_case, *argv) == 0) | ||
89 | return 1; | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | Suite * | ||
95 | eina_build_suite(int argc, const char **argv) | ||
96 | { | ||
97 | TCase *tc; | ||
98 | Suite *s; | ||
99 | int i; | ||
100 | |||
101 | s = suite_create("Eina"); | ||
102 | |||
103 | for (i = 0; etc[i].test_case; ++i) | ||
104 | { | ||
105 | if (!_use_test(argc, argv, etc[i].test_case)) | ||
106 | continue; | ||
107 | |||
108 | tc = tcase_create(etc[i].test_case); | ||
109 | |||
110 | etc[i].build(tc); | ||
111 | |||
112 | suite_add_tcase(s, tc); | ||
113 | tcase_set_timeout(tc, 0); | ||
114 | } | ||
115 | |||
116 | return s; | ||
117 | } | ||
118 | |||
119 | /* FIXME this is a copy from eina_test_mempool | ||
120 | * we should remove the duplication | ||
121 | */ | ||
122 | static Eina_Array *_modules; | ||
123 | static void _mempool_init(void) | ||
124 | { | ||
125 | eina_init(); | ||
126 | /* force modules to be loaded in case they are not installed */ | ||
127 | _modules = eina_module_list_get(NULL, | ||
128 | PACKAGE_BUILD_DIR "/src/modules", | ||
129 | EINA_TRUE, | ||
130 | NULL, | ||
131 | NULL); | ||
132 | eina_module_list_load(_modules); | ||
133 | } | ||
134 | |||
135 | static void _mempool_shutdown(void) | ||
136 | { | ||
137 | eina_module_list_free(_modules); | ||
138 | /* TODO delete the list */ | ||
139 | eina_shutdown(); | ||
140 | } | ||
141 | |||
142 | int | ||
143 | main(int argc, char **argv) | ||
144 | { | ||
145 | Suite *s; | ||
146 | SRunner *sr; | ||
147 | int i, failed_count; | ||
148 | |||
149 | for (i = 1; i < argc; i++) | ||
150 | if ((strcmp(argv[i], "-h") == 0) || | ||
151 | (strcmp(argv[i], "--help") == 0)) | ||
152 | { | ||
153 | fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", | ||
154 | argv[0]); | ||
155 | _list_tests(); | ||
156 | return 0; | ||
157 | } | ||
158 | else if ((strcmp(argv[i], "-l") == 0) || | ||
159 | (strcmp(argv[i], "--list") == 0)) | ||
160 | { | ||
161 | _list_tests(); | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | s = eina_build_suite(argc - 1, (const char **)argv + 1); | ||
166 | sr = srunner_create(s); | ||
167 | |||
168 | _mempool_init(); | ||
169 | |||
170 | srunner_run_all(sr, CK_ENV); | ||
171 | failed_count = srunner_ntests_failed(sr); | ||
172 | srunner_free(sr); | ||
173 | |||
174 | _mempool_shutdown(); | ||
175 | |||
176 | return (failed_count == 0) ? 0 : 255; | ||
177 | } | ||