aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-01-16 18:22:06 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-01-16 18:22:55 -0800
commitaad946f447436a31fbb301d2cf74c5e7cf1057e9 (patch)
treecfd0c795ab845e8a277d03eaf5007af5f5311c95
parentelementary: add a test for Efl.Ui.Model_Exact. (diff)
downloadefl-devs/cedric/homogeneous.tar.gz
elementary: add test for Efl.Ui.Model_Average.devs/cedric/homogeneous
-rw-r--r--src/tests/elementary/efl_ui_model.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index aa06dc70a8..b9c9203370 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -5,9 +5,15 @@
#include "efl_ui_suite.h"
#include "efl_ui_model_homogeneous.eo.h"
#include "efl_ui_model_exact.eo.h"
+#include "efl_ui_model_average.eo.h"
static const int child_number = 3;
static const int base_ints[] = { 41, 42, 43 };
+static const int expected_average[] = {
+ base_ints[0] * 3 * 3,
+ ((base_ints[0] * 3 + base_ints[1] * 3) * 3) / 2,
+ base_ints[0] * 3 + base_ints[1] * 3 + base_ints[2] * 3
+};
static Efl_Model *
_generate_base_model(void)
@@ -247,9 +253,98 @@ EFL_START_TEST(efl_ui_model_exact_test)
}
EFL_END_TEST
+static Eina_Value
+_child_updated_average(Efl_Model *model, void *data, const Eina_Value v)
+{
+ Eina_Value *r;
+ int *ex = data;
+ int got = 0;
+
+ r = efl_model_property_get(model, "Total.Height");
+ ck_assert(eina_value_int_convert(r, &got));
+ ck_assert_int_eq(got, *ex);
+ eina_value_free(r);
+
+ return v;
+}
+
+static Eina_Value
+_children_average_slice_get_then(Efl_Model *model, void *data EINA_UNUSED, const Eina_Value v)
+{
+ unsigned int i, len;
+ Efl_Model *child = NULL;
+ Eina_Future *all[4] = { NULL, NULL, NULL, EINA_FUTURE_SENTINEL };
+ Eina_Future *f;
+
+ fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
+
+ EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
+ {
+ ck_assert_int_eq(_property_uint_expected(child, "Self.Width"), 0);
+ ck_assert_int_eq(_property_uint_expected(child, "Self.Height"), 0);
+ }
+
+ EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
+ {
+ Eina_Value *v;
+ unsigned int w, h;
+
+ v = efl_model_property_get(child, "test_p_int");
+ eina_value_uint_convert(v, &w);
+ eina_value_uint_convert(v, &h);
+ eina_value_free(v);
+
+ w *= 2;
+ h *= 3;
+
+ all[i] = eina_future_all(efl_model_property_set(child, "Self.Width", eina_value_uint_new(w)),
+ efl_model_property_set(child, "Self.Height", eina_value_uint_new(h)));
+ all[i] = efl_future_then(model, all[i], .success = _child_should_succeed);
+
+ // The model average is not updated until the property have succeeded, so we have
+ // to wait before we can fetch the property.
+ all[i] = efl_future_then(model, all[i], .success = _child_updated_average, .data = &expected_average[i]);
+ }
+
+ f = eina_future_all_array(all);
+ f = efl_future_then(model, f, .success = _total_succeed, .error = _total_failed);
+ return eina_future_as_value(f);
+}
+
+EFL_START_TEST(efl_ui_model_average_test)
+{
+ Efl_Model_Item *base_model, *model;
+ Eina_Future *future;
+ Eina_Value *ret__;
+ int real__;
+
+ base_model = _generate_base_model();
+
+ model = efl_add_ref(EFL_UI_MODEL_AVERAGE_CLASS, efl_main_loop_get(),
+ efl_ui_view_model_set(efl_added, base_model));
+ ck_assert(!!model);
+
+ future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
+ efl_future_then(model, future, .success = _children_average_slice_get_then);
+
+ ck_assert_int_eq(_property_uint_expected(model, "Total.Width"), 0);
+ ck_assert_int_eq(_property_uint_expected(model, "Total.Height"), 0);
+ ck_assert_int_eq(_property_error_expected(model, "Item.Width"), EAGAIN);
+ ck_assert_int_eq(_property_error_expected(model, "Item.Height"), EAGAIN);
+
+ ret__ = efl_loop_begin(efl_app_main_get(EFL_APP_CLASS));
+ real__ = efl_loop_exit_code_process(ret__);
+ fail_if(real__ != 0);
+
+ ck_assert_int_eq(_property_uint_expected(model, "Total.Width"), base_ints[2] * 2);
+ ck_assert_int_eq(_property_uint_expected(model, "Total.Height"), base_ints[0] * 3 + base_ints[1] * 3 + base_ints[2] * 3);
+}
+EFL_END_TEST
+
void
efl_ui_model(TCase *tc)
{
tcase_add_test(tc, efl_ui_model_homogeneous_test);
+ tcase_add_test(tc, efl_ui_model_average_test);
tcase_add_test(tc, efl_ui_model_exact_test);
}