herdsman pushed a commit to branch efl-1.20.

http://git.enlightenment.org/core/efl.git/commit/?id=434247391dc8ad4e66b3b11507b03e81e60746bc

commit 434247391dc8ad4e66b3b11507b03e81e60746bc
Author: Youngbok Shin <youngb.s...@samsung.com>
Date:   Wed May 2 10:33:35 2018 +0300

    edje: fix backward compatibility issue caused by legacy cursor funcs
    
    Summary:
    edje_object_part_text_cursor_prev/next/up/down has return value.
    It has to return EINA_TRUE when only it successed.
    But, when these funcs moved to legacy, it changed to return EINA_TRUE
    whenever it fails or success. It must return EINA_FALSE when it fails.
    @fix
    
    Test Plan:
    - Run test suite
      make check
    
    Reviewers: herdsman, raster, cedric, woohyun
    
    Subscribers: zmike
    
    Differential Revision: https://phab.enlightenment.org/D5972
    
    Committer's note: backported with an additional fix to tests.
---
 src/Makefile_Edje.am                     |  2 +
 src/lib/edje/edje_legacy.c               | 64 ++++++++++++++++++++-----
 src/tests/edje/data/test_text_cursor.edc | 22 +++++++++
 src/tests/edje/edje_test_edje.c          | 81 ++++++++++++++++++++++++++++++++
 4 files changed, 157 insertions(+), 12 deletions(-)

diff --git a/src/Makefile_Edje.am b/src/Makefile_Edje.am
index 4ca20e570b..925880514b 100644
--- a/src/Makefile_Edje.am
+++ b/src/Makefile_Edje.am
@@ -287,6 +287,7 @@ tests/edje/data/test_combine_keywords.edc \
 tests/edje/data/test_messages.edc \
 tests/edje/data/test_signals.edc \
 tests/edje/data/test_signal_callback_del_full.edc \
+tests/edje/data/test_text_cursor.edc \
 tests/edje/data/filter.lua
 
 
@@ -330,6 +331,7 @@ EDJE_TEST_FILES = tests/edje/data/test_layout.edj \
                      tests/edje/data/test_messages.edj \
                      tests/edje/data/test_signals.edj \
                      tests/edje/data/test_signal_callback_del_full.edj \
+                     tests/edje/data/test_text_cursor.edj \
                      $(NULL)
 
 CLEANFILES += $(EDJE_TEST_FILES)
diff --git a/src/lib/edje/edje_legacy.c b/src/lib/edje/edje_legacy.c
index 256f468fe9..052805cda5 100644
--- a/src/lib/edje/edje_legacy.c
+++ b/src/lib/edje/edje_legacy.c
@@ -250,33 +250,73 @@ edje_object_part_text_cursor_line_end_set(Edje_Object 
*obj, const char *part, Ed
 EAPI Eina_Bool
 edje_object_part_text_cursor_prev(Edje_Object *obj, const char *part, 
Edje_Cursor cur)
 {
-   efl_text_cursor_char_prev(efl_part(obj, part),
-         efl_text_cursor_get(efl_part(obj, part), (int) cur));
-   return EINA_TRUE;
+   Efl_Text_Cursor_Cursor *c;
+   int old_pos, new_pos;
+
+   c = efl_text_cursor_get(efl_part(obj, part), (int) cur);
+
+   old_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+   efl_text_cursor_char_prev(efl_part(obj, part), c);
+   new_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+
+   if (old_pos != new_pos)
+     return EINA_TRUE;
+
+   return EINA_FALSE;
 }
 
 EAPI Eina_Bool
 edje_object_part_text_cursor_next(Edje_Object *obj, const char *part, 
Edje_Cursor cur)
 {
-   efl_text_cursor_char_next(efl_part(obj, part),
-         efl_text_cursor_get(efl_part(obj, part), (int) cur));
-   return EINA_TRUE;
+   Efl_Text_Cursor_Cursor *c;
+   int old_pos, new_pos;
+
+   c = efl_text_cursor_get(efl_part(obj, part), (int) cur);
+
+   old_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+   efl_text_cursor_char_next(efl_part(obj, part), c);
+   new_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+
+   if (old_pos != new_pos)
+     return EINA_TRUE;
+
+   return EINA_FALSE;
 }
 
 EAPI Eina_Bool
 edje_object_part_text_cursor_down(Edje_Object *obj, const char *part, 
Edje_Cursor cur)
 {
-   efl_text_cursor_line_jump_by(efl_part(obj, part),
-         efl_text_cursor_get(efl_part(obj, part), (int) cur), 1);
-   return EINA_TRUE;
+   Efl_Text_Cursor_Cursor *c;
+   int old_pos, new_pos;
+
+   c = efl_text_cursor_get(efl_part(obj, part), (int) cur);
+
+   old_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+   efl_text_cursor_line_jump_by(efl_part(obj, part), c, 1);
+   new_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+
+   if (old_pos != new_pos)
+     return EINA_TRUE;
+
+   return EINA_FALSE;
 }
 
 EAPI Eina_Bool
 edje_object_part_text_cursor_up(Edje_Object *obj, const char *part, 
Edje_Cursor cur)
 {
-   efl_text_cursor_line_jump_by(efl_part(obj, part),
-         efl_text_cursor_get(efl_part(obj, part), (int) cur), -1);
-   return EINA_TRUE;
+   Efl_Text_Cursor_Cursor *c;
+   int old_pos, new_pos;
+
+   c = efl_text_cursor_get(efl_part(obj, part), (int) cur);
+
+   old_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+   efl_text_cursor_line_jump_by(efl_part(obj, part), c, -1);
+   new_pos = efl_text_cursor_position_get(efl_part(obj, part), c);
+
+   if (old_pos != new_pos)
+     return EINA_TRUE;
+
+   return EINA_FALSE;
 }
 
 EAPI void
diff --git a/src/tests/edje/data/test_text_cursor.edc 
b/src/tests/edje/data/test_text_cursor.edc
new file mode 100644
index 0000000000..7392e545bc
--- /dev/null
+++ b/src/tests/edje/data/test_text_cursor.edc
@@ -0,0 +1,22 @@
+collections {
+   styles {
+      style { name: "tb_style";
+         base: "font=Sans font_size=20 color=#fff";
+      }
+   }
+   group { name: "test_text_cursor";
+      parts {
+         part { name: "text";
+            type: TEXTBLOCK;
+            entry_mode: EDITABLE;
+            cursor_mode: BEFORE;
+            description { state: "default" 0.0;
+               min: 300 300;
+               text {
+                  style: "tb_style";
+               }
+            }
+         }
+      }
+   }
+}
diff --git a/src/tests/edje/edje_test_edje.c b/src/tests/edje/edje_test_edje.c
index f7b017566f..4b3e1810f5 100644
--- a/src/tests/edje/edje_test_edje.c
+++ b/src/tests/edje/edje_test_edje.c
@@ -943,6 +943,86 @@ START_TEST(edje_test_signal_callback_del_full)
 }
 END_TEST
 
