summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2019-12-11 08:12:29 +0000
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-12-11 11:45:52 +0100
commit29438a5454f5998e76eeaa61474391b8c0f6dfb5 (patch)
treef3750ab241d3336a696125a0a9cd00ef548b5a9c
parent8331ea048cfafd7afc007456d7b38209e862c3b0 (diff)
efl_ui_text: unit test
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D10776
-rw-r--r--src/tests/elementary/efl_ui_suite.c1
-rw-r--r--src/tests/elementary/efl_ui_suite.h1
-rw-r--r--src/tests/elementary/efl_ui_test_text.c141
-rw-r--r--src/tests/elementary/meson.build1
-rw-r--r--src/tests/elementary/spec/efl_test_basics.c1
5 files changed, 145 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index 13d406d..9234d68 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -41,6 +41,7 @@ static const Efl_Test_Case etc[] = {
41 { "efl_ui_select_model", efl_ui_test_select_model }, 41 { "efl_ui_select_model", efl_ui_test_select_model },
42 { "efl_ui_view_model", efl_ui_test_view_model }, 42 { "efl_ui_view_model", efl_ui_test_view_model },
43 { "efl_ui_group_item", efl_ui_test_group_item }, 43 { "efl_ui_group_item", efl_ui_test_group_item },
44 { "efl_ui_text", efl_ui_test_text},
44 { NULL, NULL } 45 { NULL, NULL }
45}; 46};
46 47
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 1456cea..cb83a00 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -52,6 +52,7 @@ void efl_ui_test_scroller(TCase *tc);
52void efl_ui_test_select_model(TCase *tc); 52void efl_ui_test_select_model(TCase *tc);
53void efl_ui_test_view_model(TCase *tc); 53void efl_ui_test_view_model(TCase *tc);
54void efl_ui_test_group_item(TCase *tc); 54void efl_ui_test_group_item(TCase *tc);
55void efl_ui_test_text(TCase *tc);
55 56
56void loop_timer_interval_set(Eo *obj, double in); 57void loop_timer_interval_set(Eo *obj, double in);
57 58
diff --git a/src/tests/elementary/efl_ui_test_text.c b/src/tests/elementary/efl_ui_test_text.c
new file mode 100644
index 0000000..b0eecd1
--- /dev/null
+++ b/src/tests/elementary/efl_ui_test_text.c
@@ -0,0 +1,141 @@
1#define EFL_NOLEGACY_API_SUPPORT
2#ifdef HAVE_CONFIG_H
3# include "elementary_config.h"
4#endif
5#define EFL_LAYOUT_CALC_PROTECTED
6#include <Efl_Ui.h>
7#include "efl_ui_suite.h"
8
9static void
10increment_int_changed(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
11{
12 int *value = data;
13 (*value)++;
14}
15
16EFL_START_TEST(text_cnp)
17{
18 Eo *txt;
19 Eo *win = win_add();
20
21 int i_copy = 0, i_paste = 0, i_cut = 0;
22
23 txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
24 efl_event_callback_add(efl_added, EFL_UI_TEXTBOX_EVENT_SELECTION_COPY, increment_int_changed, &i_copy),
25 efl_event_callback_add(efl_added, EFL_UI_TEXTBOX_EVENT_SELECTION_PASTE, increment_int_changed, &i_paste),
26 efl_event_callback_add(efl_added, EFL_UI_TEXTBOX_EVENT_SELECTION_CUT, increment_int_changed, &i_cut)
27 );
28
29 efl_text_set(txt, "Hello");
30 efl_text_interactive_all_select(txt);
31 efl_ui_textbox_selection_copy(txt);
32 efl_text_interactive_all_select(txt);
33 efl_ui_textbox_selection_cut(txt);
34 efl_ui_textbox_selection_paste(txt);
35 efl_ui_textbox_selection_paste(txt);
36 ecore_main_loop_iterate();
37 ck_assert_int_eq(i_copy, 1);
38 ck_assert_int_eq(i_cut, 1);
39 ck_assert_int_eq(i_paste, 2);
40 //FIXME
41 //fail_if(strcmp(efl_text_get(txt),"HelloHello"));
42 efl_del(txt);
43}
44EFL_END_TEST
45
46EFL_START_TEST(text_all_select_all_unselect)
47{
48 Eo *txt;
49 Eo *win = win_add();
50
51 int i_have_selection = 0, i_selection = 0;
52
53 txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
54 efl_event_callback_add(efl_added, EFL_TEXT_INTERACTIVE_EVENT_HAVE_SELECTION_CHANGED,
55 increment_int_changed, &i_have_selection),
56 efl_event_callback_add(efl_added, EFL_TEXT_INTERACTIVE_EVENT_SELECTION_CHANGED,
57 increment_int_changed, &i_selection)
58 );
59
60 efl_text_set(txt, "Hello");
61 efl_text_interactive_all_select(txt);
62 Efl_Text_Cursor *c1=NULL, *c2 =NULL;
63 efl_text_interactive_selection_cursors_get(txt, &c1, &c2);
64 ck_assert_ptr_ne(c1, NULL);
65 ck_assert_ptr_ne(c2, NULL);
66 fail_if(!efl_text_interactive_have_selection_get(txt));
67 ck_assert_int_eq(efl_text_cursor_position_get(c1), 0);
68 ck_assert_int_eq(efl_text_cursor_position_get(c2), 5);
69 efl_text_interactive_all_unselect(txt);
70 fail_if(efl_text_interactive_have_selection_get(txt));
71 ecore_main_loop_iterate();
72 ck_assert_int_eq(i_have_selection, 2);
73 ck_assert_int_eq(i_selection, 1);
74 efl_del(txt);
75 efl_del(win);
76}
77EFL_END_TEST
78
79EFL_START_TEST(text_selection)
80{
81 Eo *txt;
82 Eo *win = win_add();
83
84 txt = efl_add(EFL_UI_TEXTBOX_CLASS, win);
85 efl_gfx_entity_size_set(txt, EINA_SIZE2D(300, 300));
86 efl_text_set(txt, "Hello");
87 get_me_to_those_events(txt);
88 drag_object(txt, 2, 2, 295, 295, EINA_TRUE);
89 ecore_main_loop_iterate();
90 Efl_Text_Cursor *c1=NULL, *c2 =NULL;
91 efl_text_interactive_selection_cursors_get(txt, &c1, &c2);
92 ck_assert_ptr_ne(c1, NULL);
93 ck_assert_ptr_ne(c2, NULL);
94 fail_if(!efl_text_interactive_have_selection_get(txt));
95 ck_assert_int_eq(efl_text_cursor_position_get(c1), 0);
96 ck_assert_int_eq(efl_text_cursor_position_get(c2), 5);
97 efl_text_interactive_all_unselect(txt);
98 fail_if(efl_text_interactive_have_selection_get(txt));
99 efl_text_interactive_selection_allowed_set(txt, EINA_FALSE);
100 drag_object(txt, 2, 2, 295, 295, EINA_TRUE);
101 ecore_main_loop_iterate();
102 fail_if(efl_text_interactive_have_selection_get(txt));
103 efl_del(txt);
104}
105EFL_END_TEST
106
107static void
108user_changed(void *data, const Efl_Event *ev)
109{
110 Efl_Text_Change_Info *info = (Efl_Text_Change_Info *)ev->info;
111 Efl_Text_Change_Info *stored = (Efl_Text_Change_Info *)data;
112 *stored = *info;
113}
114
115EFL_START_TEST(text_user_change)
116{
117 Eo *txt;
118 Eo *win = win_add();
119 Efl_Text_Change_Info info = {0};
120 txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
121 efl_event_callback_add(efl_added, EFL_TEXT_INTERACTIVE_EVENT_CHANGED_USER, user_changed, &info)
122 );
123
124 efl_text_set(txt, "Hello");
125 efl_gfx_entity_size_set(txt, EINA_SIZE2D(300, 300));
126 efl_text_interactive_all_select(txt);
127 efl_ui_textbox_selection_cut(txt);
128 ck_assert_int_eq(info.position, 0);
129 ck_assert_int_eq(info.length, 5);
130 efl_del(txt);
131 efl_del(win);
132}
133EFL_END_TEST
134
135void efl_ui_test_text(TCase *tc)
136{
137 tcase_add_test(tc, text_cnp);
138 tcase_add_test(tc, text_all_select_all_unselect);
139 tcase_add_test(tc, text_selection);
140 tcase_add_test(tc, text_user_change);
141}
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index c52a18c..7c7c62f 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -158,6 +158,7 @@ efl_ui_suite_src = [
158 'efl_ui_test_select_model.c', 158 'efl_ui_test_select_model.c',
159 'efl_ui_test_view_model.c', 159 'efl_ui_test_view_model.c',
160 'efl_ui_test_group_item.c', 160 'efl_ui_test_group_item.c',
161 'efl_ui_test_text.c',
161] 162]
162 163
163efl_ui_suite = executable('efl_ui_suite', 164efl_ui_suite = executable('efl_ui_suite',
diff --git a/src/tests/elementary/spec/efl_test_basics.c b/src/tests/elementary/spec/efl_test_basics.c
index c40ffcd..0985adb 100644
--- a/src/tests/elementary/spec/efl_test_basics.c
+++ b/src/tests/elementary/spec/efl_test_basics.c
@@ -17,6 +17,7 @@
17 "Efl.Ui.List_View", 17 "Efl.Ui.List_View",
18 "Efl.Ui.Tab_Bar", 18 "Efl.Ui.Tab_Bar",
19 "Efl.Ui.Tags", 19 "Efl.Ui.Tags",
20 "Efl.Ui.Textbox",
20 "Efl.Ui.Panel", 21 "Efl.Ui.Panel",
21 "Efl.Ui.Scroller", 22 "Efl.Ui.Scroller",
22 "Efl.Ui.Slider", 23 "Efl.Ui.Slider",