diff options
Diffstat (limited to 'libraries/evas/src/tests/evas_test_textblock.c')
-rw-r--r-- | libraries/evas/src/tests/evas_test_textblock.c | 1973 |
1 files changed, 1973 insertions, 0 deletions
diff --git a/libraries/evas/src/tests/evas_test_textblock.c b/libraries/evas/src/tests/evas_test_textblock.c new file mode 100644 index 0000000..6a28353 --- /dev/null +++ b/libraries/evas/src/tests/evas_test_textblock.c | |||
@@ -0,0 +1,1973 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | |||
7 | #include <Eina.h> | ||
8 | |||
9 | #include "evas_suite.h" | ||
10 | #include "Evas.h" | ||
11 | |||
12 | #include "evas_tests_helpers.h" | ||
13 | |||
14 | /* Functions defined in evas_object_textblock.c */ | ||
15 | EAPI Eina_Bool | ||
16 | _evas_textblock_check_item_node_link(Evas_Object *obj); | ||
17 | EAPI int | ||
18 | _evas_textblock_format_offset_get(const Evas_Object_Textblock_Node_Format *n); | ||
19 | /* end of functions defined in evas_object_textblock.c */ | ||
20 | |||
21 | |||
22 | static const char *style_buf = | ||
23 | "DEFAULT='font=Sans font_size=10 color=#000 text_class=entry'" | ||
24 | "br='\n'" | ||
25 | "ps='ps'" | ||
26 | "tab='\t'" | ||
27 | "b='+ font=Sans:style=bold'"; | ||
28 | |||
29 | #define START_TB_TEST() \ | ||
30 | Evas *evas; \ | ||
31 | Evas_Object *tb; \ | ||
32 | Evas_Textblock_Style *st; \ | ||
33 | Evas_Textblock_Cursor *cur; \ | ||
34 | evas = EVAS_TEST_INIT_EVAS(); \ | ||
35 | evas_font_hinting_set(evas, EVAS_FONT_HINTING_AUTO); \ | ||
36 | tb = evas_object_textblock_add(evas); \ | ||
37 | fail_if(!tb); \ | ||
38 | evas_object_textblock_legacy_newline_set(tb, EINA_FALSE); \ | ||
39 | st = evas_textblock_style_new(); \ | ||
40 | fail_if(!st); \ | ||
41 | evas_textblock_style_set(st, style_buf); \ | ||
42 | fail_if(strcmp(style_buf, evas_textblock_style_get(st))); \ | ||
43 | evas_object_textblock_style_set(tb, st); \ | ||
44 | cur = evas_object_textblock_cursor_new(tb); \ | ||
45 | do \ | ||
46 | { \ | ||
47 | } \ | ||
48 | while (0) | ||
49 | |||
50 | #define END_TB_TEST() \ | ||
51 | do \ | ||
52 | { \ | ||
53 | evas_textblock_cursor_free(cur); \ | ||
54 | evas_object_del(tb); \ | ||
55 | evas_textblock_style_free(st); \ | ||
56 | evas_free(evas); \ | ||
57 | evas_shutdown(); \ | ||
58 | } \ | ||
59 | while (0) | ||
60 | |||
61 | START_TEST(evas_textblock_simple) | ||
62 | { | ||
63 | START_TB_TEST(); | ||
64 | const char *buf = "Th<i>i</i>s is a <br> te<b>s</b>t."; | ||
65 | evas_object_textblock_text_markup_set(tb, buf); | ||
66 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf)); | ||
67 | END_TB_TEST(); | ||
68 | } | ||
69 | END_TEST | ||
70 | |||
71 | #define _CHECK_CURSOR_COORDS() \ | ||
72 | do \ | ||
73 | { \ | ||
74 | Evas_Coord cx, cy, cw, ch; \ | ||
75 | int ret; \ | ||
76 | ret = evas_textblock_cursor_geometry_get(cur, &cx, &cy, &cw, &ch, \ | ||
77 | NULL, EVAS_TEXTBLOCK_CURSOR_UNDER); \ | ||
78 | fail_if(ret == -1); \ | ||
79 | ret = evas_textblock_cursor_geometry_get(cur, &cx, &cy, &cw, &ch, \ | ||
80 | NULL, EVAS_TEXTBLOCK_CURSOR_BEFORE); \ | ||
81 | fail_if(ret == -1); \ | ||
82 | ret = evas_textblock_cursor_char_geometry_get(cur, \ | ||
83 | &cx, &cy, &cw, &ch); \ | ||
84 | fail_if(ret == -1); \ | ||
85 | ret = evas_textblock_cursor_pen_geometry_get(cur, &cx, &cy, &cw, &ch); \ | ||
86 | fail_if(ret == -1); \ | ||
87 | ret = evas_textblock_cursor_line_geometry_get(cur, \ | ||
88 | &cx, &cy, &cw, &ch); \ | ||
89 | fail_if(ret == -1); \ | ||
90 | } \ | ||
91 | while (0) | ||
92 | START_TEST(evas_textblock_cursor) | ||
93 | { | ||
94 | START_TB_TEST(); | ||
95 | Evas_Coord x, y, w, h; | ||
96 | size_t i, len; | ||
97 | Evas_Coord nw, nh; | ||
98 | const char *buf = "This is a<br> test.<ps>Lets see if this works.<ps>עוד פסקה."; | ||
99 | |||
100 | /* Walk the textblock using cursor_char_next */ | ||
101 | evas_object_textblock_text_markup_set(tb, buf); | ||
102 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf)); | ||
103 | len = eina_unicode_utf8_get_len(buf) - 9; /* 9 because len(<br>) == 1 and len(<ps>) == 1 */ | ||
104 | for (i = 0 ; i < len ; i++) | ||
105 | { | ||
106 | _CHECK_CURSOR_COORDS(); | ||
107 | |||
108 | fail_if(evas_textblock_cursor_pos_get(cur) != (int) i); | ||
109 | |||
110 | fail_if(!evas_textblock_cursor_char_next(cur) && (i < len - 1)); | ||
111 | } | ||
112 | fail_if(evas_textblock_cursor_char_next(cur)); | ||
113 | |||
114 | /* Jump to positions all aronud the textblock */ | ||
115 | evas_textblock_cursor_pos_set(cur, -1); | ||
116 | fail_if(evas_textblock_cursor_pos_get(cur) != 0); | ||
117 | |||
118 | evas_textblock_cursor_pos_set(cur, len + 5); | ||
119 | fail_if(evas_textblock_cursor_pos_get(cur) != (int) len); | ||
120 | |||
121 | for (i = 0 ; i < len ; i++) | ||
122 | { | ||
123 | evas_textblock_cursor_pos_set(cur, i); | ||
124 | |||
125 | _CHECK_CURSOR_COORDS(); | ||
126 | |||
127 | fail_if(evas_textblock_cursor_pos_get(cur) != (int) i); | ||
128 | } | ||
129 | |||
130 | /* Create another cursor and insert text, making sure everything | ||
131 | * is in sync. */ | ||
132 | evas_object_textblock_clear(tb); | ||
133 | Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb); | ||
134 | evas_textblock_cursor_copy(main_cur, cur); | ||
135 | fail_if(evas_textblock_cursor_pos_get(cur) != | ||
136 | evas_textblock_cursor_pos_get(main_cur)); | ||
137 | |||
138 | evas_textblock_cursor_text_prepend(main_cur, "a"); | ||
139 | fail_if(evas_textblock_cursor_pos_get(cur) == | ||
140 | evas_textblock_cursor_pos_get(main_cur)); | ||
141 | evas_textblock_cursor_text_prepend(main_cur, "a"); | ||
142 | fail_if(evas_textblock_cursor_pos_get(cur) == | ||
143 | evas_textblock_cursor_pos_get(main_cur)); | ||
144 | |||
145 | /* Insert text to a non-empty textblock */ | ||
146 | evas_object_textblock_clear(tb); | ||
147 | evas_object_textblock_text_markup_set(tb, buf); | ||
148 | evas_textblock_cursor_copy(main_cur, cur); | ||
149 | fail_if(evas_textblock_cursor_pos_get(cur) != | ||
150 | evas_textblock_cursor_pos_get(main_cur)); | ||
151 | |||
152 | evas_textblock_cursor_text_prepend(main_cur, "a"); | ||
153 | fail_if(evas_textblock_cursor_pos_get(cur) == | ||
154 | evas_textblock_cursor_pos_get(main_cur)); | ||
155 | evas_textblock_cursor_text_prepend(main_cur, "a"); | ||
156 | fail_if(evas_textblock_cursor_pos_get(cur) == | ||
157 | evas_textblock_cursor_pos_get(main_cur)); | ||
158 | |||
159 | /* Make sure append works */ | ||
160 | evas_textblock_cursor_copy(main_cur, cur); | ||
161 | fail_if(evas_textblock_cursor_pos_get(cur) != | ||
162 | evas_textblock_cursor_pos_get(main_cur)); | ||
163 | evas_textblock_cursor_text_append(main_cur, "a"); | ||
164 | fail_if(evas_textblock_cursor_pos_get(cur) != | ||
165 | evas_textblock_cursor_pos_get(main_cur)); | ||
166 | |||
167 | /* Cursor comparison */ | ||
168 | evas_textblock_cursor_pos_set(cur, 1); | ||
169 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
170 | fail_if(evas_textblock_cursor_compare(cur, main_cur) != -1); | ||
171 | |||
172 | evas_textblock_cursor_pos_set(cur, 2); | ||
173 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
174 | fail_if(evas_textblock_cursor_compare(cur, main_cur) != 0); | ||
175 | |||
176 | evas_textblock_cursor_pos_set(cur, 3); | ||
177 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
178 | fail_if(evas_textblock_cursor_compare(cur, main_cur) != 1); | ||
179 | |||
180 | /* Paragraph first */ | ||
181 | evas_object_textblock_text_markup_set(tb, buf); | ||
182 | for (i = 0 ; i < len ; i++) | ||
183 | { | ||
184 | evas_textblock_cursor_pos_set(cur, i); | ||
185 | |||
186 | evas_textblock_cursor_paragraph_first(cur); | ||
187 | fail_if(evas_textblock_cursor_pos_get(cur) != 0); | ||
188 | } | ||
189 | |||
190 | /* Paragraph last */ | ||
191 | for (i = 0 ; i < len ; i++) | ||
192 | { | ||
193 | evas_textblock_cursor_pos_set(cur, i); | ||
194 | |||
195 | evas_textblock_cursor_paragraph_last(cur); | ||
196 | fail_if(evas_textblock_cursor_pos_get(cur) != (int) len); | ||
197 | } | ||
198 | |||
199 | /* Paragraph next */ | ||
200 | evas_textblock_cursor_paragraph_last(cur); | ||
201 | fail_if(evas_textblock_cursor_paragraph_next(cur)); | ||
202 | |||
203 | evas_textblock_cursor_paragraph_first(cur); | ||
204 | fail_if(!evas_textblock_cursor_paragraph_next(cur)); | ||
205 | fail_if(!evas_textblock_cursor_paragraph_next(cur)); | ||
206 | |||
207 | /* Paragraph prev */ | ||
208 | evas_textblock_cursor_paragraph_first(cur); | ||
209 | fail_if(evas_textblock_cursor_paragraph_prev(cur)); | ||
210 | |||
211 | evas_textblock_cursor_paragraph_last(cur); | ||
212 | fail_if(!evas_textblock_cursor_paragraph_prev(cur)); | ||
213 | fail_if(!evas_textblock_cursor_paragraph_prev(cur)); | ||
214 | |||
215 | /* Cher next */ | ||
216 | evas_textblock_cursor_paragraph_last(cur); | ||
217 | fail_if(evas_textblock_cursor_char_next(cur)); | ||
218 | |||
219 | evas_textblock_cursor_paragraph_first(cur); | ||
220 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
221 | fail_if(!evas_textblock_cursor_paragraph_next(cur)); | ||
222 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
223 | fail_if(!evas_textblock_cursor_paragraph_next(cur)); | ||
224 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
225 | |||
226 | /* Cher prev */ | ||
227 | evas_textblock_cursor_paragraph_first(cur); | ||
228 | fail_if(evas_textblock_cursor_char_prev(cur)); | ||
229 | |||
230 | evas_textblock_cursor_paragraph_last(cur); | ||
231 | fail_if(!evas_textblock_cursor_char_prev(cur)); | ||
232 | fail_if(!evas_textblock_cursor_paragraph_prev(cur)); | ||
233 | fail_if(!evas_textblock_cursor_char_prev(cur)); | ||
234 | |||
235 | /* Paragraph char first */ | ||
236 | evas_textblock_cursor_paragraph_first(main_cur); | ||
237 | evas_textblock_cursor_paragraph_first(cur); | ||
238 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
239 | evas_textblock_cursor_paragraph_char_first(cur); | ||
240 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
241 | |||
242 | /* Paragraph char last */ | ||
243 | evas_textblock_cursor_paragraph_last(main_cur); | ||
244 | evas_textblock_cursor_paragraph_last(cur); | ||
245 | fail_if(!evas_textblock_cursor_char_prev(cur)); | ||
246 | evas_textblock_cursor_paragraph_char_last(cur); | ||
247 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
248 | |||
249 | /* Line char first */ | ||
250 | evas_textblock_cursor_paragraph_first(main_cur); | ||
251 | evas_textblock_cursor_paragraph_first(cur); | ||
252 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
253 | evas_textblock_cursor_line_char_first(cur); | ||
254 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
255 | |||
256 | evas_textblock_cursor_pos_set(cur, 12); | ||
257 | evas_textblock_cursor_line_char_first(cur); | ||
258 | fail_if(evas_textblock_cursor_pos_get(cur) != 10); | ||
259 | |||
260 | /* Line char first */ | ||
261 | evas_textblock_cursor_paragraph_last(main_cur); | ||
262 | evas_textblock_cursor_paragraph_last(cur); | ||
263 | fail_if(!evas_textblock_cursor_char_prev(cur)); | ||
264 | evas_textblock_cursor_line_char_last(cur); | ||
265 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
266 | |||
267 | evas_textblock_cursor_pos_set(cur, 12); | ||
268 | evas_textblock_cursor_line_char_last(cur); | ||
269 | fail_if(evas_textblock_cursor_pos_get(cur) != 16); | ||
270 | |||
271 | /* Line set */ | ||
272 | evas_textblock_cursor_paragraph_first(main_cur); | ||
273 | evas_textblock_cursor_paragraph_last(cur); | ||
274 | |||
275 | fail_if(!evas_textblock_cursor_line_set(cur, 0)); | ||
276 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
277 | fail_if(!evas_textblock_cursor_line_set(cur, 1)); | ||
278 | fail_if(!evas_textblock_cursor_line_set(cur, 2)); | ||
279 | fail_if(!evas_textblock_cursor_line_set(cur, 3)); | ||
280 | |||
281 | fail_if(evas_textblock_cursor_line_set(cur, -1)); | ||
282 | fail_if(evas_textblock_cursor_line_set(cur, 99)); | ||
283 | |||
284 | /* Paragraph text get */ | ||
285 | evas_textblock_cursor_paragraph_first(cur); | ||
286 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
287 | "This is a<br> test.")); | ||
288 | evas_textblock_cursor_paragraph_next(cur); | ||
289 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
290 | "Lets see if this works.")); | ||
291 | evas_textblock_cursor_paragraph_next(cur); | ||
292 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
293 | "עוד פסקה.")); | ||
294 | |||
295 | /* Paragraph length get */ | ||
296 | evas_textblock_cursor_paragraph_first(cur); | ||
297 | /* -3 because len(<br>) == 1 */ | ||
298 | fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) != | ||
299 | eina_unicode_utf8_get_len("This is a<br> test.") - 3); | ||
300 | evas_textblock_cursor_paragraph_next(cur); | ||
301 | fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) != | ||
302 | eina_unicode_utf8_get_len("Lets see if this works.")); | ||
303 | evas_textblock_cursor_paragraph_next(cur); | ||
304 | fail_if(evas_textblock_cursor_paragraph_text_length_get(cur) != | ||
305 | eina_unicode_utf8_get_len("עוד פסקה.")); | ||
306 | |||
307 | /* Cursor content get */ | ||
308 | evas_textblock_cursor_pos_set(cur, 0); | ||
309 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "T")); | ||
310 | evas_textblock_cursor_pos_set(cur, 9); | ||
311 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<br>")); | ||
312 | evas_textblock_cursor_pos_set(cur, 43); | ||
313 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "ד")); | ||
314 | |||
315 | /* Eol get */ | ||
316 | for (i = 0 ; i < len ; i++) | ||
317 | { | ||
318 | evas_textblock_cursor_pos_set(cur, i); | ||
319 | evas_textblock_cursor_copy(cur, main_cur); | ||
320 | evas_textblock_cursor_line_char_last(main_cur); | ||
321 | |||
322 | if (!evas_textblock_cursor_compare(cur, main_cur)) | ||
323 | { | ||
324 | fail_if(!evas_textblock_cursor_eol_get(cur)); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | fail_if(evas_textblock_cursor_eol_get(cur)); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | /* Format positions */ | ||
333 | const Evas_Object_Textblock_Node_Format *fnode; | ||
334 | fnode = evas_textblock_node_format_first_get(tb); | ||
335 | fail_if(!fnode); | ||
336 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
337 | evas_textblock_cursor_copy(cur, main_cur); | ||
338 | fail_if(evas_textblock_cursor_pos_get(cur) != 9); | ||
339 | fail_if(evas_textblock_cursor_format_get(cur) != fnode); | ||
340 | |||
341 | fnode = evas_textblock_node_format_next_get(fnode); | ||
342 | fail_if(!fnode); | ||
343 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
344 | fail_if(evas_textblock_cursor_pos_get(cur) != 16); | ||
345 | fail_if(evas_textblock_cursor_format_get(cur) != fnode); | ||
346 | evas_textblock_cursor_format_next(main_cur); | ||
347 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
348 | |||
349 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
350 | fail_if(!fnode); | ||
351 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
352 | fail_if(evas_textblock_cursor_pos_get(cur) != 9); | ||
353 | fail_if(evas_textblock_cursor_format_get(cur) != fnode); | ||
354 | evas_textblock_cursor_format_prev(main_cur); | ||
355 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
356 | |||
357 | evas_textblock_cursor_char_next(main_cur); | ||
358 | evas_textblock_cursor_format_prev(main_cur); | ||
359 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
360 | |||
361 | |||
362 | evas_object_textblock_text_markup_set(tb, buf); | ||
363 | |||
364 | /* Check that pen geometry and getting char at coord are in sync. */ | ||
365 | do | ||
366 | { | ||
367 | int cur_pos; | ||
368 | |||
369 | /* Check if it's the last char, if it is, break, otherwise, go back | ||
370 | * to the current char because our test advanced the cursor. */ | ||
371 | if (!evas_textblock_cursor_char_next(cur)) | ||
372 | break; | ||
373 | else | ||
374 | evas_textblock_cursor_char_prev(cur); | ||
375 | |||
376 | cur_pos = evas_textblock_cursor_pos_get(cur); | ||
377 | evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h); | ||
378 | evas_textblock_cursor_char_coord_set(cur, x + (w / 2), y + (h / 2)); | ||
379 | fail_if(cur_pos != evas_textblock_cursor_pos_get(cur)); | ||
380 | } | ||
381 | while (evas_textblock_cursor_char_next(cur)); | ||
382 | |||
383 | /* Try positions before the first paragraph, and after the last paragraph */ | ||
384 | evas_object_textblock_text_markup_set(tb, buf); | ||
385 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
386 | evas_object_resize(tb, nw, nh); | ||
387 | evas_textblock_cursor_pos_set(cur, 5); | ||
388 | evas_textblock_cursor_char_coord_set(cur, nw / 2, | ||
389 | -50); | ||
390 | evas_textblock_cursor_paragraph_first(main_cur); | ||
391 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
392 | |||
393 | evas_textblock_cursor_pos_set(cur, 5); | ||
394 | evas_textblock_cursor_char_coord_set(cur, nw / 2, | ||
395 | nh + 50); | ||
396 | evas_textblock_cursor_paragraph_last(main_cur); | ||
397 | fail_if(evas_textblock_cursor_compare(cur, main_cur)); | ||
398 | |||
399 | /* Try positions beyond the left/right limits of lines. */ | ||
400 | for (i = 0 ; i < 2 ; i++) | ||
401 | { | ||
402 | evas_textblock_cursor_line_set(cur, i); | ||
403 | evas_textblock_cursor_line_geometry_get(cur, &x, &y, &w, &h); | ||
404 | |||
405 | evas_textblock_cursor_pos_set(main_cur, 5); | ||
406 | evas_textblock_cursor_char_coord_set(main_cur, x - 50, y); | ||
407 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
408 | |||
409 | evas_textblock_cursor_line_char_last(cur); | ||
410 | evas_textblock_cursor_pos_set(main_cur, 5); | ||
411 | evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y); | ||
412 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
413 | } | ||
414 | |||
415 | #ifdef HAVE_FRIBIDI | ||
416 | evas_object_textblock_text_markup_set(tb, | ||
417 | "testנסיוןtestנסיון<ps>" | ||
418 | "נסיוןtestנסיוןtest<ps>" | ||
419 | "testנסיוןtest<ps>" | ||
420 | "נסיוןtestנסיון<ps>" | ||
421 | "testנסיון<br>נסיון<ps>" | ||
422 | "נסיוןtest<br>test" | ||
423 | ); | ||
424 | |||
425 | for (i = 0 ; i < 8 ; i++) | ||
426 | { | ||
427 | evas_textblock_cursor_line_set(cur, i); | ||
428 | evas_textblock_cursor_line_geometry_get(cur, &x, &y, &w, &h); | ||
429 | switch (i) | ||
430 | { | ||
431 | case 0: | ||
432 | case 2: | ||
433 | case 4: | ||
434 | case 5: | ||
435 | /* Ltr paragraph */ | ||
436 | evas_textblock_cursor_pos_set(main_cur, 7); | ||
437 | evas_textblock_cursor_char_coord_set(main_cur, x - 50, y); | ||
438 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
439 | |||
440 | evas_textblock_cursor_line_char_last(cur); | ||
441 | evas_textblock_cursor_pos_set(main_cur, 7); | ||
442 | evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y); | ||
443 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
444 | break; | ||
445 | case 1: | ||
446 | case 3: | ||
447 | case 6: | ||
448 | case 7: | ||
449 | /* Rtl paragraph */ | ||
450 | evas_textblock_cursor_line_char_last(cur); | ||
451 | evas_textblock_cursor_pos_set(main_cur, 7); | ||
452 | evas_textblock_cursor_char_coord_set(main_cur, x - 50, y); | ||
453 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
454 | |||
455 | evas_textblock_cursor_line_char_first(cur); | ||
456 | evas_textblock_cursor_pos_set(main_cur, 7); | ||
457 | evas_textblock_cursor_char_coord_set(main_cur, x + w + 50, y); | ||
458 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
459 | break; | ||
460 | } | ||
461 | } | ||
462 | #endif | ||
463 | |||
464 | evas_object_textblock_text_markup_set(tb, buf); | ||
465 | /* Testing line geometry.*/ | ||
466 | { | ||
467 | Evas_Coord lx, ly, lw, lh; | ||
468 | Evas_Coord plx, ply, plw, plh; | ||
469 | evas_textblock_cursor_line_set(cur, 0); | ||
470 | evas_textblock_cursor_copy(cur, main_cur); | ||
471 | evas_textblock_cursor_line_char_last(main_cur); | ||
472 | evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh); | ||
473 | |||
474 | while (evas_textblock_cursor_compare(cur, main_cur) <= 0) | ||
475 | { | ||
476 | evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h); | ||
477 | fail_if(0 != evas_textblock_cursor_line_geometry_get( | ||
478 | cur, &lx, &ly, &lw, &lh)); | ||
479 | fail_if((x < lx) || (x + w > lx + lw) || | ||
480 | (y < ly) || (y + h > ly + lh)); | ||
481 | fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh)); | ||
482 | |||
483 | plx = lx; | ||
484 | ply = ly; | ||
485 | plw = lw; | ||
486 | plh = lh; | ||
487 | evas_textblock_cursor_char_next(cur); | ||
488 | } | ||
489 | |||
490 | evas_textblock_cursor_line_set(cur, 1); | ||
491 | evas_textblock_cursor_copy(cur, main_cur); | ||
492 | evas_textblock_cursor_line_char_last(main_cur); | ||
493 | evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh); | ||
494 | |||
495 | while (evas_textblock_cursor_compare(cur, main_cur) <= 0) | ||
496 | { | ||
497 | evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h); | ||
498 | fail_if(1 != evas_textblock_cursor_line_geometry_get( | ||
499 | cur, &lx, &ly, &lw, &lh)); | ||
500 | fail_if((x < lx) || (x + w > lx + lw) || | ||
501 | (y < ly) || (y + h > ly + lh)); | ||
502 | fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh)); | ||
503 | |||
504 | plx = lx; | ||
505 | ply = ly; | ||
506 | plw = lw; | ||
507 | plh = lh; | ||
508 | evas_textblock_cursor_char_next(cur); | ||
509 | } | ||
510 | |||
511 | evas_textblock_cursor_paragraph_last(cur); | ||
512 | evas_textblock_cursor_line_set(cur, 0); | ||
513 | evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh); | ||
514 | evas_object_textblock_line_number_geometry_get(tb, 0, | ||
515 | &lx, &ly, &lw, &lh); | ||
516 | fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh)); | ||
517 | fail_if(0 != evas_textblock_cursor_line_coord_set(cur, ly + (lh / 2))); | ||
518 | |||
519 | evas_textblock_cursor_line_set(cur, 1); | ||
520 | evas_textblock_cursor_line_geometry_get(cur, &plx, &ply, &plw, &plh); | ||
521 | evas_object_textblock_line_number_geometry_get(tb, 1, | ||
522 | &lx, &ly, &lw, &lh); | ||
523 | fail_if((lx != plx) || (ly != ply) || (lw != plw) || (lh != plh)); | ||
524 | fail_if(1 != evas_textblock_cursor_line_coord_set(cur, ly + (lh / 2))); | ||
525 | |||
526 | /* Before the start of the textblock */ | ||
527 | fail_if(0 != evas_textblock_cursor_line_coord_set(cur, -50)); | ||
528 | fail_if(3 != evas_textblock_cursor_line_coord_set(cur, 100000)); | ||
529 | |||
530 | /* And now with a valigned textblock. */ | ||
531 | evas_object_textblock_text_markup_set(tb, buf); | ||
532 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
533 | evas_object_resize(tb, 2 * nw, 2 * nh); | ||
534 | |||
535 | evas_object_textblock_valign_set(tb, 0.5); | ||
536 | evas_textblock_cursor_paragraph_first(cur); | ||
537 | evas_textblock_cursor_pen_geometry_get(cur, &x, &y, &w, &h); | ||
538 | fail_if(y <= 0); | ||
539 | |||
540 | evas_textblock_cursor_paragraph_last(main_cur); | ||
541 | evas_textblock_cursor_char_coord_set(main_cur, x + w, y / 2); | ||
542 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
543 | |||
544 | evas_textblock_cursor_paragraph_last(main_cur); | ||
545 | evas_textblock_cursor_line_coord_set(main_cur, y / 2); | ||
546 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
547 | |||
548 | /* Fail if they are equal, i.e if it for some reason thinks it should | ||
549 | * go to the end. */ | ||
550 | evas_textblock_cursor_paragraph_first(main_cur); | ||
551 | evas_textblock_cursor_paragraph_last(cur); | ||
552 | evas_textblock_cursor_char_coord_set(main_cur, x + w, nh + 1); | ||
553 | fail_if(!evas_textblock_cursor_compare(main_cur, cur)); | ||
554 | |||
555 | evas_textblock_cursor_paragraph_first(main_cur); | ||
556 | evas_textblock_cursor_paragraph_last(cur); | ||
557 | evas_textblock_cursor_line_coord_set(main_cur, nh + 1); | ||
558 | fail_if(!evas_textblock_cursor_compare(main_cur, cur)); | ||
559 | |||
560 | /* Fail if it doesn't go to the end. */ | ||
561 | evas_textblock_cursor_paragraph_last(cur); | ||
562 | evas_textblock_cursor_paragraph_first(main_cur); | ||
563 | evas_textblock_cursor_char_coord_set(main_cur, x + w, (2 * nh) - 1); | ||
564 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
565 | |||
566 | evas_textblock_cursor_paragraph_first(main_cur); | ||
567 | evas_textblock_cursor_line_coord_set(main_cur, (2 * nh) - 1); | ||
568 | fail_if(evas_textblock_cursor_compare(main_cur, cur)); | ||
569 | } | ||
570 | |||
571 | END_TB_TEST(); | ||
572 | } | ||
573 | END_TEST | ||
574 | |||
575 | START_TEST(evas_textblock_format_removal) | ||
576 | { | ||
577 | START_TB_TEST(); | ||
578 | int i; | ||
579 | const char *buf = "Th<b>is a<a>tes</a>st</b>."; | ||
580 | const Evas_Object_Textblock_Node_Format *fnode; | ||
581 | Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb); | ||
582 | evas_object_textblock_text_markup_set(tb, buf); | ||
583 | |||
584 | /* Remove the "b" pair. */ | ||
585 | fnode = evas_textblock_node_format_first_get(tb); | ||
586 | evas_textblock_node_format_remove_pair(tb, | ||
587 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
588 | |||
589 | fnode = evas_textblock_node_format_first_get(tb); | ||
590 | fail_if (!fnode); | ||
591 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
592 | "+ a")); | ||
593 | |||
594 | fnode = evas_textblock_node_format_next_get(fnode); | ||
595 | fail_if (!fnode); | ||
596 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
597 | "- a")); | ||
598 | |||
599 | fnode = evas_textblock_node_format_next_get(fnode); | ||
600 | fail_if (fnode); | ||
601 | |||
602 | /* Now also remove the a pair */ | ||
603 | fnode = evas_textblock_node_format_first_get(tb); | ||
604 | evas_textblock_node_format_remove_pair(tb, | ||
605 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
606 | fnode = evas_textblock_node_format_first_get(tb); | ||
607 | fail_if (fnode); | ||
608 | |||
609 | /* Remove the "a" pair. */ | ||
610 | evas_object_textblock_text_markup_set(tb, buf); | ||
611 | |||
612 | fnode = evas_textblock_node_format_first_get(tb); | ||
613 | fnode = evas_textblock_node_format_next_get(fnode); | ||
614 | evas_textblock_node_format_remove_pair(tb, | ||
615 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
616 | |||
617 | fnode = evas_textblock_node_format_first_get(tb); | ||
618 | fail_if (!fnode); | ||
619 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
620 | "+ b")); | ||
621 | |||
622 | fnode = evas_textblock_node_format_next_get(fnode); | ||
623 | fail_if (!fnode); | ||
624 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
625 | "- b")); | ||
626 | |||
627 | fnode = evas_textblock_node_format_next_get(fnode); | ||
628 | fail_if (fnode); | ||
629 | |||
630 | /* Now also remove the b pair */ | ||
631 | fnode = evas_textblock_node_format_first_get(tb); | ||
632 | evas_textblock_node_format_remove_pair(tb, | ||
633 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
634 | fnode = evas_textblock_node_format_first_get(tb); | ||
635 | fail_if (fnode); | ||
636 | |||
637 | /* Now remove formats by removing text */ | ||
638 | evas_object_textblock_text_markup_set(tb, buf); | ||
639 | evas_textblock_cursor_pos_set(cur, 6); | ||
640 | evas_textblock_cursor_char_delete(cur); | ||
641 | evas_textblock_cursor_char_delete(cur); | ||
642 | evas_textblock_cursor_char_delete(cur); | ||
643 | /* Only b formats should remain */ | ||
644 | fnode = evas_textblock_node_format_first_get(tb); | ||
645 | fail_if (!fnode); | ||
646 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
647 | "+ b")); | ||
648 | |||
649 | fnode = evas_textblock_node_format_next_get(fnode); | ||
650 | fail_if (!fnode); | ||
651 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
652 | "- b")); | ||
653 | |||
654 | fnode = evas_textblock_node_format_next_get(fnode); | ||
655 | fail_if (fnode); | ||
656 | |||
657 | /* No formats should remain. */ | ||
658 | evas_textblock_cursor_pos_set(cur, 2); | ||
659 | evas_textblock_cursor_char_delete(cur); | ||
660 | evas_textblock_cursor_char_delete(cur); | ||
661 | evas_textblock_cursor_char_delete(cur); | ||
662 | evas_textblock_cursor_char_delete(cur); | ||
663 | evas_textblock_cursor_char_delete(cur); | ||
664 | evas_textblock_cursor_char_delete(cur); | ||
665 | fnode = evas_textblock_node_format_first_get(tb); | ||
666 | fail_if (fnode); | ||
667 | |||
668 | /* Try to remove the formats in a way that shouldn't remove them */ | ||
669 | evas_object_textblock_text_markup_set(tb, buf); | ||
670 | evas_textblock_cursor_pos_set(cur, 7); | ||
671 | evas_textblock_cursor_char_delete(cur); | ||
672 | evas_textblock_cursor_char_delete(cur); | ||
673 | evas_textblock_cursor_char_delete(cur); | ||
674 | evas_textblock_cursor_char_delete(cur); | ||
675 | fnode = evas_textblock_node_format_first_get(tb); | ||
676 | fail_if (!fnode); | ||
677 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
678 | "+ b")); | ||
679 | |||
680 | fnode = evas_textblock_node_format_next_get(fnode); | ||
681 | fail_if (!fnode); | ||
682 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
683 | "+ a")); | ||
684 | |||
685 | fnode = evas_textblock_node_format_next_get(fnode); | ||
686 | fail_if (!fnode); | ||
687 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
688 | "- a")); | ||
689 | |||
690 | fnode = evas_textblock_node_format_next_get(fnode); | ||
691 | fail_if (!fnode); | ||
692 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
693 | "- b")); | ||
694 | |||
695 | fnode = evas_textblock_node_format_next_get(fnode); | ||
696 | fail_if (fnode); | ||
697 | |||
698 | /* Try range deletion to delete a */ | ||
699 | evas_object_textblock_text_markup_set(tb, buf); | ||
700 | evas_textblock_cursor_pos_set(cur, 6); | ||
701 | evas_textblock_cursor_pos_set(main_cur, 9); | ||
702 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
703 | fnode = evas_textblock_node_format_first_get(tb); | ||
704 | fail_if (!fnode); | ||
705 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
706 | "+ b")); | ||
707 | |||
708 | fnode = evas_textblock_node_format_next_get(fnode); | ||
709 | fail_if (!fnode); | ||
710 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
711 | "- b")); | ||
712 | |||
713 | fnode = evas_textblock_node_format_next_get(fnode); | ||
714 | fail_if (fnode); | ||
715 | |||
716 | /* Range deletion to delete both */ | ||
717 | evas_object_textblock_text_markup_set(tb, buf); | ||
718 | evas_textblock_cursor_pos_set(cur, 2); | ||
719 | evas_textblock_cursor_pos_set(main_cur, 11); | ||
720 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
721 | fnode = evas_textblock_node_format_first_get(tb); | ||
722 | fail_if (fnode); | ||
723 | |||
724 | /* Range deletion across paragraphs */ | ||
725 | evas_object_textblock_text_markup_set(tb, | ||
726 | "Th<b>is a<a>te<ps>" | ||
727 | "s</a>st</b>."); | ||
728 | evas_textblock_cursor_pos_set(cur, 6); | ||
729 | evas_textblock_cursor_pos_set(main_cur, 10); | ||
730 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
731 | fnode = evas_textblock_node_format_first_get(tb); | ||
732 | fail_if (!fnode); | ||
733 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
734 | "+ b")); | ||
735 | |||
736 | fnode = evas_textblock_node_format_next_get(fnode); | ||
737 | fail_if (!fnode); | ||
738 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
739 | "- b")); | ||
740 | |||
741 | fnode = evas_textblock_node_format_next_get(fnode); | ||
742 | fail_if (fnode); | ||
743 | |||
744 | /* Two formats in the same place. */ | ||
745 | evas_object_textblock_text_markup_set(tb, "a<b><a>b</a></b>b"); | ||
746 | evas_textblock_cursor_pos_set(cur, 1); | ||
747 | evas_textblock_cursor_char_delete(cur); | ||
748 | fnode = evas_textblock_node_format_first_get(tb); | ||
749 | fail_if (fnode); | ||
750 | |||
751 | /* Two formats across different paragraphs with notihng in between. */ | ||
752 | evas_object_textblock_text_markup_set(tb, "<b><ps></b>"); | ||
753 | evas_textblock_cursor_pos_set(cur, 0); | ||
754 | evas_textblock_cursor_char_delete(cur); | ||
755 | fnode = evas_textblock_node_format_first_get(tb); | ||
756 | fail_if (fnode); | ||
757 | |||
758 | /* Try with range */ | ||
759 | evas_object_textblock_text_markup_set(tb, "<b><ps></b>"); | ||
760 | evas_textblock_cursor_pos_set(cur, 0); | ||
761 | evas_textblock_cursor_pos_set(main_cur, 1); | ||
762 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
763 | fnode = evas_textblock_node_format_first_get(tb); | ||
764 | fail_if (fnode); | ||
765 | |||
766 | /* Verify fmt position and REP_CHAR positions are the same */ | ||
767 | evas_object_textblock_text_markup_set(tb, | ||
768 | "This is<ps>an <item absize=93x152 vsize=ascent></>a."); | ||
769 | evas_textblock_cursor_pos_set(cur, 7); | ||
770 | evas_textblock_cursor_char_delete(cur); | ||
771 | fnode = evas_textblock_node_format_first_get(tb); | ||
772 | fail_if(_evas_textblock_format_offset_get(fnode) != 10); | ||
773 | |||
774 | /* Out of order <b><i></b></i> mixes. */ | ||
775 | evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</i>e"); | ||
776 | evas_textblock_cursor_pos_set(cur, 2); | ||
777 | |||
778 | for (i = 0 ; i < 2 ; i++) | ||
779 | { | ||
780 | fnode = evas_textblock_node_format_first_get(tb); | ||
781 | fail_if (!fnode); | ||
782 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
783 | |||
784 | fnode = evas_textblock_node_format_next_get(fnode); | ||
785 | fail_if (!fnode); | ||
786 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i")); | ||
787 | |||
788 | fnode = evas_textblock_node_format_next_get(fnode); | ||
789 | fail_if (!fnode); | ||
790 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b")); | ||
791 | |||
792 | fnode = evas_textblock_node_format_next_get(fnode); | ||
793 | fail_if (!fnode); | ||
794 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i")); | ||
795 | |||
796 | fnode = evas_textblock_node_format_next_get(fnode); | ||
797 | fail_if (fnode); | ||
798 | |||
799 | evas_textblock_cursor_char_delete(cur); | ||
800 | } | ||
801 | fnode = evas_textblock_node_format_first_get(tb); | ||
802 | fail_if (!fnode); | ||
803 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
804 | |||
805 | fnode = evas_textblock_node_format_next_get(fnode); | ||
806 | fail_if (!fnode); | ||
807 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b")); | ||
808 | |||
809 | fnode = evas_textblock_node_format_next_get(fnode); | ||
810 | fail_if (fnode); | ||
811 | |||
812 | /* This time with a generic closer */ | ||
813 | evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</>e"); | ||
814 | evas_textblock_cursor_pos_set(cur, 2); | ||
815 | |||
816 | for (i = 0 ; i < 2 ; i++) | ||
817 | { | ||
818 | fnode = evas_textblock_node_format_first_get(tb); | ||
819 | fail_if (!fnode); | ||
820 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
821 | |||
822 | fnode = evas_textblock_node_format_next_get(fnode); | ||
823 | fail_if (!fnode); | ||
824 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i")); | ||
825 | |||
826 | fnode = evas_textblock_node_format_next_get(fnode); | ||
827 | fail_if (!fnode); | ||
828 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b")); | ||
829 | |||
830 | fnode = evas_textblock_node_format_next_get(fnode); | ||
831 | fail_if (!fnode); | ||
832 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
833 | |||
834 | fnode = evas_textblock_node_format_next_get(fnode); | ||
835 | fail_if (fnode); | ||
836 | |||
837 | evas_textblock_cursor_char_delete(cur); | ||
838 | } | ||
839 | fnode = evas_textblock_node_format_first_get(tb); | ||
840 | fail_if (!fnode); | ||
841 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
842 | |||
843 | fnode = evas_textblock_node_format_next_get(fnode); | ||
844 | fail_if (!fnode); | ||
845 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b")); | ||
846 | |||
847 | fnode = evas_textblock_node_format_next_get(fnode); | ||
848 | fail_if (fnode); | ||
849 | |||
850 | /* And now with remove pair. */ | ||
851 | evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</b>d</i>e"); | ||
852 | evas_textblock_cursor_pos_set(cur, 2); | ||
853 | fnode = evas_textblock_node_format_first_get(tb); | ||
854 | evas_textblock_node_format_remove_pair(tb, | ||
855 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
856 | |||
857 | fnode = evas_textblock_node_format_first_get(tb); | ||
858 | fail_if (!fnode); | ||
859 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i")); | ||
860 | |||
861 | fnode = evas_textblock_node_format_next_get(fnode); | ||
862 | fail_if (!fnode); | ||
863 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i")); | ||
864 | |||
865 | fnode = evas_textblock_node_format_next_get(fnode); | ||
866 | fail_if (fnode); | ||
867 | |||
868 | /* Remove the other pair */ | ||
869 | evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</>d</i>e"); | ||
870 | evas_textblock_cursor_pos_set(cur, 2); | ||
871 | fnode = evas_textblock_node_format_first_get(tb); | ||
872 | fnode = evas_textblock_node_format_next_get(fnode); | ||
873 | evas_textblock_node_format_remove_pair(tb, | ||
874 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
875 | |||
876 | fnode = evas_textblock_node_format_first_get(tb); | ||
877 | fail_if (!fnode); | ||
878 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
879 | |||
880 | fnode = evas_textblock_node_format_next_get(fnode); | ||
881 | fail_if (!fnode); | ||
882 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i")); | ||
883 | |||
884 | fnode = evas_textblock_node_format_next_get(fnode); | ||
885 | fail_if (fnode); | ||
886 | |||
887 | /* Remove two pairs with the same name and same positions. */ | ||
888 | evas_object_textblock_text_markup_set(tb, "<a><a>A</a></a>"); | ||
889 | evas_textblock_cursor_pos_set(cur, 0); | ||
890 | evas_textblock_cursor_char_delete(cur); | ||
891 | |||
892 | fnode = evas_textblock_node_format_first_get(tb); | ||
893 | fail_if (fnode); | ||
894 | |||
895 | /* Try to remove a format that doesn't have a pair (with a bad mkup) */ | ||
896 | evas_object_textblock_text_markup_set(tb, "a<b>b<i>c</>d</i>e"); | ||
897 | evas_textblock_cursor_pos_set(cur, 2); | ||
898 | fnode = evas_textblock_node_format_first_get(tb); | ||
899 | evas_textblock_node_format_remove_pair(tb, | ||
900 | (Evas_Object_Textblock_Node_Format *) fnode); | ||
901 | |||
902 | fnode = evas_textblock_node_format_first_get(tb); | ||
903 | fail_if (!fnode); | ||
904 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ i")); | ||
905 | |||
906 | fnode = evas_textblock_node_format_next_get(fnode); | ||
907 | fail_if (!fnode); | ||
908 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
909 | |||
910 | fnode = evas_textblock_node_format_next_get(fnode); | ||
911 | fail_if (!fnode); | ||
912 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- i")); | ||
913 | |||
914 | fnode = evas_textblock_node_format_next_get(fnode); | ||
915 | fail_if (fnode); | ||
916 | |||
917 | END_TB_TEST(); | ||
918 | } | ||
919 | END_TEST | ||
920 | |||
921 | /* Testing items */ | ||
922 | START_TEST(evas_textblock_items) | ||
923 | { | ||
924 | Evas_Coord w, h, w2, h2, nw, nh, ih; | ||
925 | START_TB_TEST(); | ||
926 | const char *buf = "This is an <item absize=93x152></>."; | ||
927 | |||
928 | /* Absolute item size */ | ||
929 | buf = "This is an <item absize=93x152 vsize=full></>."; | ||
930 | evas_object_textblock_text_markup_set(tb, buf); | ||
931 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
932 | fail_if((w < 93) || (h != 152)); | ||
933 | evas_textblock_cursor_pos_set(cur, 11); | ||
934 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
935 | fail_if((w != 93) || (h != 152)); | ||
936 | |||
937 | buf = "This is an <item absize=93x152 vsize=ascent></>."; | ||
938 | evas_object_textblock_text_markup_set(tb, buf); | ||
939 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
940 | fail_if((w < 93) || (h <= 152)); | ||
941 | evas_textblock_cursor_pos_set(cur, 11); | ||
942 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
943 | fail_if((w != 93) || (h != 152)); | ||
944 | |||
945 | /* Size is the same as abssize, unless there's scaling applied. */ | ||
946 | buf = "This is an <item size=93x152 vsize=full></>."; | ||
947 | evas_object_textblock_text_markup_set(tb, buf); | ||
948 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
949 | fail_if((w < 93) || (h != 152)); | ||
950 | evas_textblock_cursor_pos_set(cur, 11); | ||
951 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
952 | fail_if((w != 93) || (h != 152)); | ||
953 | |||
954 | buf = "This is an <item size=93x152 vsize=ascent></>."; | ||
955 | evas_object_textblock_text_markup_set(tb, buf); | ||
956 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
957 | fail_if((w < 93) || (h <= 152)); | ||
958 | evas_textblock_cursor_pos_set(cur, 11); | ||
959 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
960 | fail_if((w != 93) || (h != 152)); | ||
961 | |||
962 | evas_object_scale_set(tb, 2.0); | ||
963 | buf = "This is an <item size=93x152 vsize=full></>."; | ||
964 | evas_object_textblock_text_markup_set(tb, buf); | ||
965 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
966 | fail_if((w < (2 * 93)) || (h != (2 * 152))); | ||
967 | evas_textblock_cursor_pos_set(cur, 11); | ||
968 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
969 | fail_if((w != (2 * 93)) || (h != (2 * 152))); | ||
970 | evas_textblock_cursor_pos_set(cur, 11); | ||
971 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
972 | fail_if((w != (2 * 93)) || (h != (2 * 152))); | ||
973 | |||
974 | buf = "This is an <item size=93x152 vsize=ascent></>."; | ||
975 | evas_object_textblock_text_markup_set(tb, buf); | ||
976 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
977 | fail_if((w < (2 * 93)) || (h <= (2 * 152))); | ||
978 | evas_textblock_cursor_pos_set(cur, 11); | ||
979 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
980 | fail_if((w != (2 * 93)) || (h != (2 * 152))); | ||
981 | |||
982 | evas_object_scale_set(tb, 1.0); | ||
983 | |||
984 | /* Relsize */ | ||
985 | /* relsize means it should adjust itself to the size of the line */ | ||
986 | buf = "This is an <item relsize=93x152 vsize=full></>."; | ||
987 | evas_object_textblock_text_markup_set(tb, buf); | ||
988 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
989 | fail_if((w >= 93) || (h >= 152)); | ||
990 | evas_textblock_cursor_pos_set(cur, 11); | ||
991 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &ih); | ||
992 | fail_if((w > 90) || (h != ih)); | ||
993 | |||
994 | buf = "This is an <item relize=93x152 vsize=ascent></>."; | ||
995 | evas_object_textblock_text_markup_set(tb, buf); | ||
996 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
997 | fail_if((w >= 93) || (h >= 152)); | ||
998 | evas_textblock_cursor_pos_set(cur, 11); | ||
999 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &ih); | ||
1000 | fail_if((w > 90) || (h <= ih)); | ||
1001 | |||
1002 | /* Relsize and abs size in the same line, all should be the same size */ | ||
1003 | buf = "<item relsize=64x64 vsize=ascent href=emoticon/knowing-grin></item><item absize=64x64 vsize=ascent href=emoticon/knowing-grin></item><item relsize=64x64 vsize=ascent href=emoticon/knowing-grin></item>"; | ||
1004 | evas_object_textblock_text_markup_set(tb, buf); | ||
1005 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1006 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1007 | fail_if((nw != w) || (nh != h)); | ||
1008 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
1009 | evas_textblock_cursor_char_next(cur); | ||
1010 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w2, &h2); | ||
1011 | fail_if((w != w2) || (h != h2)); | ||
1012 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w, &h); | ||
1013 | evas_textblock_cursor_char_next(cur); | ||
1014 | evas_textblock_cursor_format_item_geometry_get(cur, NULL, NULL, &w2, &h2); | ||
1015 | fail_if((w != w2) || (h != h2)); | ||
1016 | |||
1017 | /* FIXME: Also verify x,y positions of the item. */ | ||
1018 | |||
1019 | /* FIXME We need some item tests that involve line wrapping that make the | ||
1020 | * items move between lines that are in different sizes. | ||
1021 | * Also, tests that involve wrapping positions with relsized items. We | ||
1022 | * want to make sure the item gets a relsize on the correct time (before | ||
1023 | * the wrapping, and then is updated after the wrapping) and that | ||
1024 | * all the lines have the correct sizes afterwards. */ | ||
1025 | |||
1026 | END_TB_TEST(); | ||
1027 | } | ||
1028 | END_TEST | ||
1029 | |||
1030 | /* Wrapping tests */ | ||
1031 | START_TEST(evas_textblock_wrapping) | ||
1032 | { | ||
1033 | Evas_Coord bw, bh, w, h, nw, nh; | ||
1034 | int i; | ||
1035 | START_TB_TEST(); | ||
1036 | evas_object_textblock_text_markup_set(tb, "a"); | ||
1037 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1038 | |||
1039 | /* Char wrap */ | ||
1040 | evas_object_textblock_text_markup_set(tb, "aaaaaaa"); | ||
1041 | evas_textblock_cursor_format_prepend(cur, "+ wrap=char"); | ||
1042 | evas_object_resize(tb, bw, bh); | ||
1043 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1044 | /* Wrap to minimum */ | ||
1045 | fail_if(w != bw); | ||
1046 | fail_if(h <= bh); | ||
1047 | |||
1048 | /* Mixed - fallback to char wrap */ | ||
1049 | evas_object_textblock_text_markup_set(tb, "aaaaaaa"); | ||
1050 | evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed"); | ||
1051 | evas_object_resize(tb, bw, bh); | ||
1052 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1053 | /* Wrap to minimum */ | ||
1054 | fail_if(w != bw); | ||
1055 | fail_if(h <= bh); | ||
1056 | |||
1057 | /* Basic Word wrap */ | ||
1058 | evas_object_textblock_text_markup_set(tb, "aaaa"); | ||
1059 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1060 | |||
1061 | evas_object_textblock_text_markup_set(tb, "aaaa aa"); | ||
1062 | evas_textblock_cursor_format_prepend(cur, "+ wrap=word"); | ||
1063 | evas_object_resize(tb, bw, bh); | ||
1064 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1065 | /* Wrap to minimum */ | ||
1066 | fail_if(w != bw); | ||
1067 | fail_if(h <= bh); | ||
1068 | |||
1069 | /* Mixed - fallback to word wrap */ | ||
1070 | evas_object_textblock_text_markup_set(tb, "aaaa aa"); | ||
1071 | evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed"); | ||
1072 | evas_object_resize(tb, bw + 1, bh); | ||
1073 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1074 | /* Wrap to minimum */ | ||
1075 | fail_if(w != bw); | ||
1076 | fail_if(h <= bh); | ||
1077 | |||
1078 | /* Wrap and then expand again. */ | ||
1079 | evas_object_textblock_text_markup_set(tb, "aaaa aa"); | ||
1080 | evas_textblock_cursor_format_prepend(cur, "+ wrap=word"); | ||
1081 | evas_object_resize(tb, bw, bh); | ||
1082 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1083 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1084 | evas_object_resize(tb, nw, nh); | ||
1085 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1086 | fail_if((w != nw) || (h != nh)); | ||
1087 | |||
1088 | /* Reduce size until reaching the minimum, making sure we don't | ||
1089 | * get something wrong along the way */ | ||
1090 | /* Char wrap */ | ||
1091 | evas_object_textblock_text_markup_set(tb, "a"); | ||
1092 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1093 | evas_object_textblock_text_markup_set(tb, | ||
1094 | "aaaa aaaa aaa aa aaa<ps>" | ||
1095 | "aaaa aaa aaa aaa aaa<ps>" | ||
1096 | "a aaaaa aaaaaaaaaaaaaa<br>aaaaa<ps>" | ||
1097 | "aaaaaa" | ||
1098 | ); | ||
1099 | evas_textblock_cursor_format_prepend(cur, "+ wrap=char"); | ||
1100 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1101 | |||
1102 | Evas_Coord iw; | ||
1103 | for (iw = nw ; iw >= bw ; iw--) | ||
1104 | { | ||
1105 | evas_object_resize(tb, iw, 1000); | ||
1106 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1107 | fail_if(w < bw); | ||
1108 | fail_if(w > iw); | ||
1109 | } | ||
1110 | fail_if(w != bw); | ||
1111 | |||
1112 | /* Word wrap */ | ||
1113 | evas_object_textblock_text_markup_set(tb, "aaaaaa"); | ||
1114 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1115 | evas_object_textblock_text_markup_set(tb, | ||
1116 | "aaaa aaaa aaa aa aaa<ps>" | ||
1117 | "aaaa aaa aaa aaa aaa<ps>" | ||
1118 | "a aaaaa aaaaaa<br>aaaaa<ps>" | ||
1119 | "aaaaa" | ||
1120 | ); | ||
1121 | evas_textblock_cursor_format_prepend(cur, "+ wrap=word"); | ||
1122 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1123 | |||
1124 | for (iw = nw ; iw >= bw ; iw--) | ||
1125 | { | ||
1126 | evas_object_resize(tb, iw, 1000); | ||
1127 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1128 | fail_if(w < bw); | ||
1129 | fail_if(w > iw); | ||
1130 | } | ||
1131 | fail_if(w != bw); | ||
1132 | |||
1133 | /* Mixed wrap */ | ||
1134 | evas_object_textblock_text_markup_set(tb, "a"); | ||
1135 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1136 | evas_object_textblock_text_markup_set(tb, | ||
1137 | "aaaa aaaa aaa aa aaa<ps>" | ||
1138 | "aaaa aaa aaa aaa aaa<ps>" | ||
1139 | "a aaaaa aaaaaa<br>aaaaa<ps>" | ||
1140 | "aaaaa" | ||
1141 | ); | ||
1142 | evas_textblock_cursor_format_prepend(cur, "+ wrap=mixed"); | ||
1143 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1144 | |||
1145 | for (iw = nw ; iw >= bw ; iw--) | ||
1146 | { | ||
1147 | evas_object_resize(tb, iw, 1000); | ||
1148 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1149 | fail_if(w < bw); | ||
1150 | fail_if(w > iw); | ||
1151 | } | ||
1152 | fail_if(w != bw); | ||
1153 | |||
1154 | /* Resize, making sure we keep going down in the minimum size. */ | ||
1155 | char *wrap_style[] = { "+ wrap=word", "+ wrap=char", "+ wrap=mixed" }; | ||
1156 | int wrap_items = sizeof(wrap_style) / sizeof(*wrap_style); | ||
1157 | |||
1158 | evas_object_textblock_text_markup_set(tb, | ||
1159 | "This is an entry widget in this window that<br>" | ||
1160 | "uses markup <b>like this</> for styling and<br>" | ||
1161 | "formatting <em>like this</>, as well as<br>" | ||
1162 | "<a href=X><link>links in the text</></a>, so enter text<br>" | ||
1163 | "in here to edit it. By the way, links are<br>" | ||
1164 | "called <a href=anc-02>Anchors</a> so you will need<br>" | ||
1165 | "to refer to them this way.<br>" | ||
1166 | "<br>" | ||
1167 | |||
1168 | "Also you can stick in items with (relsize + ascent): " | ||
1169 | "<item relsize=16x16 vsize=ascent href=emoticon/evil-laugh></item>" | ||
1170 | " (full) " | ||
1171 | "<item relsize=16x16 vsize=full href=emoticon/guilty-smile></item>" | ||
1172 | " (to the left)<br>" | ||
1173 | |||
1174 | "Also (size + ascent): " | ||
1175 | "<item size=16x16 vsize=ascent href=emoticon/haha></item>" | ||
1176 | " (full) " | ||
1177 | "<item size=16x16 vsize=full href=emoticon/happy-panting></item>" | ||
1178 | " (before this)<br>" | ||
1179 | |||
1180 | "And as well (absize + ascent): " | ||
1181 | "<item absize=64x64 vsize=ascent href=emoticon/knowing-grin></item>" | ||
1182 | " (full) " | ||
1183 | "<item absize=64x64 vsize=full href=emoticon/not-impressed></item>" | ||
1184 | " or even paths to image files on disk too like: " | ||
1185 | "<item absize=96x128 vsize=full href=file://%s/images/sky_01.jpg></item>" | ||
1186 | " ... end." | ||
1187 | ); | ||
1188 | |||
1189 | /* Get minimum size */ | ||
1190 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1191 | |||
1192 | for (i = 0 ; i < wrap_items ; i++) | ||
1193 | { | ||
1194 | evas_textblock_cursor_format_prepend(cur, wrap_style[i]); | ||
1195 | evas_object_resize(tb, 0, 0); | ||
1196 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1197 | |||
1198 | for (iw = nw ; iw >= bw ; iw--) | ||
1199 | { | ||
1200 | evas_object_resize(tb, iw, 1000); | ||
1201 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1202 | fail_if(w < bw); | ||
1203 | fail_if(w > iw); | ||
1204 | } | ||
1205 | fail_if(w != bw); | ||
1206 | } | ||
1207 | |||
1208 | |||
1209 | /* Ellipsis */ | ||
1210 | evas_object_textblock_text_markup_set(tb, "aaaaaaaaaa"); | ||
1211 | evas_textblock_cursor_format_prepend(cur, "+ ellipsis=1.0"); | ||
1212 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1213 | evas_object_resize(tb, nw / 2, nh); | ||
1214 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1215 | fail_if((w > (nw / 2)) || (h != nh)); | ||
1216 | |||
1217 | END_TB_TEST(); | ||
1218 | } | ||
1219 | END_TEST | ||
1220 | |||
1221 | /* Various textblock stuff */ | ||
1222 | START_TEST(evas_textblock_various) | ||
1223 | { | ||
1224 | Evas_Coord w, h, bw, bh; | ||
1225 | START_TB_TEST(); | ||
1226 | const char *buf = "This<ps>textblock<ps>has<ps>a<ps>lot<ps>of<ps>lines<ps>."; | ||
1227 | evas_object_textblock_text_markup_set(tb, buf); | ||
1228 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1229 | /* Move outside of the screen so it'll have to search for the correct | ||
1230 | * paragraph and etc. */ | ||
1231 | evas_object_move(tb, -(w / 2), -(h / 2)); | ||
1232 | |||
1233 | /* Replacement char */ | ||
1234 | evas_object_textblock_text_markup_set(tb, "*"); | ||
1235 | evas_object_textblock_size_formatted_get(tb, &bw, &bh); | ||
1236 | evas_object_textblock_replace_char_set(tb, "*"); | ||
1237 | evas_object_textblock_text_markup_set(tb, "|"); | ||
1238 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1239 | fail_if((w != bw) || (h != bh)); | ||
1240 | |||
1241 | /* Items have correct text node information */ | ||
1242 | evas_object_textblock_text_markup_set(tb, ""); | ||
1243 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1244 | evas_object_textblock_text_markup_set(tb, "<ps>"); | ||
1245 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1246 | evas_object_textblock_text_markup_set(tb, "a<ps>"); | ||
1247 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1248 | evas_object_textblock_text_markup_set(tb, "a<ps>a"); | ||
1249 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1250 | evas_object_textblock_text_markup_set(tb, "a<ps>a<ps>"); | ||
1251 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1252 | evas_object_textblock_text_markup_set(tb, "a<ps>a<ps>a"); | ||
1253 | fail_if(!_evas_textblock_check_item_node_link(tb)); | ||
1254 | |||
1255 | END_TB_TEST(); | ||
1256 | } | ||
1257 | END_TEST | ||
1258 | |||
1259 | /* Various geometries. e.g. range geometry. */ | ||
1260 | START_TEST(evas_textblock_geometries) | ||
1261 | { | ||
1262 | START_TB_TEST(); | ||
1263 | const char *buf = "This is a <br> test."; | ||
1264 | evas_object_textblock_text_markup_set(tb, buf); | ||
1265 | |||
1266 | /* Single line range */ | ||
1267 | Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb); | ||
1268 | evas_textblock_cursor_pos_set(cur, 0); | ||
1269 | evas_textblock_cursor_pos_set(main_cur, 6); | ||
1270 | |||
1271 | Eina_List *rects, *rects2; | ||
1272 | Evas_Textblock_Rectangle *tr, *tr2; | ||
1273 | rects = evas_textblock_cursor_range_geometry_get(cur, main_cur); | ||
1274 | fail_if(!rects); | ||
1275 | rects2 = evas_textblock_cursor_range_geometry_get(main_cur, cur); | ||
1276 | fail_if(!rects2); | ||
1277 | |||
1278 | fail_if(eina_list_count(rects) != 1); | ||
1279 | fail_if(eina_list_count(rects2) != 1); | ||
1280 | |||
1281 | tr = eina_list_data_get(rects); | ||
1282 | fail_if((tr->h <= 0) || (tr->w <= 0)); | ||
1283 | tr2 = eina_list_data_get(rects2); | ||
1284 | fail_if((tr2->h <= 0) || (tr2->w <= 0)); | ||
1285 | |||
1286 | fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) || | ||
1287 | (tr->h != tr2->h)); | ||
1288 | |||
1289 | /* Multiline range */ | ||
1290 | evas_textblock_cursor_pos_set(cur, 0); | ||
1291 | evas_textblock_cursor_pos_set(main_cur, 14); | ||
1292 | |||
1293 | rects = evas_textblock_cursor_range_geometry_get(cur, main_cur); | ||
1294 | fail_if(!rects); | ||
1295 | rects2 = evas_textblock_cursor_range_geometry_get(main_cur, cur); | ||
1296 | fail_if(!rects2); | ||
1297 | |||
1298 | fail_if(eina_list_count(rects) != 2); | ||
1299 | fail_if(eina_list_count(rects2) != 2); | ||
1300 | |||
1301 | tr = eina_list_data_get(rects); | ||
1302 | fail_if((tr->h <= 0) || (tr->w <= 0)); | ||
1303 | tr2 = eina_list_data_get(rects2); | ||
1304 | fail_if((tr2->h <= 0) || (tr2->w <= 0)); | ||
1305 | |||
1306 | fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) || | ||
1307 | (tr->h != tr2->h)); | ||
1308 | |||
1309 | tr = eina_list_data_get(eina_list_next(rects)); | ||
1310 | fail_if((tr->h <= 0) || (tr->w <= 0)); | ||
1311 | tr2 = eina_list_data_get(eina_list_next(rects2)); | ||
1312 | fail_if((tr2->h <= 0) || (tr2->w <= 0)); | ||
1313 | |||
1314 | fail_if((tr->x != tr2->x) || (tr->y != tr2->y) || (tr->w != tr2->w) || | ||
1315 | (tr->h != tr2->h)); | ||
1316 | |||
1317 | /* Check that the second line is positioned below the first */ | ||
1318 | tr = eina_list_data_get(rects); | ||
1319 | tr2 = eina_list_data_get(eina_list_next(rects)); | ||
1320 | fail_if(tr->y >= tr2->y); | ||
1321 | |||
1322 | END_TB_TEST(); | ||
1323 | } | ||
1324 | END_TEST | ||
1325 | |||
1326 | /* Should handle all the text editing. */ | ||
1327 | START_TEST(evas_textblock_editing) | ||
1328 | { | ||
1329 | START_TB_TEST(); | ||
1330 | const char *buf = "First par.<ps>Second par."; | ||
1331 | evas_object_textblock_text_markup_set(tb, buf); | ||
1332 | Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb); | ||
1333 | |||
1334 | /* Check deletion works */ | ||
1335 | /* Try deleting after the end of the textblock */ | ||
1336 | { | ||
1337 | char *content; | ||
1338 | evas_textblock_cursor_paragraph_last(cur); | ||
1339 | content = strdup(evas_object_textblock_text_markup_get(tb)); | ||
1340 | evas_textblock_cursor_char_delete(cur); | ||
1341 | fail_if(strcmp(content, evas_object_textblock_text_markup_get(tb))); | ||
1342 | free(content); | ||
1343 | } | ||
1344 | |||
1345 | /* Delete the first char */ | ||
1346 | evas_textblock_cursor_paragraph_first(cur); | ||
1347 | evas_textblock_cursor_char_delete(cur); | ||
1348 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), | ||
1349 | "irst par.<ps>Second par.")); | ||
1350 | |||
1351 | /* Delete some arbitrary char */ | ||
1352 | evas_textblock_cursor_char_next(cur); | ||
1353 | evas_textblock_cursor_char_next(cur); | ||
1354 | evas_textblock_cursor_char_next(cur); | ||
1355 | evas_textblock_cursor_char_delete(cur); | ||
1356 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), | ||
1357 | "irs par.<ps>Second par.")); | ||
1358 | |||
1359 | /* Delete a range */ | ||
1360 | evas_textblock_cursor_pos_set(main_cur, 1); | ||
1361 | evas_textblock_cursor_pos_set(cur, 6); | ||
1362 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
1363 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), | ||
1364 | "ir.<ps>Second par.")); | ||
1365 | evas_textblock_cursor_paragraph_char_first(main_cur); | ||
1366 | evas_textblock_cursor_paragraph_char_last(cur); | ||
1367 | evas_textblock_cursor_char_next(cur); | ||
1368 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
1369 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), | ||
1370 | "Second par.")); | ||
1371 | |||
1372 | evas_object_textblock_text_markup_set(tb, buf); | ||
1373 | evas_textblock_cursor_paragraph_last(main_cur); | ||
1374 | evas_object_textblock_text_markup_prepend(main_cur, "Test<b>bla</b>bla."); | ||
1375 | evas_textblock_cursor_paragraph_last(cur); | ||
1376 | evas_textblock_cursor_paragraph_char_first(main_cur); | ||
1377 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
1378 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), | ||
1379 | "First par.<ps>")); | ||
1380 | |||
1381 | /* Merging paragraphs */ | ||
1382 | evas_object_textblock_text_markup_set(tb, buf); | ||
1383 | evas_textblock_cursor_paragraph_char_last(cur); | ||
1384 | evas_textblock_cursor_copy(cur, main_cur); | ||
1385 | evas_textblock_cursor_char_delete(cur); | ||
1386 | |||
1387 | evas_textblock_cursor_paragraph_first(cur); | ||
1388 | fail_if(evas_textblock_cursor_paragraph_next(cur)); | ||
1389 | |||
1390 | /* Split paragraphs */ | ||
1391 | evas_textblock_cursor_format_prepend(cur, "ps"); | ||
1392 | |||
1393 | evas_textblock_cursor_paragraph_first(cur); | ||
1394 | fail_if(!evas_textblock_cursor_paragraph_next(cur)); | ||
1395 | fail_if(evas_textblock_cursor_paragraph_next(cur)); | ||
1396 | |||
1397 | /* Merge paragraphs using range deletion */ | ||
1398 | evas_object_textblock_text_markup_set(tb, buf); | ||
1399 | evas_textblock_cursor_paragraph_first(cur); | ||
1400 | evas_textblock_cursor_paragraph_char_last(cur); | ||
1401 | evas_textblock_cursor_copy(cur, main_cur); | ||
1402 | evas_textblock_cursor_char_prev(cur); | ||
1403 | evas_textblock_cursor_char_next(main_cur); | ||
1404 | |||
1405 | evas_textblock_cursor_range_delete(cur, main_cur); | ||
1406 | evas_textblock_cursor_paragraph_first(cur); | ||
1407 | fail_if(evas_textblock_cursor_paragraph_next(cur)); | ||
1408 | |||
1409 | /* FIXME: Also add text appending/prepending */ | ||
1410 | |||
1411 | END_TB_TEST(); | ||
1412 | } | ||
1413 | END_TEST | ||
1414 | |||
1415 | /* Text getters */ | ||
1416 | START_TEST(evas_textblock_text_getters) | ||
1417 | { | ||
1418 | START_TB_TEST(); | ||
1419 | const char *buf = "This is a <br> test.<ps>" | ||
1420 | "טקסט בעברית<ps>and now in english."; | ||
1421 | evas_object_textblock_text_markup_set(tb, buf); | ||
1422 | evas_textblock_cursor_paragraph_first(cur); | ||
1423 | |||
1424 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
1425 | "This is a <br> test.")); | ||
1426 | |||
1427 | evas_textblock_cursor_paragraph_next(cur); | ||
1428 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
1429 | "טקסט בעברית")); | ||
1430 | |||
1431 | evas_textblock_cursor_paragraph_next(cur); | ||
1432 | fail_if(strcmp(evas_textblock_cursor_paragraph_text_get(cur), | ||
1433 | "and now in english.")); | ||
1434 | |||
1435 | /* Range get */ | ||
1436 | Evas_Textblock_Cursor *main_cur = evas_object_textblock_cursor_get(tb); | ||
1437 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
1438 | evas_textblock_cursor_pos_set(cur, 2); | ||
1439 | fail_if(*evas_textblock_cursor_range_text_get(main_cur, cur, | ||
1440 | EVAS_TEXTBLOCK_TEXT_MARKUP)); | ||
1441 | |||
1442 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
1443 | evas_textblock_cursor_pos_set(cur, 6); | ||
1444 | fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur, | ||
1445 | EVAS_TEXTBLOCK_TEXT_MARKUP), "is i")); | ||
1446 | |||
1447 | evas_textblock_cursor_pos_set(main_cur, 5); | ||
1448 | evas_textblock_cursor_pos_set(cur, 14); | ||
1449 | fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur, | ||
1450 | EVAS_TEXTBLOCK_TEXT_MARKUP), "is a <br> te")); | ||
1451 | |||
1452 | evas_textblock_cursor_pos_set(main_cur, 14); | ||
1453 | evas_textblock_cursor_pos_set(cur, 20); | ||
1454 | fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur, | ||
1455 | EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps>טק")); | ||
1456 | |||
1457 | evas_textblock_cursor_pos_set(main_cur, 14); | ||
1458 | evas_textblock_cursor_pos_set(cur, 32); | ||
1459 | fail_if(strcmp(evas_textblock_cursor_range_text_get(main_cur, cur, | ||
1460 | EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps>טקסט בעברית<ps>an")); | ||
1461 | |||
1462 | /* Backward range get */ | ||
1463 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
1464 | evas_textblock_cursor_pos_set(cur, 2); | ||
1465 | fail_if(*evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1466 | EVAS_TEXTBLOCK_TEXT_MARKUP)); | ||
1467 | |||
1468 | evas_textblock_cursor_pos_set(main_cur, 2); | ||
1469 | evas_textblock_cursor_pos_set(cur, 6); | ||
1470 | fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1471 | EVAS_TEXTBLOCK_TEXT_MARKUP), "is i")); | ||
1472 | |||
1473 | evas_textblock_cursor_pos_set(main_cur, 5); | ||
1474 | evas_textblock_cursor_pos_set(cur, 14); | ||
1475 | fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1476 | EVAS_TEXTBLOCK_TEXT_MARKUP), "is a <br> te")); | ||
1477 | |||
1478 | evas_textblock_cursor_pos_set(main_cur, 14); | ||
1479 | evas_textblock_cursor_pos_set(cur, 20); | ||
1480 | fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1481 | EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps>טק")); | ||
1482 | |||
1483 | evas_textblock_cursor_pos_set(main_cur, 14); | ||
1484 | evas_textblock_cursor_pos_set(cur, 32); | ||
1485 | fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1486 | EVAS_TEXTBLOCK_TEXT_MARKUP), "st.<ps>טקסט בעברית<ps>an")); | ||
1487 | |||
1488 | /* Uninit cursors and other weird cases */ | ||
1489 | evas_object_textblock_clear(tb); | ||
1490 | evas_textblock_cursor_copy(main_cur, cur); | ||
1491 | evas_textblock_cursor_text_prepend(main_cur, "aaa"); | ||
1492 | fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur, | ||
1493 | EVAS_TEXTBLOCK_TEXT_MARKUP), "aaa")); | ||
1494 | |||
1495 | END_TB_TEST(); | ||
1496 | } | ||
1497 | END_TEST | ||
1498 | |||
1499 | /* Formats */ | ||
1500 | START_TEST(evas_textblock_formats) | ||
1501 | { | ||
1502 | START_TB_TEST(); | ||
1503 | const char *buf = "Th<b>i<font_size=15 wrap=none>s i</font_size=13>s</> a <br> te<ps>st<item></>."; | ||
1504 | const Evas_Object_Textblock_Node_Format *fnode; | ||
1505 | evas_object_textblock_text_markup_set(tb, buf); | ||
1506 | |||
1507 | /* Walk from the start */ | ||
1508 | fnode = evas_textblock_node_format_first_get(tb); | ||
1509 | fail_if(!fnode); | ||
1510 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
1511 | |||
1512 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1513 | fail_if(!fnode); | ||
1514 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
1515 | "+ font_size=15 wrap=none")); | ||
1516 | |||
1517 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1518 | fail_if(!fnode); | ||
1519 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
1520 | "- font_size=13")); | ||
1521 | |||
1522 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1523 | fail_if(!fnode); | ||
1524 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
1525 | |||
1526 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1527 | fail_if(!fnode); | ||
1528 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "br")); | ||
1529 | |||
1530 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1531 | fail_if(!fnode); | ||
1532 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "ps")); | ||
1533 | |||
1534 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1535 | fail_if(!fnode); | ||
1536 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item")); | ||
1537 | |||
1538 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1539 | fail_if(!fnode); | ||
1540 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
1541 | |||
1542 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1543 | fail_if(fnode); | ||
1544 | |||
1545 | /* Walk backwards */ | ||
1546 | fnode = evas_textblock_node_format_last_get(tb); | ||
1547 | fail_if(!fnode); | ||
1548 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
1549 | |||
1550 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1551 | fail_if(!fnode); | ||
1552 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item")); | ||
1553 | |||
1554 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1555 | fail_if(!fnode); | ||
1556 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "ps")); | ||
1557 | |||
1558 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1559 | fail_if(!fnode); | ||
1560 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "br")); | ||
1561 | |||
1562 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1563 | fail_if(!fnode); | ||
1564 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- ")); | ||
1565 | |||
1566 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1567 | fail_if(!fnode); | ||
1568 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
1569 | "- font_size=13")); | ||
1570 | |||
1571 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1572 | fail_if(!fnode); | ||
1573 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), | ||
1574 | "+ font_size=15 wrap=none")); | ||
1575 | |||
1576 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1577 | fail_if(!fnode); | ||
1578 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
1579 | |||
1580 | fnode = evas_textblock_node_format_prev_get(fnode); | ||
1581 | fail_if(fnode); | ||
1582 | |||
1583 | /* Cursor and format detection */ | ||
1584 | fnode = evas_textblock_node_format_first_get(tb); | ||
1585 | fail_if(!fnode); | ||
1586 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1587 | fail_if(evas_textblock_cursor_format_is_visible_get(cur)); | ||
1588 | |||
1589 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1590 | fail_if(!fnode); | ||
1591 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1592 | fail_if(evas_textblock_cursor_format_is_visible_get(cur)); | ||
1593 | |||
1594 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1595 | fail_if(!fnode); | ||
1596 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1597 | fail_if(evas_textblock_cursor_format_is_visible_get(cur)); | ||
1598 | |||
1599 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1600 | fail_if(!fnode); | ||
1601 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1602 | fail_if(evas_textblock_cursor_format_is_visible_get(cur)); | ||
1603 | |||
1604 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1605 | fail_if(!fnode); | ||
1606 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1607 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1608 | |||
1609 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1610 | fail_if(!fnode); | ||
1611 | evas_textblock_cursor_at_format_set(cur, fnode); | ||
1612 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1613 | |||
1614 | size_t i = 0; | ||
1615 | evas_textblock_cursor_paragraph_first(cur); | ||
1616 | do | ||
1617 | { | ||
1618 | switch (i) | ||
1619 | { | ||
1620 | case 2: | ||
1621 | case 3: | ||
1622 | case 6: | ||
1623 | case 7: | ||
1624 | case 10: | ||
1625 | case 14: | ||
1626 | case 17: | ||
1627 | case 18: | ||
1628 | fail_if(!evas_textblock_cursor_is_format(cur)); | ||
1629 | break; | ||
1630 | default: | ||
1631 | fail_if(evas_textblock_cursor_is_format(cur)); | ||
1632 | fail_if(evas_textblock_cursor_format_is_visible_get(cur)); | ||
1633 | break; | ||
1634 | } | ||
1635 | i++; | ||
1636 | } | ||
1637 | while (evas_textblock_cursor_char_next(cur)); | ||
1638 | |||
1639 | /* Format text nodes invalidation */ | ||
1640 | { | ||
1641 | Evas_Coord w, h, nw, nh; | ||
1642 | evas_object_textblock_text_markup_set(tb, "Test"); | ||
1643 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1644 | evas_textblock_cursor_paragraph_first(cur); | ||
1645 | evas_textblock_cursor_format_prepend(cur, "+ font_size=40"); | ||
1646 | evas_object_textblock_size_formatted_get(tb, &nw, &nh); | ||
1647 | fail_if((w >= nw) || (h >= nh)); | ||
1648 | } | ||
1649 | /* FIXME: Should extend invalidation tests. */ | ||
1650 | |||
1651 | /* Various formats, just verify there's no seg, we can't really | ||
1652 | * verify them visually, well, we can some of them. Possibly in the | ||
1653 | * future we will */ | ||
1654 | evas_object_textblock_text_markup_set(tb, | ||
1655 | "<font_size=40>font_size=40</><ps>" | ||
1656 | "<color=#F210B3FF>color=#F210B3FF</><ps>" | ||
1657 | "<underline=single underline_color=#A2B3C4>underline=single underline_color=#A2B3C4</><ps>" | ||
1658 | "<underline=double underline_color=#F00 underline2_color=#00F>underline=double underline_color=#F00 underline2_color=#00F</><ps>" | ||
1659 | "<underline=dashed underline_dash_color=#0F0 underline_dash_width=2 underline_dash_gap=1>underline=dashed underline_dash_color=#0F0 underline_dash_width=2 underline_dash_gap=1</><ps>" | ||
1660 | "<style=outline outline_color=#F0FA>style=outline outline_color=#F0FA</><ps>" | ||
1661 | "<style=shadow shadow_color=#F0F>style=shadow shadow_color=#F0F</><ps>" | ||
1662 | "<style=glow glow_color=#BBB>style=glow glow_color=#BBB</><ps>" | ||
1663 | "<style=glow glow2_color=#0F0>style=glow glow2_color=#0F0</><ps>" | ||
1664 | "<style=glow color=#fff glow2_color=#fe87 glow_color=#f214>style=glow color=#fff glow2_color=#fe87 glow_color=#f214</><ps>" | ||
1665 | "<backing=on backing_color=#00F>backing=on backing_color=#00F</><ps>" | ||
1666 | "<strikethrough=on strikethrough_color=#FF0>strikethrough=on strikethrough_color=#FF0</><ps>" | ||
1667 | "<align=right>align=right</><ps>" | ||
1668 | "<backing=on backing_color=#F008 valign=0.0>valign=0.0</><ps>" | ||
1669 | "<backing=on backing_color=#0F08 tabstops=50>tabstops=<\\t></>50</><ps>" | ||
1670 | "<backing=on backing_color=#00F8 linesize=40>linesize=40</><ps>" | ||
1671 | "<backing=on backing_color=#F0F8 linerelsize=200%>linerelsize=200%</><ps>" | ||
1672 | "<backing=on backing_color=#0FF8 linegap=20>linegap=20</><ps>" | ||
1673 | "<backing=on backing_color=#FF08 linerelgap=100%>linerelgap=100%</><ps>"); | ||
1674 | |||
1675 | /* Force a relayout */ | ||
1676 | evas_object_textblock_size_formatted_get(tb, NULL, NULL); | ||
1677 | |||
1678 | /* Removing paired formats. */ | ||
1679 | evas_object_textblock_text_markup_set(tb, "<a>aa<b>bb</b>cc</a>"); | ||
1680 | fnode = evas_textblock_node_format_first_get(tb); | ||
1681 | evas_textblock_node_format_remove_pair(tb, (Evas_Object_Textblock_Node_Format *) fnode); | ||
1682 | fnode = evas_textblock_node_format_first_get(tb); | ||
1683 | fail_if(!fnode); | ||
1684 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ b")); | ||
1685 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1686 | fail_if(!fnode); | ||
1687 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- b")); | ||
1688 | |||
1689 | evas_object_textblock_text_markup_set(tb, "<a>aa<b>bb</b>cc</a>"); | ||
1690 | fnode = evas_textblock_node_format_first_get(tb); | ||
1691 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1692 | evas_textblock_node_format_remove_pair(tb, (Evas_Object_Textblock_Node_Format *) fnode); | ||
1693 | fnode = evas_textblock_node_format_first_get(tb); | ||
1694 | fail_if(!fnode); | ||
1695 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ a")); | ||
1696 | fnode = evas_textblock_node_format_next_get(fnode); | ||
1697 | fail_if(!fnode); | ||
1698 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "- a")); | ||
1699 | |||
1700 | /* Format list get */ | ||
1701 | evas_object_textblock_text_markup_set(tb, "<a>a</>a<item>b</>" | ||
1702 | "b<item>b</>c<a>c</>"); | ||
1703 | const Eina_List *flist = evas_textblock_node_format_list_get(tb, "a"); | ||
1704 | const Eina_List *itr; | ||
1705 | EINA_LIST_FOREACH(flist, itr, fnode) | ||
1706 | { | ||
1707 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ a")); | ||
1708 | } | ||
1709 | |||
1710 | flist = evas_textblock_node_format_list_get(tb, "item"); | ||
1711 | EINA_LIST_FOREACH(flist, itr, fnode) | ||
1712 | { | ||
1713 | fail_if(strcmp(evas_textblock_node_format_text_get(fnode), "+ item")); | ||
1714 | } | ||
1715 | |||
1716 | /* Make sure we get all the types of visible formats correctly. */ | ||
1717 | evas_object_textblock_text_markup_set(tb, "<ps>a<br>a<tab>a<item></>"); | ||
1718 | fail_if(strcmp(evas_textblock_node_format_text_get( | ||
1719 | evas_textblock_cursor_format_get(cur)), "ps")); | ||
1720 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<ps>")); | ||
1721 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1722 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1723 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1724 | fail_if(strcmp(evas_textblock_node_format_text_get( | ||
1725 | evas_textblock_cursor_format_get(cur)), "br")); | ||
1726 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<br>")); | ||
1727 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1728 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1729 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1730 | fail_if(strcmp(evas_textblock_node_format_text_get( | ||
1731 | evas_textblock_cursor_format_get(cur)), "tab")); | ||
1732 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<tab>")); | ||
1733 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1734 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1735 | fail_if(!evas_textblock_cursor_char_next(cur)); | ||
1736 | fail_if(strcmp(evas_textblock_node_format_text_get( | ||
1737 | evas_textblock_cursor_format_get(cur)), "+ item")); | ||
1738 | fail_if(strcmp(evas_textblock_cursor_content_get(cur), "<item>")); | ||
1739 | fail_if(!evas_textblock_cursor_format_is_visible_get(cur)); | ||
1740 | |||
1741 | END_TB_TEST(); | ||
1742 | } | ||
1743 | END_TEST | ||
1744 | |||
1745 | /* Different text styles, for example, shadow. */ | ||
1746 | START_TEST(evas_textblock_style) | ||
1747 | { | ||
1748 | Evas_Coord w, h, nw, nh; | ||
1749 | Evas_Coord l, r, t, b; | ||
1750 | START_TB_TEST(); | ||
1751 | Evas_Textblock_Style *newst; | ||
1752 | const char *buf = "Test<ps>Test2<ps>נסיון"; | ||
1753 | evas_object_textblock_text_markup_set(tb, buf); | ||
1754 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf)); | ||
1755 | |||
1756 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1757 | newst = evas_textblock_style_new(); | ||
1758 | fail_if(!newst); | ||
1759 | evas_textblock_style_set(newst, | ||
1760 | "DEFAULT='font=Sans font_size=20 color=#000 text_class=entry'" | ||
1761 | "br='\n'" | ||
1762 | "ps='ps'" | ||
1763 | "tab='\t'"); | ||
1764 | evas_object_textblock_style_set(tb, newst); | ||
1765 | evas_object_textblock_size_formatted_get(tb, &nw, &nh); | ||
1766 | fail_if((w >= nw) || (h >= nh)); | ||
1767 | |||
1768 | /* Style padding. */ | ||
1769 | evas_object_textblock_text_markup_set(tb, "Test"); | ||
1770 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1771 | fail_if((l != 0) || (r != 0) || (t != 0) || (b != 0)); | ||
1772 | |||
1773 | evas_object_textblock_text_markup_set(tb, "<style=shadow>Test</>"); | ||
1774 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1775 | fail_if((l != 0) || (r != 1) || (t != 0) || (b != 1)); | ||
1776 | |||
1777 | evas_object_textblock_text_markup_set(tb, "<style=outline>Test</>"); | ||
1778 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1779 | fail_if((l != 1) || (r != 1) || (t != 1) || (b != 1)); | ||
1780 | |||
1781 | evas_object_textblock_text_markup_set(tb, "<style=soft_outline>Test</>"); | ||
1782 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1783 | fail_if((l != 2) || (r != 2) || (t != 2) || (b != 2)); | ||
1784 | |||
1785 | evas_object_textblock_text_markup_set(tb, "<style=glow>Test</>"); | ||
1786 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1787 | fail_if((l != 2) || (r != 2) || (t != 2) || (b != 2)); | ||
1788 | |||
1789 | evas_object_textblock_text_markup_set(tb, "<style=outline_shadow>Test</>"); | ||
1790 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1791 | fail_if((l != 1) || (r != 2) || (t != 1) || (b != 2)); | ||
1792 | |||
1793 | evas_object_textblock_text_markup_set(tb, "<style=far_shadow>Test</>"); | ||
1794 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1795 | fail_if((l != 1) || (r != 2) || (t != 1) || (b != 2)); | ||
1796 | |||
1797 | evas_object_textblock_text_markup_set(tb, "<style=outline_soft_shadow>Test</>"); | ||
1798 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1799 | fail_if((l != 1) || (r != 3) || (t != 1) || (b != 3)); | ||
1800 | |||
1801 | evas_object_textblock_text_markup_set(tb, "<style=soft_shadow>Test</>"); | ||
1802 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1803 | fail_if((l != 1) || (r != 3) || (t != 1) || (b != 3)); | ||
1804 | |||
1805 | evas_object_textblock_text_markup_set(tb, "<style=far_soft_shadow>Test</>"); | ||
1806 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1807 | fail_if((l != 0) || (r != 4) || (t != 0) || (b != 4)); | ||
1808 | |||
1809 | /* Mixed style padding */ | ||
1810 | evas_object_textblock_text_markup_set(tb, | ||
1811 | "<style=far_shadow>Test</><style=far_soft_shadow>Test</>"); | ||
1812 | evas_object_textblock_style_insets_get(tb, &l, &r, &t, &b); | ||
1813 | fail_if((l != 1) || (r != 4) || (t != 1) || (b != 4)); | ||
1814 | |||
1815 | END_TB_TEST(); | ||
1816 | } | ||
1817 | END_TEST | ||
1818 | |||
1819 | /* Various setters and getters */ | ||
1820 | START_TEST(evas_textblock_set_get) | ||
1821 | { | ||
1822 | START_TB_TEST(); | ||
1823 | const char *buf = ""; | ||
1824 | evas_object_textblock_text_markup_set(tb, buf); | ||
1825 | fail_if(strcmp(evas_textblock_style_get(st), style_buf)); | ||
1826 | fail_if(evas_object_textblock_style_get(tb) != st); | ||
1827 | evas_object_textblock_replace_char_set(tb, "|"); | ||
1828 | fail_if(strcmp(evas_object_textblock_replace_char_get(tb), "|")); | ||
1829 | evas_object_textblock_replace_char_set(tb, "ש"); | ||
1830 | fail_if(strcmp(evas_object_textblock_replace_char_get(tb), "ש")); | ||
1831 | |||
1832 | evas_object_textblock_valign_set(tb, -1.0); | ||
1833 | fail_if(evas_object_textblock_valign_get(tb) != 0.0); | ||
1834 | evas_object_textblock_valign_set(tb, 0.0); | ||
1835 | fail_if(evas_object_textblock_valign_get(tb) != 0.0); | ||
1836 | evas_object_textblock_valign_set(tb, 0.432); | ||
1837 | fail_if(evas_object_textblock_valign_get(tb) != 0.432); | ||
1838 | evas_object_textblock_valign_set(tb, 1.0); | ||
1839 | fail_if(evas_object_textblock_valign_get(tb) != 1.0); | ||
1840 | evas_object_textblock_valign_set(tb, 1.5); | ||
1841 | fail_if(evas_object_textblock_valign_get(tb) != 1.0); | ||
1842 | |||
1843 | evas_object_textblock_bidi_delimiters_set(tb, ",.|"); | ||
1844 | fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",.|")); | ||
1845 | evas_object_textblock_bidi_delimiters_set(tb, ",|"); | ||
1846 | fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",|")); | ||
1847 | evas_object_textblock_bidi_delimiters_set(tb, NULL); | ||
1848 | fail_if(evas_object_textblock_bidi_delimiters_get(tb)); | ||
1849 | evas_object_textblock_bidi_delimiters_set(tb, ",|"); | ||
1850 | fail_if(strcmp(evas_object_textblock_bidi_delimiters_get(tb), ",|")); | ||
1851 | |||
1852 | /* Hinting */ | ||
1853 | evas_object_textblock_text_markup_set(tb, "This is<ps>a test<br>bla"); | ||
1854 | /* Force relayout */ | ||
1855 | evas_object_textblock_size_formatted_get(tb, NULL, NULL); | ||
1856 | evas_font_hinting_set(evas, EVAS_FONT_HINTING_NONE); | ||
1857 | evas_font_hinting_set(evas, EVAS_FONT_HINTING_AUTO); | ||
1858 | evas_font_hinting_set(evas, EVAS_FONT_HINTING_BYTECODE); | ||
1859 | END_TB_TEST(); | ||
1860 | } | ||
1861 | END_TEST | ||
1862 | |||
1863 | /* Aux evas stuff, such as scale. */ | ||
1864 | START_TEST(evas_textblock_evas) | ||
1865 | { | ||
1866 | Evas_Coord w, h, sw, sh; | ||
1867 | START_TB_TEST(); | ||
1868 | const char *buf = "Test"; | ||
1869 | evas_object_textblock_text_markup_set(tb, buf); | ||
1870 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1871 | evas_object_scale_set(tb, 3.0); | ||
1872 | evas_object_textblock_size_formatted_get(tb, &sw, &sh); | ||
1873 | fail_if((sw <= w) || (sh <= h)); | ||
1874 | |||
1875 | evas_object_scale_set(tb, 0.5); | ||
1876 | evas_object_textblock_size_formatted_get(tb, &sw, &sh); | ||
1877 | fail_if((sw >= w) || (sh >= h)); | ||
1878 | |||
1879 | END_TB_TEST(); | ||
1880 | } | ||
1881 | END_TEST | ||
1882 | |||
1883 | /* All the string escaping stuff */ | ||
1884 | START_TEST(evas_textblock_escaping) | ||
1885 | { | ||
1886 | int len; | ||
1887 | START_TB_TEST(); | ||
1888 | fail_if(strcmp(evas_textblock_escape_string_get("&"), "&")); | ||
1889 | fail_if(strcmp(evas_textblock_string_escape_get("&", &len), "&")); | ||
1890 | fail_if(len != 1); | ||
1891 | |||
1892 | fail_if(strcmp(evas_textblock_escape_string_get("·"), "\xc2\xb7")); | ||
1893 | fail_if(strcmp(evas_textblock_string_escape_get("\xc2\xb7", &len), | ||
1894 | "·")); | ||
1895 | fail_if(len != 2); | ||
1896 | |||
1897 | fail_if(strcmp(evas_textblock_escape_string_get("👙"), | ||
1898 | "\xF0\x9F\x91\x99")); | ||
1899 | fail_if(strcmp(evas_textblock_escape_string_get("👙"), | ||
1900 | "\xF0\x9F\x91\x99")); | ||
1901 | |||
1902 | fail_if(evas_textblock_escape_string_get("·aa")); | ||
1903 | const char *tmp = "·aa"; | ||
1904 | fail_if(strcmp(evas_textblock_escape_string_range_get(tmp, tmp + 8), | ||
1905 | "\xc2\xb7")); | ||
1906 | fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 9)); | ||
1907 | fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 7)); | ||
1908 | fail_if(evas_textblock_escape_string_range_get(tmp, tmp + 5)); | ||
1909 | |||
1910 | const char *buf = "This · is"; | ||
1911 | evas_object_textblock_text_markup_set(tb, buf); | ||
1912 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf)); | ||
1913 | |||
1914 | buf = "This is"; | ||
1915 | evas_object_textblock_text_markup_set(tb, buf); | ||
1916 | fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf)); | ||
1917 | |||
1918 | END_TB_TEST(); | ||
1919 | } | ||
1920 | END_TEST | ||
1921 | |||
1922 | START_TEST(evas_textblock_size) | ||
1923 | { | ||
1924 | START_TB_TEST(); | ||
1925 | Evas_Coord w, h, h2, nw, nh; | ||
1926 | const char *buf = "This is a <br> test.<br>גם בעברית"; | ||
1927 | /* When wrapping is off, native size should be the same as formatted | ||
1928 | * size */ | ||
1929 | |||
1930 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1931 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1932 | fail_if((w != nw) || (h != nh)); | ||
1933 | fail_if(w != 0); | ||
1934 | |||
1935 | evas_object_textblock_text_markup_set(tb, "a<br>a"); | ||
1936 | evas_object_textblock_size_formatted_get(tb, &w, &h2); | ||
1937 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1938 | fail_if((w != nw) || (h2 != nh)); | ||
1939 | |||
1940 | /* Two lines == double the height */ | ||
1941 | fail_if(h * 2 != h2); | ||
1942 | |||
1943 | evas_object_textblock_text_markup_set(tb, buf); | ||
1944 | |||
1945 | evas_object_textblock_size_formatted_get(tb, &w, &h); | ||
1946 | evas_object_textblock_size_native_get(tb, &nw, &nh); | ||
1947 | fail_if((w != nw) || (h != nh)); | ||
1948 | fail_if(w <= 0); | ||
1949 | |||
1950 | /* FIXME: There is a lot more to be done. */ | ||
1951 | END_TB_TEST(); | ||
1952 | } | ||
1953 | END_TEST | ||
1954 | |||
1955 | void evas_test_textblock(TCase *tc) | ||
1956 | { | ||
1957 | tcase_add_test(tc, evas_textblock_simple); | ||
1958 | tcase_add_test(tc, evas_textblock_cursor); | ||
1959 | tcase_add_test(tc, evas_textblock_size); | ||
1960 | tcase_add_test(tc, evas_textblock_editing); | ||
1961 | tcase_add_test(tc, evas_textblock_style); | ||
1962 | tcase_add_test(tc, evas_textblock_evas); | ||
1963 | tcase_add_test(tc, evas_textblock_text_getters); | ||
1964 | tcase_add_test(tc, evas_textblock_formats); | ||
1965 | tcase_add_test(tc, evas_textblock_format_removal); | ||
1966 | tcase_add_test(tc, evas_textblock_escaping); | ||
1967 | tcase_add_test(tc, evas_textblock_set_get); | ||
1968 | tcase_add_test(tc, evas_textblock_geometries); | ||
1969 | tcase_add_test(tc, evas_textblock_various); | ||
1970 | tcase_add_test(tc, evas_textblock_wrapping); | ||
1971 | tcase_add_test(tc, evas_textblock_items); | ||
1972 | } | ||
1973 | |||