summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-02-18 12:35:24 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-02-20 13:27:42 +0900
commit78c7931575c5828179cc442f29525bb1d171eb0f (patch)
tree35b17e14a190e6f88831fe81b547d49645d29435 /src
parent74d84032172c01034119930643631a91c7fe54a5 (diff)
Evas filters: Add test cases for the script parser
Basic syntax checks and instructions coverage.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Evas.am1
-rw-r--r--src/tests/evas/evas_suite.c1
-rw-r--r--src/tests/evas/evas_suite.h1
-rw-r--r--src/tests/evas/evas_test_filters.c211
4 files changed, 214 insertions, 0 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 62627e9c11..df99287fff 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -1607,6 +1607,7 @@ tests/evas/evas_test_textblock.c \
1607tests/evas/evas_test_text.c \ 1607tests/evas/evas_test_text.c \
1608tests/evas/evas_test_callbacks.c \ 1608tests/evas/evas_test_callbacks.c \
1609tests/evas/evas_test_render_engines.c \ 1609tests/evas/evas_test_render_engines.c \
1610tests/evas/evas_test_filters.c \
1610tests/evas/evas_tests_helpers.h \ 1611tests/evas/evas_tests_helpers.h \
1611tests/evas/evas_suite.h 1612tests/evas/evas_suite.h
1612 1613
diff --git a/src/tests/evas/evas_suite.c b/src/tests/evas/evas_suite.c
index aa9841e1b1..a0ceee90db 100644
--- a/src/tests/evas/evas_suite.c
+++ b/src/tests/evas/evas_suite.c
@@ -24,6 +24,7 @@ static const Evas_Test_Case etc[] = {
24 { "Object Text", evas_test_text }, 24 { "Object Text", evas_test_text },
25 { "Callbacks", evas_test_callbacks }, 25 { "Callbacks", evas_test_callbacks },
26 { "Render Engines", evas_test_render_engines }, 26 { "Render Engines", evas_test_render_engines },
27 { "Filters", evas_test_filters },
27 { NULL, NULL } 28 { NULL, NULL }
28}; 29};
29 30
diff --git a/src/tests/evas/evas_suite.h b/src/tests/evas/evas_suite.h
index 34ba0a63bd..c7b62f4168 100644
--- a/src/tests/evas/evas_suite.h
+++ b/src/tests/evas/evas_suite.h
@@ -9,6 +9,7 @@ void evas_test_textblock(TCase *tc);
9void evas_test_text(TCase *tc); 9void evas_test_text(TCase *tc);
10void evas_test_callbacks(TCase *tc); 10void evas_test_callbacks(TCase *tc);
11void evas_test_render_engines(TCase *tc); 11void evas_test_render_engines(TCase *tc);
12void evas_test_filters(TCase *tc);
12 13
13 14
14#endif /* _EVAS_SUITE_H */ 15#endif /* _EVAS_SUITE_H */
diff --git a/src/tests/evas/evas_test_filters.c b/src/tests/evas/evas_test_filters.c
new file mode 100644
index 0000000000..2fc9fcdb8d
--- /dev/null
+++ b/src/tests/evas/evas_test_filters.c
@@ -0,0 +1,211 @@
1/* Unit test cases for the filters submodule.
2 * For now, limited to Evas_Object_Text, but I prefer to separate these
3 * functions from the core text object.
4 */
5
6#ifdef HAVE_CONFIG_H
7# include "config.h"
8#endif
9
10#include <stdio.h>
11
12#include "evas_suite.h"
13#include "Evas.h"
14#include "evas_tests_helpers.h"
15#include "../../lib/evas/include/evas_filter.h"
16
17#if !defined(EFL_EO_API_SUPPORT) || !defined(EFL_BETA_API_SUPPORT)
18# define BUILD_FILTER_TESTS 0
19#else
20# define BUILD_FILTER_TESTS 1
21#endif
22
23#if BUILD_FILTER_TESTS
24
25/* These are the same as in evas_test_text.c */
26
27#define TEST_FONT_NAME "DejaVuSans,UnDotum"
28#define TEST_FONT_SOURCE TESTS_SRC_DIR "/TestFont.eet"
29
30#define START_FILTER_TEST() \
31 Evas *evas; \
32 Evas_Object *to; \
33 evas = EVAS_TEST_INIT_EVAS(); \
34 evas_font_hinting_set(evas, EVAS_FONT_HINTING_AUTO); \
35 to = evas_object_text_add(evas); \
36 evas_object_text_font_source_set(to, TEST_FONT_SOURCE); \
37do \
38{ \
39} \
40while (0)
41
42#define END_FILTER_TEST() \
43do \
44{ \
45 evas_object_del(to); \
46 evas_free(evas); \
47 evas_shutdown(); \
48} \
49while (0)
50
51
52START_TEST(evas_filter_parser)
53{
54 Evas_Filter_Program *pgm;
55
56#define CHECK_FILTER(_a, _v) do { \
57 pgm = evas_filter_program_new("evas_suite"); \
58 fail_if(evas_filter_program_parse(pgm, _a) != _v); \
59 evas_filter_program_del(pgm); \
60 } while (0)
61#define CHKGOOD(_a) CHECK_FILTER(_a, EINA_TRUE)
62#define CHKBAAD(_a) CHECK_FILTER(_a, EINA_FALSE)
63
64 // Basic syntax errors
65 fail_if(evas_filter_program_parse(NULL, "blend();"));
66 CHKBAAD(NULL);
67 CHKBAAD("");
68 CHKBAAD(" \t \n ");
69 CHKBAAD("blend");
70 CHKBAAD("blend()");
71 CHKBAAD("blend;");
72
73 // Known & unknown instructions + some syntax errors
74 CHKGOOD("blend();");
75 CHKBAAD("blend()\nblend();");
76 CHKBAAD("blend(blend());");
77 CHKGOOD("blend(); blend();");
78 CHKGOOD("buffer:a;blend();");
79 CHKGOOD("buffer:a(alpha);blend();");
80 CHKGOOD("buffer:a(rgba);blend();");
81 CHKBAAD("buffer:a(BAAD);blend();");
82 CHKBAAD("buffer a(alpha);blend();");
83 CHKGOOD("blend();blur();fill();");
84 CHKGOOD("grow(10);");
85 CHKGOOD("curve(0:0 - 255:255);");
86 CHKGOOD("buffer:a(alpha);mask(a);");
87 CHKGOOD("buffer:a(rgba);mask(a);");
88 CHKGOOD("buffer:a(rgba);bump(a);");
89 CHKGOOD("buffer:a(rgba);displace(a);");
90 CHKGOOD("transform(output);");
91 CHKBAAD("unknown_command();");
92 CHKBAAD("blend(unknown_buffer);");
93
94 // Case sensitivity
95 CHKGOOD("BLEND();");
96 CHKGOOD("Blend();");
97 CHKGOOD("bLeNd();");
98 CHKGOOD("buffer : lowercase; blend (lowercase);");
99 CHKGOOD("buffer : UPPERCASE; blend (UPPERCASE);");
100 CHKBAAD("buffer : CamelCase; blend (cAMELcASE);");
101
102 // Full sequential arguments (default values)
103 CHKGOOD("blend(input, output, 0, 0, color = white, fillmode = none);");
104 CHKGOOD("blur(3, -1, default, 0, 0, color = white, src = input, dst = output);");
105 CHKGOOD("buffer : m (alpha); "
106 "bump(m, 135.0, 45.0, 8.0, 0.0, color = white, compensate = true, "
107 "src = input, dst = output, black = black, white = white, fillmode = repeat);");
108 CHKGOOD("curve(0:0 - 255:255, linear, rgb, src = input, dst = output);");
109 CHKGOOD("buffer : m (rgba); "
110 "displace(m, 10, default, src = input, dst = output, fillmode = repeat);");
111 CHKGOOD("fill(output, transparent, 0, 0, 0, 0);");
112 CHKGOOD("grow(0, smooth = yes, src = input, dst = output);");
113 CHKGOOD("buffer : m (alpha); "
114 "mask(m, src = input, dst = output, color = white, fillmode = none);");
115 CHKGOOD("buffer : m (alpha); "
116 "transform(m, op = vflip, src = input, oy = 0);");
117
118 // All colors
119 static const char *colors [] = {
120 "white",
121 "black",
122 "red",
123 "green",
124 "blue",
125 "darkblue",
126 "yellow",
127 "magenta",
128 "cyan",
129 "orange",
130 "purple",
131 "brown",
132 "maroon",
133 "lime",
134 "gray",
135 "grey",
136 "silver",
137 "olive",
138 "invisible",
139 "transparent",
140 "#ABC",
141 "#ABCF",
142 "#AABBCC",
143 "#AABBCCFF",
144 "WHITE",
145 "White"
146 };
147
148 static const char *colors_bad[] = {
149 "newcolor",
150 "ABC",
151 "#ZZZ",
152 "#-10"
153 };
154
155 for (size_t c = 0; c < sizeof(colors) / sizeof(colors[0]); c++)
156 {
157 char buf[64];
158 sprintf(buf, "blend(color = %s);", colors[c]);
159 CHKGOOD(buf);
160 }
161
162 for (size_t c = 0; c < sizeof(colors_bad) / sizeof(colors_bad[0]); c++)
163 {
164 char buf[64];
165 sprintf(buf, "blend(color = %s);", colors_bad[c]);
166 CHKBAAD(buf);
167 }
168
169 // All booleans
170 static const char *booleans[] = {
171 "1", "0",
172 "yes", "no",
173 "on", "off",
174 "enable", "disable",
175 "enabled", "disabled",
176 "true", "false",
177 "YES", "Yes"
178 };
179
180 static const char *booleans_bad[] = {
181 "o", "oui", "10"
182 };
183
184 for (size_t c = 0; c < sizeof(booleans) / sizeof(booleans[0]); c++)
185 {
186 char buf[64];
187 sprintf(buf, "grow(10, smooth = %s);", booleans[c]);
188 CHKGOOD(buf);
189 }
190
191 for (size_t c = 0; c < sizeof(booleans_bad) / sizeof(booleans_bad[0]); c++)
192 {
193 char buf[64];
194 sprintf(buf, "grow(10, smooth = %s);", booleans_bad[c]);
195 CHKBAAD(buf);
196 }
197
198 // fillmodes are parsed when converting from instructions to commands
199}
200END_TEST
201
202#endif // BUILD_FILTER_TESTS
203
204void evas_test_filters(TCase *tc)
205{
206#if BUILD_FILTER_TESTS
207 tcase_add_test(tc, evas_filter_parser);
208#else
209 (void) tc;
210#endif
211}