ui.relative_layout: enhance relation_xxx_set,get apis 80/204780/2
authorYeongjong Lee <yj34.lee@samsung.com>
Wed, 24 Apr 2019 11:33:20 +0000 (20:33 +0900)
committerYeongJong Lee <yj34.lee@samsung.com>
Fri, 26 Apr 2019 08:08:57 +0000 (08:08 +0000)
Summary:
I forgot `efl_pack_layout_request` after relation_xxx is changed.
Unnecessary register function in `relation_xxx_get` will return unexpected result.
if a object is not child of relative_layout, `relation_xxx_get` should return
`target = NULL` and `relative = 0.0` with error message.

Test Plan: make check

Reviewers: Jaehyun_Cho

Reviewed By: Jaehyun_Cho

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8627

Change-Id: Ifc3fd0f64bb337758bfb1766cf1b334cc2376832

src/bin/elementary/test_ui_relative_layout.c
src/lib/elementary/efl_ui_relative_layout_private.h
src/tests/elementary/efl_ui_test_relative_layout.c

index f1d58af..0e8bcbc 100644 (file)
@@ -74,7 +74,6 @@ _btn_clicked_to_cb(void *data, const Efl_Event *event)
         break;
      }
    efl_text_set(obj, ((to == layout) ? "parent" : (char *)efl_text_get(to)));
-   efl_pack_layout_request(layout);
 }
 
 static void
@@ -102,7 +101,6 @@ _slider_changed_relative_cb(void *data, const Efl_Event *event)
         efl_ui_relative_layout_relation_bottom_set(layout, btn, NULL, val);
         break;
      }
-   efl_pack_layout_request(layout);
 }
 
 static void
index c58f7b0..e0f2abf 100644 (file)
@@ -70,23 +70,35 @@ struct _Efl_Ui_Relative_Layout_Child
 
 #define EFL_UI_RELATIVE_LAYOUT_RELATION_SET_GET(direction, DIRECTION) \
    EOLIAN static void \
-   _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \
+   _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \
    { \
       Efl_Ui_Relative_Layout_Child *rc; \
+      if (!child) return; \
       rc = _relative_child_get(pd, child); \
+      if (!rc) return; \
       if (target) rc->rel[DIRECTION].to = target; \
       if (relative < 0) relative = 0; \
       else if (relative > 1) relative = 1; \
       rc->rel[DIRECTION].relative = relative; \
+      efl_pack_layout_request(obj); \
    } \
    \
    EOLIAN static void \
    _efl_ui_relative_layout_relation_ ## direction ## _get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo **target, double *relative) \
    { \
       Efl_Ui_Relative_Layout_Child *rc; \
-      rc = _relative_child_get(pd, child); \
-      if (target) *target = rc->rel[DIRECTION].to; \
-      if (relative) *relative = rc->rel[DIRECTION].relative; \
+      Eo *rel_to = NULL; \
+      double rel_relative = 0.0; \
+      rc = eina_hash_find(pd->children, &child); \
+      if (rc) \
+        { \
+           rel_to = rc->rel[DIRECTION].to; \
+           rel_relative = rc->rel[DIRECTION].relative; \
+        } \
+      else \
+        ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child)); \
+      if (target) *target = rel_to; \
+      if (relative) *relative = rel_relative; \
    }
 
 #endif
index f769bf4..3027bdb 100644 (file)
@@ -292,10 +292,61 @@ EFL_START_TEST (efl_ui_relative_layout_layout_update_chain)
 }
 EFL_END_TEST
 
+EFL_START_TEST (efl_ui_relative_layout_relation_set)
+{
+   Eo *btn;
+   Eo *target = NULL;
+   double relative;
+
+   btn = efl_add(EFL_UI_BUTTON_CLASS, layout);
+
+   // negative test
+   efl_ui_relative_layout_relation_top_get(layout, NULL, &target, &relative);
+   ck_assert_ptr_eq(target, NULL);
+   ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+   efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, NULL);
+   ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+   efl_ui_relative_layout_relation_top_set(layout, NULL, NULL, 0.0);
+   ck_assert_ptr_eq(target, NULL);
+   ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+   // default value test
+   efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.0);
+
+   efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 0.0));
+   efl_ui_relative_layout_relation_bottom_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 1.0));
+   efl_ui_relative_layout_relation_left_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 0.0));
+   efl_ui_relative_layout_relation_right_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 1.0));
+
+   // positive test
+   efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.123);
+   efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 0.123));
+
+   efl_ui_relative_layout_relation_top_set(layout, btn, NULL, 0.456);
+   efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+   ck_assert_ptr_eq(target, layout);
+   ck_assert(EINA_DBL_EQ(relative, 0.456));
+}
+EFL_END_TEST
+
 void efl_ui_test_relative_layout(TCase *tc)
 {
    tcase_add_checked_fixture(tc, layout_setup, layout_teardown);
    tcase_add_test(tc, efl_ui_relative_layout_class_check);
    tcase_add_test(tc, efl_ui_relative_layout_layout_update);
    tcase_add_test(tc, efl_ui_relative_layout_layout_update_chain);
+   tcase_add_test(tc, efl_ui_relative_layout_relation_set);
 }