Support span tag: background
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextEditor-internal.cpp
index 53474ae..0af3a34 100644 (file)
@@ -87,12 +87,12 @@ int UtcDaliTextEditorMarkupUnderline(void)
   application.SendNotification();
   application.Render();
 
-  uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
+  uint32_t expectedNumberOfUnderlineRuns = 2u;
 
   Toolkit::Internal::TextEditor& textEditorImpl        = GetImpl(textEditor);
   const Text::Length             numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
 
-  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
+  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
 
   Vector<UnderlinedGlyphRun> underlineRuns;
   underlineRuns.Resize(numberOfUnderlineRuns);
@@ -100,12 +100,11 @@ int UtcDaliTextEditorMarkupUnderline(void)
 
   //ABC are underlined
   DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
-  DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 1u, TEST_LOCATION);
-  DALI_TEST_EQUALS(underlineRuns[2u].glyphRun.glyphIndex, 2u, TEST_LOCATION);
+  DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
 
   //GH are underlined
-  DALI_TEST_EQUALS(underlineRuns[3u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(underlineRuns[4u].glyphRun.glyphIndex, 6u, TEST_LOCATION);
+  DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
 
   END_TEST;
 }
@@ -128,9 +127,7 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
     "<u height='5.0f'>ABC6</u>then"
     "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
     "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
-    "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
-
-    ;
+    "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end";
 
   textEditor.SetProperty(TextEditor::Property::TEXT, testText);
   textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
@@ -138,13 +135,12 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
   application.SendNotification();
   application.Render();
 
-  const uint32_t NUMBER_OF_CASES                  = 9u;
-  uint32_t       expectedNumberOfUnderlinedGlyphs = 36u;
+  const uint32_t expectedNumberOfUnderlineRuns = 9u;
 
   Toolkit::Internal::TextEditor& textEditorImpl        = GetImpl(textEditor);
   const Text::Length             numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
 
-  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
+  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
 
   Vector<UnderlinedGlyphRun> underlineRuns;
   underlineRuns.Resize(numberOfUnderlineRuns);
@@ -153,20 +149,16 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
   struct DataOfCase
   {
     std::string              title;
-    uint32_t                 startIndex;
-    uint32_t                 endIndex;
-    GlyphIndex               startGlyphIndex;
-    GlyphIndex               endGlyphIndex;
+    GlyphIndex               glyphIndex;
+    Length                   numberOfGlyphs;
     UnderlineStyleProperties properties;
   };
   DataOfCase data[] =
     {
       //<u>ABC1</u>
       {"<u>ABC1</u>",
-       0u,
-       3u,
        5u,
-       8u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::BLACK,
@@ -182,10 +174,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u type='solid'>ABC2</u>
       {"<u type='solid'>ABC2</u>",
-       4u,
-       7u,
        13u,
-       16u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::BLACK,
@@ -201,10 +191,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u type='dashed'>ABC3</u>
       {"<u type='dashed'>ABC3</u>",
-       8u,
-       11u,
        21u,
-       24u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -220,10 +208,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u type='double'>ABC4</u>
       {"<u type='double'>ABC4</u>",
-       12u,
-       15u,
        29u,
-       32u,
+       4u,
        {
          Text::Underline::DOUBLE,
          Color::BLACK,
@@ -239,10 +225,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u color='green'>ABC5</u>
       {"<u color='green'>ABC5</u>",
-       16u,
-       19u,
        37u,
-       40u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::GREEN,
@@ -258,10 +242,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u height='5.0f'>ABC6</u>
       {"<u height='5.0f'>ABC6</u>",
-       20u,
-       23u,
        45u,
-       48u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::BLACK,
@@ -277,10 +259,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u type='dashed' dash-gap='3.0f'>ABC7</u>
       {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
-       24u,
-       27u,
        53u,
-       56u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -296,10 +276,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u type='dashed' dash-width='4.0f'>ABC8</u>
       {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
-       28u,
-       31u,
        61u,
-       64u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -315,10 +293,8 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
       //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
       {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
-       32u,
-       35u,
        69u,
-       72u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLUE,
@@ -334,14 +310,12 @@ int UtcDaliTextEditorMarkupUnderlineAttributes(void)
 
     };
 
-  for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
+  for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
   {
     tet_infoline(data[i].title.c_str());
-    DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
-    DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
-
-    DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
-    DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
+    DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
   }
 
   END_TEST;
@@ -365,9 +339,7 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>then"
     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>then"
-    "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>end"
-
-    ;
+    "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>end";
 
   textEditor.SetProperty(TextEditor::Property::TEXT, testText);
   textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
@@ -375,13 +347,12 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
   application.SendNotification();
   application.Render();
 
-  const uint32_t NUMBER_OF_CASES                  = 8u;
-  uint32_t       expectedNumberOfUnderlinedGlyphs = 32u;
+  const uint32_t expectedNumberOfUnderlineRuns = 8u;
 
   Toolkit::Internal::TextEditor& textEditorImpl        = GetImpl(textEditor);
   const Text::Length             numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
 
-  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
+  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
 
   Vector<UnderlinedGlyphRun> underlineRuns;
   underlineRuns.Resize(numberOfUnderlineRuns);
@@ -390,20 +361,16 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
   struct DataOfCase
   {
     std::string              title;
-    uint32_t                 startIndex;
-    uint32_t                 endIndex;
-    GlyphIndex               startGlyphIndex;
-    GlyphIndex               endGlyphIndex;
+    GlyphIndex               glyphIndex;
+    Length                   numberOfGlyphs;
     UnderlineStyleProperties properties;
   };
   DataOfCase data[] =
     {
-
+      //<u type='solid'>ABC2</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
-       0u,
-       3u,
        13u,
-       16u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::BLACK,
@@ -417,11 +384,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u type='dashed'>ABC3</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
-       4u,
-       7u,
        21u,
-       24u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -435,11 +401,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u type='double'>ABC4</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
-       8u,
-       11u,
        29u,
-       32u,
+       4u,
        {
          Text::Underline::DOUBLE,
          Color::BLACK,
@@ -453,11 +418,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u color='green'>ABC5</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
-       12u,
-       15u,
        37u,
-       40u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::GREEN,
@@ -471,11 +435,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u height='5.0f'>ABC6</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
-       16u,
-       19u,
        45u,
-       48u,
+       4u,
        {
          Text::Underline::SOLID,
          Color::BLACK,
@@ -489,11 +452,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u type='dashed' dash-gap='3.0f'>ABC7</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>",
-       20u,
-       23u,
        53u,
-       56u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -507,11 +469,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          false,
        }},
 
+      //<u type='dashed' dash-width='4.0f'>ABC8</u>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>",
-       24u,
-       27u,
        61u,
-       64u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLACK,
@@ -525,11 +486,10 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
          true,
        }},
 
+      //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>",
-       28u,
-       31u,
        69u,
-       72u,
+       4u,
        {
          Text::Underline::DASHED,
          Color::BLUE,
@@ -545,14 +505,96 @@ int UtcDaliTextEditorMarkupSpanUnderline(void)
 
     };
 
-  for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
+  for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
   {
     tet_infoline(data[i].title.c_str());
-    DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
-    DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
+    DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextEditorMarkupNestedUnderlineTags(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextEditorMarkupNestedUnderlineTags ");
+
+  TextEditor textEditor = TextEditor::New();
+
+  application.GetScene().Add(textEditor);
+
+  std::string testText = "start<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>end";
+
+  textEditor.SetProperty(TextEditor::Property::TEXT, testText);
+  textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
+
+  application.SendNotification();
+  application.Render();
+
+  const uint32_t expectedNumberOfUnderlineRuns = 2u;
+
+  Toolkit::Internal::TextEditor& textEditorImpl        = GetImpl(textEditor);
+  const Text::Length             numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
+
+  DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
+
+  Vector<UnderlinedGlyphRun> underlineRuns;
+  underlineRuns.Resize(numberOfUnderlineRuns);
+  textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
+
+  struct DataOfCase
+  {
+    std::string              title;
+    GlyphIndex               glyphIndex;
+    Length                   numberOfGlyphs;
+    UnderlineStyleProperties properties;
+  };
+  DataOfCase data[] =
+    {
+      //Outter
+      {"<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>",
+       5u,
+       8u,
+       {
+         Text::Underline::SOLID,
+         Color::GREEN,
+         5u,
+         1u,
+         2u,
+         false,
+         true,
+         true,
+         false,
+         false,
+       }},
 
-    DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
-    DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
+      //Inner
+      {"<u color='blue' >XYZ</u>",
+       7u,
+       3u,
+       {
+         Text::Underline::SOLID,
+         Color::BLUE,
+         5u,
+         1u,
+         2u,
+         false,
+         true,
+         true,
+         false,
+         false,
+       }},
+
+    };
+
+  for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
+  {
+    tet_infoline(data[i].title.c_str());
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
+    DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
+    DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
   }
 
   END_TEST;
@@ -647,6 +689,37 @@ int UtcDaliTextEditorBackgroundTag(void)
   END_TEST;
 }
 
+int UtcDaliTextEditorSpanBackgroundTag(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextEditorSpanBackgroundTag\n");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK(editor);
+
+  editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
+  editor.SetProperty(TextEditor::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
+  application.GetScene().Add(editor);
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextEditor& editorImpl                   = GetImpl(editor);
+  const ColorIndex* const        backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
+
+  DALI_TEST_CHECK(backgroundColorIndicesBuffer);
+
+  //default color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
+
+  //red color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
+
+  //yellow color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliTextEditorTextWithSpan(void)
 {
   ToolkitTestApplication application;