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