Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_entry_tc2.c
1 /*
2  * Tested interface: AtkText
3  *
4  * Tested AtkObject: EailEntry
5  *
6  * Description: Test AtkText interface
7  *
8  * Test input: accessible object representing EailEntry
9  *
10  * Expected test result: test should return 0 (success)
11  */
12
13 #include <Elementary.h>
14 #include <atk/atk.h>
15
16 #include "eail_test_utils.h"
17
18 #define TEXT_LEN 475
19
20 INIT_TEST("EailEntry")
21
22 static void
23 _do_test(AtkObject *obj)
24 {
25    gchar *text;
26    int start_offset, end_offset;
27    AtkAttributeSet *elem = NULL, *at_set = NULL;
28    AtkAttribute *attr = NULL;
29    gboolean wrap_exist = FALSE, editable_exist = FALSE;
30
31    g_assert(ATK_IS_TEXT(obj));
32
33    text = atk_text_get_text(ATK_TEXT(obj), 6, 11);
34    g_assert_cmpstr(text, ==, "ipsum");
35    g_free(text);
36
37    g_assert(atk_text_get_character_at_offset(ATK_TEXT(obj), 12) == 'd');
38    g_assert(atk_text_get_character_count(ATK_TEXT(obj)) == TEXT_LEN);
39    g_assert(atk_text_set_caret_offset(ATK_TEXT(obj), 13));
40    g_assert(atk_text_get_caret_offset(ATK_TEXT(obj)) == 13);
41
42    start_offset = 0;
43    end_offset = 5;
44    g_assert(atk_text_get_n_selections(ATK_TEXT(obj)) == 0);
45    g_assert(atk_text_set_selection(ATK_TEXT(obj), 0, start_offset, end_offset));
46    text = atk_text_get_selection(ATK_TEXT(obj), 0, &start_offset,  &end_offset);
47    g_assert_cmpstr(text, ==, "Lorem");
48    g_assert(start_offset == 0);
49    g_assert(end_offset == 5);
50
51    g_assert(atk_text_get_n_selections(ATK_TEXT(obj)) == 1);
52    g_assert(atk_text_remove_selection(ATK_TEXT(obj), 0) == TRUE);
53    g_assert(atk_text_get_n_selections(ATK_TEXT(obj)) == 0);
54    g_assert(atk_text_add_selection(ATK_TEXT(obj), start_offset, end_offset));
55    g_assert(atk_text_get_n_selections(ATK_TEXT(obj)) == 1);
56    g_free(text);
57
58    at_set = atk_text_get_run_attributes
59        (ATK_TEXT(obj), 0, &start_offset, &end_offset);
60    g_assert(at_set);
61
62    for (elem = at_set; elem; elem = elem->next)
63      {
64         attr = (AtkAttribute *)elem->data;
65         if (0 == g_strcmp0(attr->name, atk_text_attribute_get_name
66                            (ATK_TEXT_ATTR_WRAP_MODE)))
67           wrap_exist = TRUE;
68         else if (0 == g_strcmp0(attr->name, atk_text_attribute_get_name
69                                 (ATK_TEXT_ATTR_EDITABLE)))
70           editable_exist = TRUE;
71      }
72
73    g_assert(0 == start_offset);
74    g_assert(atk_text_get_character_count(ATK_TEXT(obj)) == end_offset);
75
76    g_assert(wrap_exist);
77    g_assert(editable_exist);
78
79    /* out of bounds offset in run attributes test*/
80    at_set = atk_text_get_run_attributes
81        (ATK_TEXT(obj), atk_text_get_character_count
82         (ATK_TEXT(obj)), &start_offset, &end_offset);
83    g_assert(NULL == at_set);
84    g_assert(-1 == start_offset);
85    g_assert(-1 == end_offset);
86
87    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 6,
88                                       ATK_TEXT_BOUNDARY_CHAR,
89                                       &start_offset,
90                                       &end_offset);
91    g_assert_cmpstr(text, ==, "i");
92    g_free(text);
93    g_assert(start_offset == 6);
94    g_assert(end_offset == 7);
95
96    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 2,
97                                       ATK_TEXT_BOUNDARY_WORD_START,
98                                       &start_offset,
99                                       &end_offset);
100    g_assert_cmpstr(text, ==, "Lorem ");
101    g_free(text);
102
103    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 11,
104                                       ATK_TEXT_BOUNDARY_WORD_START,
105                                       &start_offset,
106                                       &end_offset);
107    g_assert_cmpstr(text, ==, "ipsum ");
108    g_free(text);
109
110    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 11,
111                                       ATK_TEXT_BOUNDARY_WORD_END,
112                                       &start_offset,
113                                       &end_offset);
114    g_assert_cmpstr(text, ==, " dolor");
115    g_free(text);
116
117    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 10,
118                                       ATK_TEXT_BOUNDARY_WORD_END,
119                                       &start_offset,
120                                       &end_offset);
121    g_assert_cmpstr(text, ==, " ipsum");
122    g_free(text);
123
124    text = atk_text_get_text_after_offset(ATK_TEXT(obj), 6,
125                                          ATK_TEXT_BOUNDARY_CHAR,
126                                          &start_offset,
127                                          &end_offset);
128    g_assert_cmpstr(text, ==, "p");
129    g_free(text);
130    g_assert(start_offset == 7);
131    g_assert(end_offset == 8);
132
133    text = atk_text_get_text_after_offset(ATK_TEXT(obj), 12,
134                                          ATK_TEXT_BOUNDARY_WORD_START,
135                                          &start_offset,
136                                          &end_offset);
137    g_assert_cmpstr(text, ==, "sit ");
138    g_free(text);
139
140    text = atk_text_get_text_after_offset(ATK_TEXT(obj), 10,
141                                          ATK_TEXT_BOUNDARY_WORD_END,
142                                          &start_offset,
143                                          &end_offset);
144    g_assert_cmpstr(text, ==, " dolor");
145    g_free(text);
146
147    text = atk_text_get_text_before_offset(ATK_TEXT(obj), 5,
148                                          ATK_TEXT_BOUNDARY_CHAR,
149                                          &start_offset,
150                                          &end_offset);
151    g_assert_cmpstr(text, ==, "m");
152    g_free(text);
153    g_assert(start_offset == 4);
154    g_assert(end_offset == 5);
155
156    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 12,
157                                          ATK_TEXT_BOUNDARY_LINE_START,
158                                          &start_offset,
159                                          &end_offset);
160    g_assert_cmpstr(text, ==,
161                    "Lorem ipsum dolor sit amet, consectetur adipisicing elit,\n");
162    g_free(text);
163
164    text = atk_text_get_text_at_offset(ATK_TEXT(obj), 129,
165                                          ATK_TEXT_BOUNDARY_LINE_END,
166                                          &start_offset,
167                                          &end_offset);
168    g_assert_cmpstr(
169        text, ==, "Ut enim ad minim veniam, quis nostrud exercitation ullamc");
170    g_free(text);
171
172    text = atk_text_get_text_after_offset(ATK_TEXT(obj), 2,
173                                       ATK_TEXT_BOUNDARY_LINE_START,
174                                       &start_offset,
175                                       &end_offset);
176    g_assert_cmpstr(
177        text, ==,
178        "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n");
179    g_free(text);
180
181    text = atk_text_get_text_after_offset(ATK_TEXT(obj), 70,
182                                          ATK_TEXT_BOUNDARY_LINE_END,
183                                          &start_offset,
184                                          &end_offset);
185    g_assert_cmpstr(
186        text, ==,
187        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n");
188    g_free(text);
189
190    eailu_test_code_called = 1;
191 }
192
193 static void
194 _init_entry(Evas_Object *win)
195 {
196    Evas_Object *box, *tb, *bg, *en;
197    const char *text1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit,<br>"
198        "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>"
199        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris<br>"
200        "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in<br>"
201        "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla<br>"
202        "pariatur. Excepteur sint occaecat cupidatat non proident, sunt<br>"
203        "in culpa qui officia deserunt mollit anim id est laborum.<br>";
204
205    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
206    elm_win_autodel_set(win, EINA_TRUE);
207
208    bg = elm_bg_add(win);
209    elm_win_resize_object_add(win, bg);
210    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211    evas_object_show(bg);
212
213    box = elm_box_add(win);
214    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215    elm_win_resize_object_add(win, box);
216    evas_object_show(box);
217
218    tb = elm_box_add(win);
219    elm_box_horizontal_set(tb, EINA_TRUE);
220    evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
221    evas_object_size_hint_weight_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
222    elm_box_pack_end(box, tb);
223    evas_object_show(tb);
224
225    en = elm_entry_add(win);
226    elm_entry_autosave_set(en, EINA_FALSE);
227    elm_entry_line_wrap_set(en, ELM_WRAP_NONE);
228    elm_entry_entry_set(en, text1);
229    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
231    elm_box_pack_end(box, en);
232    evas_object_show(en);
233
234    evas_object_resize(win, 200, 200);
235 }
236
237 EAPI_MAIN int
238 elm_main(int argc, char *argv[])
239 {
240    Evas_Object *win;
241
242    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
243    _init_entry(win);
244    evas_object_show(win);
245    elm_run();
246    elm_shutdown();
247
248    return 0;
249 }
250 ELM_MAIN()