Evas/Textblock: Introduce PS deletion bug test and fix
authorDaniel Hirt <daniel.hirt@samsung.com>
Tue, 17 Jun 2014 10:09:26 +0000 (11:09 +0100)
committerTom Hacohen <tom@stosb.com>
Tue, 17 Jun 2014 10:11:33 +0000 (11:11 +0100)
Summary:
This test should make the test suite fail. It sets "a<ps>b" and
"a<ps/>b" markups, and deletes the PS format. Essentially, these two
different markups should have the same result by this deletion. Instead,
only the <ps/> format gets deleted properly.
A follow-up commit is added with this as a fix.

Evas/Textblock: fix deletion of PS bug

Fixes an issue with deletion of "<ps>". Format deletion was only
performed for formats that are own-closers. This sets the paragraph
separator to be an own-closer format.

@fix

Reviewers: tasn

Reviewed By: tasn

CC: JackDanielZ, id213sin
Differential Revision: https://phab.enlightenment.org/D1046

src/lib/evas/canvas/evas_object_textblock.c
src/tests/evas/evas_test_textblock.c

index fc90a4f..df668e5 100644 (file)
@@ -8491,11 +8491,27 @@ _evas_textblock_node_format_new(Evas_Textblock_Data *o, const char *_format)
         if ((format_len > 0) && format[format_len - 1] == '>')
           {
              format_len--; /* We don't care about '>' */
-             /* Check if it closes itself. Skip the </> case. */
-             if ((format_len > 1) && format[format_len - 1] == '/')
+             /* Check if it closes itself, i.e. one of the following:
+              * 1. Ends with a "/" e.g. "<my_tag/>"
+              * 2. Is a paragraph separator */
+             /* Skip the </> case. */
+             if (format_len > 1)
                {
-                  format_len--; /* We don't care about '/' */
-                  n->own_closer = EINA_TRUE;
+                  if (format[format_len - 1] == '/')
+                    {
+                       format_len--; /* We don't care about '/' */
+                       n->own_closer = EINA_TRUE;
+                    }
+                  else if (format_len == 2)
+                    {
+                       char tmp[format_len + 1];
+                       strncpy(tmp, format, format_len);
+                       tmp[format_len] = '\0';
+                       if (_IS_PARAGRAPH_SEPARATOR(o, tmp))
+                         {
+                             n->own_closer = EINA_TRUE;
+                         }
+                    }
                }
           }
 
index aebb8aa..a727b76 100644 (file)
@@ -2909,6 +2909,42 @@ START_TEST(evas_textblock_size)
 }
 END_TEST
 
+START_TEST(evas_textblock_delete)
+{
+   START_TB_TEST();
+   const Evas_Object_Textblock_Node_Format *fmt;
+
+   /* The first and the second set of commands should result in the same
+    * conditions for format and text nodes of the textblock object.
+    * Essentially, it creates the markup 'a<ps>b' */
+   evas_object_textblock_text_markup_set(tb, "ab");
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if(fmt);
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_object_textblock_text_markup_prepend(cur, "<ps/>");
+   evas_textblock_cursor_pos_set(cur, 1);
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if (!fmt);
+   evas_textblock_cursor_char_delete(cur);
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if(fmt);
+
+   evas_object_textblock_text_markup_set(tb, "ab");
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if(fmt);
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_object_textblock_text_markup_prepend(cur, "<ps>");
+   evas_textblock_cursor_pos_set(cur, 1);
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if (!fmt);
+   evas_textblock_cursor_char_delete(cur);
+   fmt =  evas_textblock_cursor_format_get(cur);
+   fail_if(fmt);
+
+   END_TB_TEST();
+}
+END_TEST;
+
 void evas_test_textblock(TCase *tc)
 {
    tcase_add_test(tc, evas_textblock_simple);
@@ -2929,5 +2965,6 @@ void evas_test_textblock(TCase *tc)
    tcase_add_test(tc, evas_textblock_various);
    tcase_add_test(tc, evas_textblock_wrapping);
    tcase_add_test(tc, evas_textblock_items);
+   tcase_add_test(tc, evas_textblock_delete);
 }