summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-01-11 17:59:31 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-01-30 12:06:20 -0800
commitd1b1dce5ffba429c05f6aacfb9972085862710e7 (patch)
tree9a6f3c5731e5e482d8764209ff4b6e230324d0cd
parentf30c7c6a1ea5f9d6ff369edaebd3cb9cb8b5caac (diff)
elementary: add a test for Efl.Ui.Model_Homogeneous.
Reviewed-by: SangHyeon Jade Lee <sh10233.lee@samsung.com> Differential Revision: https://phab.enlightenment.org/D7663
-rw-r--r--src/Makefile_Elementary.am5
-rw-r--r--src/tests/elementary/efl_ui_model.c184
-rw-r--r--src/tests/elementary/efl_ui_suite.c6
-rw-r--r--src/tests/elementary/efl_ui_suite.h7
-rw-r--r--src/tests/elementary/meson.build3
5 files changed, 199 insertions, 6 deletions
diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am
index ed2a629d14..6f38e0b801 100644
--- a/src/Makefile_Elementary.am
+++ b/src/Makefile_Elementary.am
@@ -1612,6 +1612,7 @@ tests_elementary_elm_suite_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@
1612 1612
1613tests_elementary_efl_ui_suite_SOURCES = \ 1613tests_elementary_efl_ui_suite_SOURCES = \
1614 tests/elementary/suite_helpers.c \ 1614 tests/elementary/suite_helpers.c \
1615 tests/elementary/suite_helpers.h \
1615 tests/elementary/efl_ui_suite.c \ 1616 tests/elementary/efl_ui_suite.c \
1616 tests/elementary/elm_test_init.c \ 1617 tests/elementary/elm_test_init.c \
1617 tests/elementary/efl_ui_test_atspi.c \ 1618 tests/elementary/efl_ui_test_atspi.c \
@@ -1622,7 +1623,9 @@ tests_elementary_efl_ui_suite_SOURCES = \
1622 tests/elementary/efl_ui_test_grid.c \ 1623 tests/elementary/efl_ui_test_grid.c \
1623 tests/elementary/efl_ui_test_image.c \ 1624 tests/elementary/efl_ui_test_image.c \
1624 tests/elementary/efl_ui_test_image_zoomable.c \ 1625 tests/elementary/efl_ui_test_image_zoomable.c \
1625 tests/elementary/efl_ui_test_layout.c 1626 tests/elementary/efl_ui_test_layout.c \
1627 tests/elementary/efl_ui_suite.h \
1628 tests/elementary/efl_ui_model.c
1626 1629
1627tests_elementary_efl_ui_suite_CPPFLAGS = \ 1630tests_elementary_efl_ui_suite_CPPFLAGS = \
1628-DELM_INTERNAL_API_ARGESFSDFEFC=1 \ 1631-DELM_INTERNAL_API_ARGESFSDFEFC=1 \
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
new file mode 100644
index 0000000000..b3c764014a
--- /dev/null
+++ b/src/tests/elementary/efl_ui_model.c
@@ -0,0 +1,184 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include "efl_ui_suite.h"
6#include "efl_ui_model_homogeneous.eo.h"
7
8static const int child_number = 3;
9static const int base_ints[] = { 41, 42, 43 };
10
11static Efl_Model *
12_generate_base_model(void)
13{
14 Efl_Model_Item *base_model, *child;
15 Eina_Value v;
16 int i;
17
18 eina_value_setup(&v, EINA_VALUE_TYPE_INT);
19
20 base_model = efl_add_ref(EFL_MODEL_ITEM_CLASS, efl_main_loop_get());
21 ck_assert(!!base_model);
22 for (i = 0; i < child_number; ++i)
23 {
24 child = efl_model_child_add(base_model);
25 ck_assert(!!child);
26 ck_assert(eina_value_set(&v, base_ints[i]));
27 efl_model_property_set(child, "test_p_int", &v);
28 }
29 eina_value_flush(&v);
30
31 return base_model;
32}
33
34static Eina_Error
35_property_error_expected(Efl_Model *model, const char *property)
36{
37 Eina_Value *v;
38 Eina_Error err = 0;
39
40 v = efl_model_property_get(model, property);
41 ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_ERROR);
42 ck_assert(eina_value_error_get(v, &err));
43 eina_value_free(v);
44
45 return err;
46}
47
48static unsigned int
49_property_uint_expected(Efl_Model *model, const char *property)
50{
51 Eina_Value *v;
52 unsigned int r = 0;
53
54 v = efl_model_property_get(model, property);
55 ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_UINT);
56 ck_assert(eina_value_uint_get(v, &r));
57 eina_value_free(v);
58
59 return r;
60}
61
62static Eina_Value
63_child_should_succeed(Efl_Model *model EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v)
64{
65 ck_assert_ptr_eq(eina_value_type_get(&v), EINA_VALUE_TYPE_ARRAY);
66 return v;
67}
68
69static Eina_Value
70_child_should_fail(Efl_Model *model EINA_UNUSED, void *data, const Eina_Value v)
71{
72 unsigned int i, len;
73 Eina_Value c = EINA_VALUE_EMPTY;
74
75 EINA_VALUE_ARRAY_FOREACH(&v, len, i, c)
76 {
77 if (eina_value_type_get(&c) != EINA_VALUE_TYPE_ERROR)
78 {
79 fprintf(stderr, "Request on child %i should have failed but got '%s'\n",
80 (int)(uintptr_t) data, eina_value_to_string(&c));
81 abort();
82 }
83 }
84 return eina_value_int_init(0);
85}
86
87static Eina_Value
88_total_succeed(Efl_Model *model EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v)
89{
90 efl_loop_quit(efl_loop_get(model), eina_value_string_init("BOOM"));
91 return v;
92}
93
94static Eina_Value
95_total_failed(Efl_Model *model EINA_UNUSED, void *data EINA_UNUSED, Eina_Error err)
96{
97 fprintf(stderr, "Shouldn't have failed: '%s'\n", eina_error_msg_get(err));
98 efl_loop_quit(efl_loop_get(model), eina_value_int_init(42));
99 return eina_value_error_init(err);
100}
101
102static Eina_Value
103_children_homogeneous_slice_get_then(Efl_Model *model, void *data EINA_UNUSED, const Eina_Value v)
104{
105 unsigned int i, len;
106 Efl_Model *child = NULL;
107 Eina_Future *all[4] = { NULL, NULL, NULL, EINA_FUTURE_SENTINEL };
108 Eina_Future *f;
109
110 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
111
112 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
113 {
114 ck_assert_int_eq(_property_error_expected(child, "self.width"), EAGAIN);
115 ck_assert_int_eq(_property_error_expected(child, "self.height"), EAGAIN);
116 }
117
118 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
119 {
120 Eina_Value *v;
121 unsigned int w, h;
122
123 v = efl_model_property_get(child, "test_p_int");
124 eina_value_uint_convert(v, &w);
125 eina_value_uint_convert(v, &h);
126 eina_value_free(v);
127
128 w *= 2;
129 h *= 3;
130
131 all[i] = eina_future_all(efl_model_property_set(child, "self.width", eina_value_uint_new(w)),
132 efl_model_property_set(child, "self.height", eina_value_uint_new(h)));
133
134 if (i == 0)
135 all[i] = efl_future_then(model, all[i], .success = _child_should_succeed);
136 else
137 all[i] = efl_future_then(model, all[i],
138 .success = _child_should_fail,
139 .success_type = EINA_VALUE_TYPE_ARRAY,
140 .data = (void*)(uintptr_t) i);
141 }
142
143 f = eina_future_all_array(all);
144 f = efl_future_then(model, f, .success = _total_succeed, .error = _total_failed);
145 return eina_future_as_value(f);
146}
147
148EFL_START_TEST(efl_ui_model_homogeneous_test)
149{
150 Efl_Model_Item *base_model, *model;
151 Eina_Value *ret__;
152 Eina_Future *future;
153 int real__;
154
155 base_model = _generate_base_model();
156
157 model = efl_add_ref(EFL_UI_MODEL_HOMOGENEOUS_CLASS, efl_main_loop_get(),
158 efl_ui_view_model_set(efl_added, base_model));
159 ck_assert(!!model);
160
161 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
162 efl_future_then(model, future, .success = _children_homogeneous_slice_get_then);
163
164 ck_assert_int_eq(_property_error_expected(model, "total.width"), EAGAIN);
165 ck_assert_int_eq(_property_error_expected(model, "total.height"), EAGAIN);
166 ck_assert_int_eq(_property_error_expected(model, "item.width"), EAGAIN);
167 ck_assert_int_eq(_property_error_expected(model, "item.height"), EAGAIN);
168
169 ret__ = efl_loop_begin(efl_app_main_get(EFL_APP_CLASS));
170 real__ = efl_loop_exit_code_process(ret__);
171 fail_if(real__ != 0);
172
173 ck_assert_int_eq(_property_uint_expected(model, "total.width"), base_ints[0] * 2);
174 ck_assert_int_eq(_property_uint_expected(model, "total.height"), base_ints[0] * 3 * 3);
175 ck_assert_int_eq(_property_uint_expected(model, "item.width"), base_ints[0] * 2);
176 ck_assert_int_eq(_property_uint_expected(model, "item.height"), base_ints[0] * 3);
177}
178EFL_END_TEST
179
180void
181efl_ui_model(TCase *tc)
182{
183 tcase_add_test(tc, efl_ui_model_homogeneous_test);
184}
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index e87627ffe5..91a579a763 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -1,10 +1,7 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h" 2# include "elementary_config.h"
3#endif 3#endif
4#include <check.h> 4
5#define EFL_NOLEGACY_API_SUPPORT
6#include <Efl_Ui.h>
7#include "../efl_check.h"
8#include "efl_ui_suite.h" 5#include "efl_ui_suite.h"
9#include "suite_helpers.h" 6#include "suite_helpers.h"
10 7
@@ -19,6 +16,7 @@ static const Efl_Test_Case etc[] = {
19 { "efl_ui_image", efl_ui_test_image}, 16 { "efl_ui_image", efl_ui_test_image},
20 { "efl_ui_image_zoomable", efl_ui_test_image_zoomable}, 17 { "efl_ui_image_zoomable", efl_ui_test_image_zoomable},
21 { "efl_ui_layout", efl_ui_test_layout}, 18 { "efl_ui_layout", efl_ui_test_layout},
19 { "Efl_Ui_Model", efl_ui_model },
22 { NULL, NULL } 20 { NULL, NULL }
23}; 21};
24 22
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 30b1a919a0..b131f01476 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -2,7 +2,11 @@
2#define EFL_UI_SUITE_H 2#define EFL_UI_SUITE_H
3 3
4#include <check.h> 4#include <check.h>
5
6#define EFL_NOLEGACY_API_SUPPORT
7#include <Efl_Ui.h>
5#include "../efl_check.h" 8#include "../efl_check.h"
9
6#define ck_assert_strn_eq(s1, s2, len) \ 10#define ck_assert_strn_eq(s1, s2, len) \
7 { \ 11 { \
8 char expected[len+1], actual[len+1]; \ 12 char expected[len+1], actual[len+1]; \
@@ -15,7 +19,6 @@
15 ck_assert_str_eq(expected, actual); \ 19 ck_assert_str_eq(expected, actual); \
16 } 20 }
17 21
18#include <Eo.h>
19void efl_ui_test_grid(TCase *tc); 22void efl_ui_test_grid(TCase *tc);
20void efl_ui_test_atspi(TCase *tc); 23void efl_ui_test_atspi(TCase *tc);
21void efl_ui_test_image_zoomable(TCase *tc); 24void efl_ui_test_image_zoomable(TCase *tc);
@@ -25,6 +28,8 @@ void efl_ui_test_image(TCase *tc);
25void efl_ui_test_focus(TCase *tc); 28void efl_ui_test_focus(TCase *tc);
26void efl_ui_test_focus_sub(TCase *tc); 29void efl_ui_test_focus_sub(TCase *tc);
27 30
31void efl_ui_model(TCase *tc);
32
28Eo *win_add(); 33Eo *win_add();
29Eo *win_add_focused(); 34Eo *win_add_focused();
30#endif 35#endif
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index 51af9d46cd..c9e4cdffb6 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -115,6 +115,7 @@ elementary_suite = executable('elementary_suite',
115efl_ui_suite_src = [ 115efl_ui_suite_src = [
116 'efl_ui_suite.c', 116 'efl_ui_suite.c',
117 'suite_helpers.c', 117 'suite_helpers.c',
118 'suite_helpers.h',
118 'elm_test_init.c', 119 'elm_test_init.c',
119 'efl_ui_test_atspi.c', 120 'efl_ui_test_atspi.c',
120 'efl_ui_test_focus_common.c', 121 'efl_ui_test_focus_common.c',
@@ -125,6 +126,8 @@ efl_ui_suite_src = [
125 'efl_ui_test_image.c', 126 'efl_ui_test_image.c',
126 'efl_ui_test_image_zoomable.c', 127 'efl_ui_test_image_zoomable.c',
127 'efl_ui_test_layout.c', 128 'efl_ui_test_layout.c',
129 'efl_ui_suite.h',
130 'efl_ui_model.c',
128] 131]
129 132
130efl_ui_suite = executable('efl_ui_suite', 133efl_ui_suite = executable('efl_ui_suite',