summaryrefslogtreecommitdiff
path: root/src/tests/edje/edje_test_text.c
blob: 20162c5c5c02a604609975186fa3a4c91c39d579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <unistd.h>
#include <stdio.h>

#define EFL_GFX_FILTER_BETA
#define EFL_CANVAS_LAYOUT_BETA

#include "edje_suite.h"

#define EVAS_DATA_DIR TESTS_SRC_DIR "/../../lib/evas"

EFL_START_TEST(edje_test_text_cursor)
{
   Evas *evas;
   Evas_Object *obj;
   const char *buf = "ABC<br/>DEF";
   const char *txt;
   int i, old_pos, new_pos;

   evas = _setup_evas();

   obj = edje_object_add(evas);
   fail_unless(edje_object_file_set(obj, test_layout_get("test_text_cursor.edj"), "test_text_cursor"));
   edje_object_part_text_set(obj, "text", buf);
   txt = edje_object_part_text_get(obj, "text");
   fail_if(!txt || strcmp(txt, buf));

   edje_object_part_text_cursor_pos_set(obj, "text", EDJE_CURSOR_MAIN, 0);
   ck_assert_int_eq(edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN), 0);
   edje_object_part_text_cursor_pos_set(obj, "text", EDJE_CURSOR_MAIN, 1);
   ck_assert_int_eq(edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN), 1);

   /* Move cursor to the 0 pos from 1 pos */
   old_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert(edje_object_part_text_cursor_prev(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_ne(old_pos, new_pos);

   /* Move cursor to the -1 pos from 0 pos. It has to fail. */
   old_pos = new_pos;
   ck_assert(!edje_object_part_text_cursor_prev(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_eq(old_pos, new_pos);

   /* Jump to 2nd line from 1st line.
    * It has to return EINA_TRUE which means success. */
   old_pos = new_pos;
   ck_assert(edje_object_part_text_cursor_down(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_ne(old_pos, new_pos);

   /* Try to jump to 3rd line from 2nd line. But, 3rd line does not exist.
    * So, it has to return EINA_FALSE which means failure. */
   old_pos = new_pos;
   ck_assert(!edje_object_part_text_cursor_down(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_eq(old_pos, new_pos);

   /* Move cursor to the end of 2nd line. */
   for (i = 0; i < 3; i++)
     {
        old_pos = new_pos;
        ck_assert(edje_object_part_text_cursor_next(obj, "text", EDJE_CURSOR_MAIN));
        new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
        ck_assert_int_ne(old_pos, new_pos);
     }

   /* Move cursor to the next of the end of 2nd line which does not exist. */
   old_pos = new_pos;
   ck_assert(!edje_object_part_text_cursor_next(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_eq(old_pos, new_pos);

   /* Jump to 1st line from 2nd line.
    * It has to return EINA_TRUE which means success. */
   old_pos = new_pos;
   ck_assert(edje_object_part_text_cursor_up(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_ne(old_pos, new_pos);

   /* Try to jump to the above of 1st line from 1st line. But, there is no such line.
    * So, it has to return EINA_FALSE which means failure. */
   old_pos = new_pos;
   ck_assert(!edje_object_part_text_cursor_up(obj, "text", EDJE_CURSOR_MAIN));
   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", EDJE_CURSOR_MAIN);
   ck_assert_int_eq(old_pos, new_pos);

}
EFL_END_TEST


EFL_START_TEST(edje_test_textblock)
{
   Evas *evas;
   Evas_Object *obj;
   const char *buf = "Hello";
   const char *txt;

   evas = _setup_evas();

   obj = edje_object_add(evas);
   ck_assert(edje_object_file_set(obj, test_layout_get("test_textblock.edj"), "test_textblock"));
   txt = edje_object_part_text_get(obj, "text");
   ck_assert_ptr_ne(txt, NULL);
   ck_assert_int_eq(strcmp(txt, "Bye"), 0);
   edje_object_part_text_set(obj, "text", buf);
   txt = edje_object_part_text_get(obj, "text");
   ck_assert_ptr_ne(txt, NULL);
   ck_assert_int_eq(strcmp(txt, buf), 0);

   Evas_Object *obj2 = edje_object_add(evas);
   ck_assert(edje_object_file_set(obj2, test_layout_get("test_textblock.edj"), "test_tc_textblock"));
   Evas_Object *tb = (Evas_Object*)edje_object_part_object_get(obj2, "tb");
   ck_assert_ptr_ne(tb, NULL);
   int w = 0, h = 0;
   evas_object_textblock_size_formatted_get(tb, &w, &h);
   Evas_Textblock_Style *st = evas_object_textblock_style_get(tb);
   txt = evas_textblock_style_get(st);
   ck_assert_str_eq(txt, "DEFAULT='color=#ff0 font_size=18.0 font=Serif'");
   ck_assert_int_ne(w, 0);
   ck_assert_int_ne(h, 0);

   edje_object_text_class_set(obj2, "tc1", "Sans", 15);
   edje_object_calc_force(obj2);
   int w2 = 0, h2 = 0;
   evas_object_textblock_size_formatted_get(tb, &w2, &h2);
   ck_assert_int_ne(w2, 0);
   ck_assert_int_ne(h2, 0);
   ck_assert_int_ne(w, w2);
   ck_assert_int_ne(h, h2);

   ck_assert(edje_object_file_set(obj2, test_layout_get("test_textblock.edj"), "test_tc_textblock2"));
   tb = (Evas_Object*)edje_object_part_object_get(obj2, "tb2");
   ck_assert_ptr_ne(tb, NULL);
   st = evas_object_textblock_style_get(tb);
   txt = evas_textblock_style_get(st);
   ck_assert_str_eq(txt, "DEFAULT='color=#0ff'");
   evas_object_textblock_size_formatted_get(tb, &w, &h);
   ck_assert_int_eq(w, 0);
   ck_assert_int_eq(h, 0);

   edje_object_text_class_set(obj2, "tc2", "Sans", 15);
   edje_object_calc_force(obj2);
   evas_object_textblock_size_formatted_get(tb, &w, &h);
   ck_assert_int_ne(w, 0);
   ck_assert_int_ne(h, 0);
   st = evas_object_textblock_style_get(tb);
   txt = evas_textblock_style_get(st);
   ck_assert_str_eq(txt, "DEFAULT='color=#0ff font_size=15.0 font=Sans'");
}
EFL_END_TEST

EFL_START_TEST(edje_test_text_ellipsis)
{
   Eo *evas;
   Eo *layout;

   evas = _setup_evas();

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(160, 40)));
   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test");
   ck_assert(!efl_file_load(layout));

   efl_text_ellipsis_set(efl_part(layout, "text"), 1.0);

}
EFL_END_TEST

EFL_START_TEST(edje_test_text_wrap)
{
   Eo *evas;
   Eo *layout;

   evas = _setup_evas();

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(160, 40)));
   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test");
   ck_assert(!efl_file_load(layout));

   efl_text_wrap_set(efl_part(layout, "text"), EFL_TEXT_FORMAT_WRAP_WORD);

}
EFL_END_TEST

EFL_START_TEST(edje_test_text_font)
{
   Eo *evas;
   Eo *layout;

   evas = _setup_evas();

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(160, 40)));
   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test");
   ck_assert(!efl_file_load(layout));

   efl_text_font_family_set(efl_part(layout, "text"), "Sans");
   efl_text_font_size_set(efl_part(layout, "text"), 14);

}
EFL_END_TEST

EFL_START_TEST(edje_test_text_color)
{
   Eo *evas;
   Eo *layout;

   evas = _setup_evas();

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(160, 40)));
   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test");
   ck_assert(!efl_file_load(layout));

   efl_text_color_set(efl_part(layout, "text"), 255, 255, 255, 255);

}
EFL_END_TEST

static void
_basic_check(Eo *layout, Eina_Bool set)
{
   // Colors
     {
        unsigned char r, g, b, a;

        // Just normal_color is enough
        if (set)
          {
             efl_text_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_background_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_glow_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_secondary_glow_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_outline_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_shadow_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_strikethrough_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_underline_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_secondary_underline_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_underline_dashed_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
          }

        efl_text_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_background_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_glow_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_secondary_glow_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_outline_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_shadow_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_strikethrough_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_underline_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_secondary_underline_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);

        efl_text_underline_dashed_color_get(efl_part(layout, "text"), &r, &g, &b, &a);
        ck_assert_int_eq(r, 255);
        ck_assert_int_eq(g, 255);
        ck_assert_int_eq(b, 255);
        ck_assert_int_eq(a, 255);
     }

   // Rest of api
     {
        Efl_Text_Format_Wrap wrap;
        double ellipsis;
        const char *font;
        Efl_Font_Size size;

        if (set)
          {
             efl_text_wrap_set(efl_part(layout, "text"), EFL_TEXT_FORMAT_WRAP_WORD);
             efl_text_ellipsis_set(efl_part(layout, "text"), 1.0);
             efl_text_font_family_set(efl_part(layout, "text"), "Sans");
             efl_text_font_size_set(efl_part(layout, "text"), 12);
          }

        wrap = efl_text_wrap_get(efl_part(layout, "text"));
        ck_assert_int_eq(wrap, EFL_TEXT_FORMAT_WRAP_WORD);

        ellipsis = efl_text_ellipsis_get(efl_part(layout, "text"));
        ck_assert(EINA_DBL_EQ(ellipsis, 1.0));

        font = efl_text_font_family_get(efl_part(layout, "text"));
        size = efl_text_font_size_get(efl_part(layout, "text"));
        ck_assert_str_eq(font, "Sans");
        ck_assert_int_eq(size, 12);
     }
}

EFL_START_TEST(edje_test_text_part)
{
   Eo *evas;
   Eo *layout;

   evas = _setup_evas();

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(160, 40)));

   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test");
   ck_assert(!efl_file_load(layout));
   _basic_check(layout, EINA_TRUE);

   // Load again and check persistance
   ck_assert(!efl_file_set(layout, test_layout_get("test_text.edj")));
   efl_file_key_set(layout, "test2");
   ck_assert(!efl_file_load(layout));
   _basic_check(layout, EINA_FALSE);

}
EFL_END_TEST

void edje_test_text(TCase *tc)
{
   tcase_add_test(tc, edje_test_text_cursor);
   tcase_add_test(tc, edje_test_textblock);
   tcase_add_test(tc, edje_test_text_ellipsis);
   tcase_add_test(tc, edje_test_text_wrap);
   tcase_add_test(tc, edje_test_text_font);
   tcase_add_test(tc, edje_test_text_color);
   tcase_add_test(tc, edje_test_text_part);
}