summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-04-21 09:36:44 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-04-22 09:54:24 +0300
commitd95a114db7ef950fe2ded3ea9b36cad1a621e294 (patch)
tree3381cc5c555a620b3197bfc4400ea6d6106540b5
parent81fbd0e2625775036b55765e996000b6a9115337 (diff)
Eolian: infras for tests + first test
-rw-r--r--src/Makefile_Eolian.am28
-rw-r--r--src/tests/eolian/data/class_simple.eo31
-rw-r--r--src/tests/eolian/eolian_suite.c206
-rw-r--r--src/tests/eolian/eolian_suite.h10
4 files changed, 275 insertions, 0 deletions
diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am
index 6807557..326727c 100644
--- a/src/Makefile_Eolian.am
+++ b/src/Makefile_Eolian.am
@@ -55,3 +55,31 @@ am__v_RAGEL_0 = @echo " RAGEL " $@;
55 55
56lib/eolian/eo_lexer.c: lib/eolian/eo_lexer.rl 56lib/eolian/eo_lexer.c: lib/eolian/eo_lexer.rl
57endif 57endif
58
59### Unit tests
60
61if EFL_ENABLE_TESTS
62check_PROGRAMS += \
63tests/eolian/eolian_suite
64
65tests_eolian_eolian_suite_SOURCES = \
66tests/eolian/eolian_suite.c \
67tests/eolian/eolian_suite.h
68
69tests_eolian_eolian_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
70-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eolian\" \
71-DPACKAGE_DATA_DIR=\"$(top_srcdir)/src/tests/eolian\" \
72@CHECK_CFLAGS@ \
73@EOLIAN_CFLAGS@
74TESTS += tests/eolian/eolian_suite
75
76tests_eolian_eolian_suite_LDADD = @CHECK_LIBS@ @USE_EOLIAN_LIBS@
77tests_eolian_eolian_suite_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
78
79eoliandatafilesdir = $(datadir)/eolian/data
80eoliandatafiles_DATA = tests/eolian/data/class_simple.eo
81
82endif
83
84EXTRA_DIST += \
85tests/eolian/data/class_simple.eo
diff --git a/src/tests/eolian/data/class_simple.eo b/src/tests/eolian/data/class_simple.eo
new file mode 100644
index 0000000..3abbc3b
--- /dev/null
+++ b/src/tests/eolian/data/class_simple.eo
@@ -0,0 +1,31 @@
1class Simple {
2 /*@ Class Desc Simple */
3 legacy_prefix: evas_object_simple;
4 eo_prefix: evas_obj_simple;
5 data: Evas_Simple_Data;
6 properties {
7 a {
8 set {
9 /*@
10 comment a::set */
11 return Eina_Bool (EINA_TRUE);
12 }
13 get {
14 }
15 values {
16 int value; /*@ Value description */
17 }
18 }
19 }
20 methods {
21 foo {
22 /*@ comment foo */
23 params {
24 @in int a; /*@ a */
25 @inout char *b;
26 @out double c;
27 }
28 return char *(NULL);
29 }
30 }
31};
diff --git a/src/tests/eolian/eolian_suite.c b/src/tests/eolian/eolian_suite.c
new file mode 100644
index 0000000..7534e57
--- /dev/null
+++ b/src/tests/eolian/eolian_suite.c
@@ -0,0 +1,206 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include "Eolian.h"
9#include "eolian_suite.h"
10
11typedef struct _Eolian_Test_Case Eolian_Test_Case;
12
13struct _Eolian_Test_Case
14{
15 const char *test_case;
16 void (*build)(TCase *tc);
17};
18
19START_TEST(eolian_simple_parsing)
20{
21 Eolian_Function fid = NULL;
22 const char *string = NULL, *ptype = NULL, *pname = NULL;
23 Eolian_Parameter_Dir dir = EOLIAN_IN_PARAM;
24 const char *class_name = "Simple";
25 const Eina_List *list = NULL;
26 Eolian_Function_Parameter param = NULL;
27
28 eolian_init();
29 /* Parsing */
30 fail_if(!eolian_eo_file_parse(PACKAGE_DATA_DIR"/data/class_simple.eo"));
31 fail_if(strcmp(eolian_class_find_by_file(PACKAGE_DATA_DIR"/data/class_simple.eo"), class_name));
32
33 /* Class */
34 fail_if(!eolian_class_exists(class_name));
35 fail_if(eolian_class_type_get(class_name) != EOLIAN_CLASS_REGULAR);
36 string = eolian_class_description_get(class_name);
37 fail_if(!string);
38 fail_if(strcmp(string, "Class Desc Simple"));
39 fail_if(eolian_class_inherits_list_get(class_name) != NULL);
40 fail_if(strcmp(eolian_class_legacy_prefix_get(class_name), "evas_object_simple"));
41 fail_if(strcmp(eolian_class_eo_prefix_get(class_name), "evas_obj_simple"));
42 fail_if(strcmp(eolian_class_data_type_get(class_name), "Evas_Simple_Data"));
43
44 /* Property */
45 fail_if(!(fid = eolian_class_function_find_by_name(class_name, "a", EOLIAN_PROPERTY)));
46 fail_if(strcmp(eolian_function_name_get(fid), "a"));
47 string = eolian_function_description_get(fid, EOLIAN_COMMENT_SET);
48 fail_if(!string);
49 fail_if(strcmp(string, "comment a::set"));
50 string = eolian_function_description_get(fid, EOLIAN_COMMENT_GET);
51 fail_if(string);
52 /* Function return */
53 string = eolian_function_return_type_get(fid, EOLIAN_PROP_SET);
54 fail_if(!string);
55 fail_if(strcmp(string, "Eina_Bool"));
56 string = eolian_function_return_dflt_value_get(fid, EOLIAN_PROP_SET);
57 fail_if(!string);
58 fail_if(strcmp(string, "EINA_TRUE"));
59 string = eolian_function_return_type_get(fid, EOLIAN_PROP_GET);
60 fail_if(string);
61
62 /* Function parameters */
63 fail_if(eolian_property_keys_list_get(fid) != NULL);
64 fail_if(!(list = eolian_property_values_list_get(fid)));
65 fail_if(eina_list_count(list) != 1);
66 fail_if(!(param = eina_list_data_get(list)));
67 eolian_parameter_information_get(param, NULL, &ptype, &pname, &string);
68 fail_if(strcmp(ptype, "int"));
69 fail_if(strcmp(pname, "value"));
70 fail_if(strcmp(string, "Value description"));
71
72 /* Method */
73 fail_if(!(fid = eolian_class_function_find_by_name(class_name, "foo", EOLIAN_METHOD)));
74 string = eolian_function_description_get(fid, EOLIAN_COMMENT);
75 fail_if(!string);
76 fail_if(strcmp(string, "comment foo"));
77 /* Function return */
78 string = eolian_function_return_type_get(fid, EOLIAN_METHOD);
79 fail_if(!string);
80 fail_if(strcmp(string, "char *"));
81 string = eolian_function_return_dflt_value_get(fid, EOLIAN_METHOD);
82 fail_if(!string);
83 fail_if(strcmp(string, "NULL"));
84
85 /* Function parameters */
86 fail_if(!(list = eolian_parameters_list_get(fid)));
87 fail_if(eina_list_count(list) != 3);
88 fail_if(!(param = eina_list_nth(list, 0)));
89 eolian_parameter_information_get(param, &dir, &ptype, &pname, &string);
90 fail_if(dir != EOLIAN_IN_PARAM);
91 fail_if(strcmp(ptype, "int"));
92 fail_if(strcmp(pname, "a"));
93 fail_if(!string || strcmp(string, "a"));
94 fail_if(!(param = eina_list_nth(list, 1)));
95 eolian_parameter_information_get(param, &dir, &ptype, &pname, &string);
96 fail_if(dir != EOLIAN_INOUT_PARAM);
97 fail_if(strcmp(ptype, "char *"));
98 fail_if(strcmp(pname, "b"));
99 fail_if(string);
100 fail_if(!(param = eina_list_nth(list, 2)));
101 eolian_parameter_information_get(param, &dir, &ptype, &pname, &string);
102 fail_if(dir != EOLIAN_OUT_PARAM);
103 fail_if(strcmp(ptype, "double"));
104 fail_if(strcmp(pname, "c"));
105 fail_if(string);
106
107 eolian_shutdown();
108}
109END_TEST
110
111static void eolian_parsing_test(TCase *tc)
112{
113 tcase_add_test(tc, eolian_simple_parsing);
114}
115
116static const Eolian_Test_Case etc[] = {
117 { "Eolian Parsing", eolian_parsing_test},
118 { NULL, NULL }
119};
120
121static void
122_list_tests(void)
123{
124 const Eolian_Test_Case *itr;
125
126 itr = etc;
127 fputs("Available Test Cases:\n", stderr);
128 for (; itr->test_case; itr++)
129 fprintf(stderr, "\t%s\n", itr->test_case);
130}
131
132static Eina_Bool
133_use_test(int argc, const char **argv, const char *test_case)
134{
135 if (argc < 1)
136 return 1;
137
138 for (; argc > 0; argc--, argv++)
139 if (strcmp(test_case, *argv) == 0)
140 return 1;
141 return 0;
142}
143
144static Suite *
145eolian_suite_build(int argc, const char **argv)
146{
147 TCase *tc;
148 Suite *s;
149 int i;
150
151 s = suite_create("Eolian");
152
153 for (i = 0; etc[i].test_case; ++i)
154 {
155 if (!_use_test(argc, argv, etc[i].test_case)) continue;
156 tc = tcase_create(etc[i].test_case);
157
158 etc[i].build(tc);
159
160 suite_add_tcase(s, tc);
161 tcase_set_timeout(tc, 0);
162 }
163
164 return s;
165}
166
167int
168main(int argc, char **argv)
169{
170 Suite *s;
171 SRunner *sr;
172 int i, failed_count;
173 eolian_init();
174 setenv("CK_FORK", "no", 0);
175
176 for (i = 1; i < argc; i++)
177 if ((strcmp(argv[i], "-h") == 0) ||
178 (strcmp(argv[i], "--help") == 0))
179 {
180 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
181 argv[0]);
182 _list_tests();
183 return 0;
184 }
185 else if ((strcmp(argv[i], "-l") == 0) ||
186 (strcmp(argv[i], "--list") == 0))
187 {
188 _list_tests();
189 return 0;
190 }
191
192 putenv("EFL_RUN_IN_TREE=1");
193
194 s = eolian_suite_build(argc - 1, (const char **)argv + 1);
195 sr = srunner_create(s);
196
197 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
198
199 srunner_run_all(sr, CK_ENV);
200 failed_count = srunner_ntests_failed(sr);
201 srunner_free(sr);
202
203 eolian_shutdown();
204
205 return (failed_count == 0) ? 0 : 255;
206}
diff --git a/src/tests/eolian/eolian_suite.h b/src/tests/eolian/eolian_suite.h
new file mode 100644
index 0000000..210b301
--- /dev/null
+++ b/src/tests/eolian/eolian_suite.h
@@ -0,0 +1,10 @@
1#ifndef _EOLIAN_SUITE_H
2#define _EOLIAN_SUITE_H
3
4#include <check.h>
5
6void eolian_test_init(TCase *tc);
7void eolian_test_general(TCase *tc);
8
9#endif /* _EOLIAN_SUITE_H */
10