aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/edje/edje_test_text.c
blob: 7d878a6153a4be97a6aebc013dc8f47647a5b24b (plain) (blame)
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
#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 <Eina.h>
#include <Edje.h>

#include "edje_suite.h"
#include "edje_tests_helpers.h"

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

static const char *
test_layout_get(const char *name)
{
   static char filename[PATH_MAX];

   snprintf(filename, PATH_MAX, TESTS_BUILD_DIR"/data/%s", name);

   return filename;
}

START_TEST(edje_test_text_ellipsis)
{
   Eo *evas = EDJE_TEST_INIT_EVAS();
   Eo *layout;

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(160, 40)));
   efl_file_set(layout, test_layout_get("test_text.edj"), "test");
   fail_if(efl_file_load_error_get(layout));

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

   EDJE_TEST_FREE_EVAS();
}
END_TEST

START_TEST(edje_test_text_wrap)
{
   Eo *evas = EDJE_TEST_INIT_EVAS();
   Eo *layout;

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(160, 40)));
   efl_file_set(layout, test_layout_get("test_text.edj"), "test");
   fail_if(efl_file_load_error_get(layout));

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

   EDJE_TEST_FREE_EVAS();
}
END_TEST

START_TEST(edje_test_text_font)
{
   Eo *evas = EDJE_TEST_INIT_EVAS();
   Eo *layout;

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(160, 40)));
   efl_file_set(layout, test_layout_get("test_text.edj"), "test");
   fail_if(efl_file_load_error_get(layout));

   efl_text_font_set(efl_part(layout, "text"), "Sans", 14);

   EDJE_TEST_FREE_EVAS();
}
END_TEST

START_TEST(edje_test_text_color)
{
   Eo *evas = EDJE_TEST_INIT_EVAS();
   Eo *layout;

   layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
         efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(160, 40)));
   efl_file_set(layout, test_layout_get("test_text.edj"), "test");
   fail_if(efl_file_load_error_get(layout));

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

   EDJE_TEST_FREE_EVAS();
}
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_normal_color_set(efl_part(layout, "text"),
                   255, 255, 255, 255);
             efl_text_backing_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_glow2_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_underline2_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_normal_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_backing_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_glow2_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_underline2_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_set(efl_part(layout, "text"), "Sans", 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));

        efl_text_font_get(efl_part(layout, "text"), &font, &size);
        ck_assert_str_eq(font, "Sans");
        ck_assert_int_eq(size, 12);
     }
}

START_TEST(edje_test_text_part)
{
   Eo *evas = EDJE_TEST_INIT_EVAS();
   Eo *layout;

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

   efl_file_set(layout, test_layout_get("test_text.edj"), "test");
   fail_if(efl_file_load_error_get(layout));
   _basic_check(layout, EINA_TRUE);

   // Load again and check persistance
   efl_file_set(layout, test_layout_get("test_text.edj"), "test2");
   fail_if(efl_file_load_error_get(layout));
   _basic_check(layout, EINA_FALSE);

   EDJE_TEST_FREE_EVAS();
}
END_TEST
void edje_test_text(TCase *tc)
{
   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);
}