+START_TEST(edje_test_text_cursor)
+{
+   Evas *evas;
+   Evas_Object *obj;
+   const char *buf = "ABC<br/>DEF";
+   const char *txt;
+   int i, old_pos, new_pos;
+
+   evas = EDJE_TEST_INIT_EVAS();
+
+   obj = edje_object_add(evas);
+   fail_unless(edje_object_file_set(obj, 
test_layout_get("test_text_cursor.edj"), "test_text_cursor"));
+   edje_object_part_text_set(obj, "text", buf);
+   txt = edje_object_part_text_get(obj, "text");
+   fail_if(!txt || strcmp(txt, buf));
+
+   edje_object_part_text_cursor_pos_set(obj, "text", EDJE_CURSOR_MAIN, 0);
+   ck_assert_int_eq(edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN), 0);
+   edje_object_part_text_cursor_pos_set(obj, "text", EDJE_CURSOR_MAIN, 1);
+   ck_assert_int_eq(edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN), 1);
+
+   /* Move cursor to the 0 pos from 1 pos */
+   old_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert(edje_object_part_text_cursor_prev(obj, "text", EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_ne(old_pos, new_pos);
+
+   /* Move cursor to the -1 pos from 0 pos. It has to fail. */
+   old_pos = new_pos;
+   ck_assert(!edje_object_part_text_cursor_prev(obj, "text", 
EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_eq(old_pos, new_pos);
+
+   /* Jump to 2nd line from 1st line.
+    * It has to return EINA_TRUE which means success. */
+   old_pos = new_pos;
+   ck_assert(edje_object_part_text_cursor_down(obj, "text", EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_ne(old_pos, new_pos);
+
+   /* Try to jump to 3rd line from 2nd line. But, 3rd line does not exist.
+    * So, it has to return EINA_FALSE which means failure. */
+   old_pos = new_pos;
+   ck_assert(!edje_object_part_text_cursor_down(obj, "text", 
EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_eq(old_pos, new_pos);
+
+   /* Move cursor to the end of 2nd line. */
+   for (i = 0; i < 3; i++)
+     {
+        old_pos = new_pos;
+        ck_assert(edje_object_part_text_cursor_next(obj, "text", 
EDJE_CURSOR_MAIN));
+        new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+        ck_assert_int_ne(old_pos, new_pos);
+     }
+
+   /* Move cursor to the next of the end of 2nd line which does not exist. */
+   old_pos = new_pos;
+   ck_assert(!edje_object_part_text_cursor_next(obj, "text", 
EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_eq(old_pos, new_pos);
+
+   /* Jump to 1st line from 2nd line.
+    * It has to return EINA_TRUE which means success. */
+   old_pos = new_pos;
+   ck_assert(edje_object_part_text_cursor_up(obj, "text", EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_ne(old_pos, new_pos);
+
+   /* Try to jump to the above of 1st line from 1st line. But, there is no 
such line.
+    * So, it has to return EINA_FALSE which means failure. */
+   old_pos = new_pos;
+   ck_assert(!edje_object_part_text_cursor_up(obj, "text", EDJE_CURSOR_MAIN));
+   new_pos = edje_object_part_text_cursor_pos_get(obj, "text", 
EDJE_CURSOR_MAIN);
+   ck_assert_int_eq(old_pos, new_pos);
+
+   EDJE_TEST_FREE_EVAS();
+}
+END_TEST
+
 void edje_test_edje(TCase *tc)
 {
    tcase_add_test(tc, edje_test_edje_init);
@@ -968,4 +1048,5 @@ void edje_test_edje(TCase *tc)
    tcase_add_test(tc, edje_test_message_send_eo);
    tcase_add_test(tc, edje_test_signals);
    tcase_add_test(tc, edje_test_signal_callback_del_full);
+   tcase_add_test(tc, edje_test_text_cursor);
 }

-- 


Reply via email to