Updates for const->constexpr
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-BidirectionalSupport.cpp
index 92ee580..e056f73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
 #include <dali-toolkit/internal/text/text-run-container.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include <toolkit-text-model.h>
+#include <toolkit-text-utils.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -38,11 +38,6 @@ using namespace Text;
 //                            CharacterIndex startIndex,
 //                            Length numberOfCharacters,
 //                            Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo )
-// void ReorderLines( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
-//                    CharacterIndex startIndex,
-//                    Length numberOfCharacters,
-//                    Vector<LineRun>& lineRuns,
-//                    Vector<BidirectionalLineInfoRun>& lineInfoRuns )
 // bool GetMirroredText( const Vector<Character>& text,
 //                       Vector<CharacterDirection>& directions,
 //                       const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
@@ -50,6 +45,7 @@ using namespace Text;
 //                       Length numberOfCharacters,
 //                       Vector<Character>& mirroredText )
 // void GetCharactersDirection( const Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo,
+//                              Length totalNumberOfCharacters,
 //                              CharacterIndex startIndex,
 //                              Length numberOfCharacters,
 //                              Vector<CharacterDirection>& directions )
@@ -78,16 +74,6 @@ struct BidiLineData
   unsigned int* visualToLogical;
 };
 
-struct ReorderLinesData
-{
-  std::string   description;        ///< Description of the test.
-  std::string   text;               ///< Input text.
-  unsigned int  startIndex;         ///< The index from where the model is updated.
-  unsigned int  numberOfCharacters; ///< The number of characters.
-  unsigned int  numberOfLineInfo;   ///< The number or reordered lines.
-  BidiLineData* bidiLineData;       ///< The bidirectional line info.
-};
-
 struct GetMirroredTextData
 {
   std::string  description;        ///< Description of the test.
@@ -99,27 +85,36 @@ struct GetMirroredTextData
 
 struct GetCharactersDirectionData
 {
-  std::string  description;         ///< Description of the test.
-  std::string  text;                ///< Input text.
-  unsigned int startIndex;          ///< The index from where the model is updated.
-  unsigned int numberOfCharacters;  ///< The number of characters.
-  bool*        directions;          ///< The expected directions.
+  std::string  description;            ///< Description of the test.
+  std::string  text;                   ///< Input text.
+  unsigned int startIndex;             ///< The index from where the model is updated.
+  unsigned int numberOfCharacters;     ///< The number of characters.
+  bool*        directions;             ///< The expected directions.
+  bool         markupProcessorEnabled; ///< Enable markup processor to use markup text.
 };
 
 bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data )
 {
   // 1) Create the model.
-  LogicalModelPtr logicalModel = LogicalModel::New();
-  VisualModelPtr visualModel = VisualModel::New();
+  ModelPtr textModel;
+  MetricsPtr metrics;
   Size textArea(100.f, 60.f);
   Size layoutSize;
 
   // Create the model.
+  const Vector<FontDescriptionRun> fontDescriptions;
+  const LayoutOptions options;
   CreateTextModel( data.text,
                    textArea,
+                   fontDescriptions,
+                   options,
                    layoutSize,
-                   logicalModel,
-                   visualModel );
+                   textModel,
+                   metrics,
+                   false );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   // 2) Clear the bidirectional paragraph info data.
   Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
@@ -183,142 +178,28 @@ bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data )
   return true;
 }
 
-/**
- * @brief Frees previously allocated bidirectional resources.
- *
- * @param[in] bidirectionalLineInfo Bidirectional info per line.
- * @param[in] startIndex Index to the first line with bidirectional info to be freed.
- * @param[in] endIndex Index to the last line with bidirectional info to be freed.
- */
-void FreeBidirectionalLineInfoResources( Vector<BidirectionalLineInfoRun> bidirectionalLineInfo,
-                                         uint32_t startIndex,
-                                         uint32_t endIndex )
-{
-  // Free the allocated memory used to store the conversion table in the bidirectional line info run.
-  for( Vector<BidirectionalLineInfoRun>::Iterator it = bidirectionalLineInfo.Begin() + startIndex,
-         endIt = bidirectionalLineInfo.Begin() + endIndex;
-       it != endIt;
-       ++it )
-  {
-    BidirectionalLineInfoRun& bidiLineInfo = *it;
-
-    free( bidiLineInfo.visualToLogicalMap );
-  }
-}
-
-bool ReorderLinesTest( const ReorderLinesData& data )
-{
-  // 1) Create the model.
-  LogicalModelPtr logicalModel = LogicalModel::New();
-  VisualModelPtr visualModel = VisualModel::New();
-  Size textArea(100.f, 300.f);
-  Size layoutSize;
-
-  // Create the model.
-  CreateTextModel( data.text,
-                   textArea,
-                   layoutSize,
-                   logicalModel,
-                   visualModel );
-
-  // 2) Clear the bidirectional line info data.
-  uint32_t startRemoveIndex = logicalModel->mBidirectionalLineInfo.Count();
-  uint32_t endRemoveIndex = startRemoveIndex;
-  ClearCharacterRuns( data.startIndex,
-                      data.startIndex + data.numberOfCharacters - 1u,
-                      logicalModel->mBidirectionalLineInfo,
-                      startRemoveIndex,
-                      endRemoveIndex );
-
-  // Index to the first index to be removed.
-
-  FreeBidirectionalLineInfoResources( logicalModel->mBidirectionalLineInfo, startRemoveIndex, endRemoveIndex );
-  BidirectionalLineInfoRun* bidiLineBuffer = logicalModel->mBidirectionalLineInfo.Begin();
-  logicalModel->mBidirectionalLineInfo.Erase( bidiLineBuffer + startRemoveIndex,
-                                              bidiLineBuffer + endRemoveIndex );
-
-  // 3) Call the function ReorderLines()
-
-  ReorderLines( logicalModel->mBidirectionalParagraphInfo,
-                data.startIndex,
-                data.numberOfCharacters,
-                visualModel->mLines,
-                logicalModel->mBidirectionalLineInfo );
-
-  // 4) Compare the results.
-
-  if( data.numberOfLineInfo != logicalModel->mBidirectionalLineInfo.Count() )
-  {
-    // Different number of bidirectional lines.
-    std::cout << "  different number of bidi lines : " << logicalModel->mBidirectionalLineInfo.Count() << ", expected : " << data.numberOfLineInfo << std::endl;
-    for( unsigned int index = 0u; index < logicalModel->mBidirectionalLineInfo.Count(); ++index )
-    {
-      const BidirectionalLineInfoRun& run = logicalModel->mBidirectionalLineInfo[index];
-      const BidiLineData& bidiLineData = data.bidiLineData[index];
-
-      std::cout << "  bidi line : " << index << ", index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << std::endl;
-      std::cout << "                      expected index : " << bidiLineData.characterIndex << ", num chars : " << bidiLineData.numberOfCharacters << std::endl;
-    }
-    return false;
-  }
-
-  for( unsigned int index = 0u; index < data.numberOfLineInfo; ++index )
-  {
-    const BidirectionalLineInfoRun& run = logicalModel->mBidirectionalLineInfo[index];
-    const BidiLineData& bidiLineData = data.bidiLineData[index];
-
-    if( bidiLineData.characterIndex != run.characterRun.characterIndex )
-    {
-      std::cout << "  bidi line : " << index << ", index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << std::endl;
-      std::cout << "                      expected index : " << bidiLineData.characterIndex << ", num chars : " << bidiLineData.numberOfCharacters << std::endl;
-      return false;
-    }
-    if( bidiLineData.numberOfCharacters != run.characterRun.numberOfCharacters )
-    {
-      std::cout << "  bidi line : " << index << ", index : " << run.characterRun.characterIndex << ", num chars : " << run.characterRun.numberOfCharacters << std::endl;
-      std::cout << "                      expected index : " << bidiLineData.characterIndex << ", num chars : " << bidiLineData.numberOfCharacters << std::endl;
-      return false;
-    }
-
-    for( unsigned int i = 0u; i < run.characterRun.numberOfCharacters; ++i )
-    {
-      if( bidiLineData.visualToLogical[i] != run.visualToLogicalMap[i] )
-      {
-        std::cout << "           v2l : ";
-        for( unsigned int i = 0u; i < run.characterRun.numberOfCharacters; ++i )
-        {
-          std::cout << run.visualToLogicalMap[i] << " ";
-        }
-        std::cout << std::endl;
-        std::cout << "  expected v2l : ";
-        for( unsigned int i = 0u; i < run.characterRun.numberOfCharacters; ++i )
-        {
-          std::cout << bidiLineData.visualToLogical[i] << " ";
-        }
-        std::cout << std::endl;
-
-        return false;
-      }
-    }
-  }
-
-  return true;
-}
-
 bool GetMirroredTextTest( const GetMirroredTextData& data )
 {
   // 1) Create the model.
-  LogicalModelPtr logicalModel = LogicalModel::New();
-  VisualModelPtr visualModel = VisualModel::New();
+  ModelPtr textModel;
+  MetricsPtr metrics;
   Size textArea(100.f, 60.f);
   Size layoutSize;
 
   // Create the model.
+  const Vector<FontDescriptionRun> fontDescriptions;
+  const LayoutOptions options;
   CreateTextModel( data.text,
                    textArea,
+                   fontDescriptions,
+                   options,
                    layoutSize,
-                   logicalModel,
-                   visualModel );
+                   textModel,
+                   metrics,
+                   false );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   // 2) Call the GetMirroredText() function for the whole text
   Vector<Character> mirroredText;
@@ -376,25 +257,36 @@ bool GetMirroredTextTest( const GetMirroredTextData& data )
 bool GetCharactersDirectionTest( const GetCharactersDirectionData& data )
 {
   // 1) Create the model.
-  LogicalModelPtr logicalModel = LogicalModel::New();
-  VisualModelPtr visualModel = VisualModel::New();
+  ModelPtr textModel;
+  MetricsPtr metrics;
   Size textArea(100.f, 60.f);
   Size layoutSize;
 
   // Create the model.
+  const Vector<FontDescriptionRun> fontDescriptions;
+  const LayoutOptions options;
   CreateTextModel( data.text,
                    textArea,
+                   fontDescriptions,
+                   options,
                    layoutSize,
-                   logicalModel,
-                   visualModel );
+                   textModel,
+                   metrics,
+                   data.markupProcessorEnabled );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo;
 
   // 2) Clear the direction info data.
   Vector<CharacterDirection>& directions = logicalModel->mCharacterDirections;
 
-  directions.Erase( directions.Begin() + data.startIndex,
-                    directions.Begin() + data.startIndex + data.numberOfCharacters );
+  if( directions.Count() >= data.startIndex + data.numberOfCharacters )
+  {
+    directions.Erase( directions.Begin() + data.startIndex,
+                      directions.Begin() + data.startIndex + data.numberOfCharacters );
+  }
 
   // 3) Call GetCharactersDirection() function.
 
@@ -421,7 +313,6 @@ bool GetCharactersDirectionTest( const GetCharactersDirectionData& data )
 
 int UtcDaliSetBidirectionalInfo(void)
 {
-  ToolkitTestApplication application;
   tet_infoline(" UtcDaliSetBidirectionalInfo");
 
   unsigned int indices01[] = {};
@@ -556,6 +447,7 @@ int UtcDaliSetBidirectionalInfo(void)
 
   for( unsigned int index = 0u; index < numberOfTests; ++index )
   {
+    ToolkitTestApplication application;
     if( !SetBidirectionalInfoTest( data[index] ) )
     {
       tet_result(TET_FAIL);
@@ -566,181 +458,8 @@ int UtcDaliSetBidirectionalInfo(void)
   END_TEST;
 }
 
-int UtcDaliReorderLines(void)
-{
-  ToolkitTestApplication application;
-  tet_infoline(" UtcDaliSetBidirectionalInfo");
-
-  unsigned int visualToLogical0301[] = { 0u, 1u, 2u, 3u, 4u, 5u, 9u, 8u, 7u, 6u, 10u };
-  unsigned int visualToLogical0302[] = { 3u, 2u, 1u, 0u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
-  unsigned int visualToLogical0303[] = { 0u, 1u, 2u, 3u, 4u };
-  unsigned int visualToLogical0304[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0305[] = { 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0306[] = { 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0307[] = { 13u, 8u, 9u, 10u, 11u, 12u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0308[] = { 5u, 0u, 1u, 2u, 3u, 4u };
-  unsigned int visualToLogical0309[] = { 0u, 1u, 2u, 3u, 4u, 5u, 9u, 8u, 7u, 6u, 10u };
-  unsigned int visualToLogical0310[] = { 3u, 2u, 1u, 0u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
-  unsigned int visualToLogical0311[] = { 0u, 1u, 2u, 3u, 4u };
-  unsigned int visualToLogical0312[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0313[] = { 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0314[] = { 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0315[] = { 13u, 8u, 9u, 10u, 11u, 12u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
-  unsigned int visualToLogical0316[] = { 0u, 1u, 2u, 3u, 4u };
-
-  BidiLineData bidiLine01[] = {};
-  BidiLineData bidiLine02[] = {};
-  BidiLineData bidiLine03[] = {
-    {
-      17u,
-      11u,
-      visualToLogical0301
-    },
-    {
-      28u,
-      11u,
-      visualToLogical0302
-    },
-    {
-      39u,
-      5u,
-      visualToLogical0303
-    },
-    {
-      44u,
-      13u,
-      visualToLogical0304
-    },
-    {
-      57u,
-      11u,
-      visualToLogical0305
-    },
-    {
-      68u,
-      10u,
-      visualToLogical0306
-    },
-    {
-      78u,
-      14u,
-      visualToLogical0307
-    },
-    {
-      92u,
-      6u,
-      visualToLogical0308
-    },
-    {
-      115u,
-      11u,
-      visualToLogical0309
-    },
-    {
-      126u,
-      11u,
-      visualToLogical0310
-    },
-    {
-      137u,
-      5u,
-      visualToLogical0311
-    },
-    {
-      142u,
-      13u,
-      visualToLogical0312
-    },
-    {
-      155u,
-      11u,
-      visualToLogical0313
-    },
-    {
-      166u,
-      10u,
-      visualToLogical0314
-    },
-    {
-      176u,
-      14u,
-      visualToLogical0315
-    },
-    {
-      190u,
-      5u,
-      visualToLogical0316
-    },
-  };
-
-  struct ReorderLinesData data[] =
-  {
-    {
-      "Zero characters.",
-      "",
-      0u,
-      0u,
-      0u,
-      bidiLine01
-    },
-    {
-      "Left to right text only.",
-      "Hello world demo\nhello world demo\nhello world demo.",
-      0u,
-      51u,
-      0u,
-      bidiLine02
-    },
-    {
-      "Bidirectional paragraphs.",
-      "Hello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world\nHello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world",
-      0u,
-      195u,
-      16u,
-      bidiLine03
-    },
-    {
-      "Bidirectional paragraphs. Update initial paragraphs.",
-      "Hello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world\nHello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world",
-      0u,
-      44u,
-      16u,
-      bidiLine03
-    },
-    {
-      "Bidirectional paragraphs. Update middle paragraphs.",
-      "Hello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world\nHello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world",
-      44u,
-      54u,
-      16u,
-      bidiLine03
-    },
-    {
-      "Bidirectional paragraphs. Update final paragraphs.",
-      "Hello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world\nHello world demo\nhello שלום עולם world demo\nשלום بالعالم עולם مرحبا שלום עולם بالعالم hello world",
-      142u,
-      53u,
-      16u,
-      bidiLine03
-    },
-  };
-  const unsigned int numberOfTests = 6u;
-
-  for( unsigned int index = 0u; index < numberOfTests; ++index )
-  {
-    if( !ReorderLinesTest( data[index] ) )
-    {
-      tet_result(TET_FAIL);
-    }
-  }
-
-  tet_result(TET_PASS);
-  END_TEST;
-}
-
 int UtcDaliGetMirroredText(void)
 {
-  ToolkitTestApplication application;
   tet_infoline(" UtcDaliGetMirroredText");
 
   struct GetMirroredTextData data[] =
@@ -812,6 +531,7 @@ int UtcDaliGetMirroredText(void)
 
   for( unsigned int index = 0u; index < numberOfTests; ++index )
   {
+    ToolkitTestApplication application;
     if( !GetMirroredTextTest( data[index] ) )
     {
       tet_result(TET_FAIL);
@@ -824,7 +544,6 @@ int UtcDaliGetMirroredText(void)
 
 int UtcDaliGetCharactersDirection(void)
 {
-  ToolkitTestApplication application;
   tet_infoline(" UtcDaliGetCharactersDirection");
 
   bool directions01[] = {};
@@ -867,6 +586,11 @@ int UtcDaliGetCharactersDirection(void)
     true,  true,  true,  true,  true,  true,  true,  true,  true,  true,
     true,  true,  false, false, false, false, false };
 
+    bool directions06[] = {
+    true,  true,  true,  true,  true,  true,  true,  true,  true, true,
+    false, false, false, false, false, false, false, false, false, false,
+    false, false, false, false, false, false };
+
   struct GetCharactersDirectionData data[] =
   {
     {
@@ -874,28 +598,32 @@ int UtcDaliGetCharactersDirection(void)
       "",
       0u,
       0u,
-      directions01
+      directions01,
+      false
     },
     {
       "Left to right characters only",
       "Hello world\nhello world demo",
       0u,
       28u,
-      directions02
+      directions02,
+      false
     },
     {
       "Right to left characters only",
       "שלום עולם\nשלום עולם",
       0u,
       19u,
-      directions03
+      directions03,
+      false
     },
     {
       "Mix of bidirectional text",
       "Hello world\nhello world שלום עולם\nשלום עולם hello world",
       0u,
       55u,
-      directions04
+      directions04,
+      false
     },
     {
       "Mix of bidirectional text. With more paragraphs.",
@@ -903,7 +631,8 @@ int UtcDaliGetCharactersDirection(void)
       " مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
       0u,
       227u,
-      directions05
+      directions05,
+      false
     },
     {
       "Mix of bidirectional text. With more paragraphs. Update first paragraph.",
@@ -911,7 +640,8 @@ int UtcDaliGetCharactersDirection(void)
       " مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
       0u,
       17u,
-      directions05
+      directions05,
+      false
     },
     {
       "Mix of bidirectional text. With more paragraphs. Update from character 29",
@@ -919,7 +649,8 @@ int UtcDaliGetCharactersDirection(void)
       " مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
       29u,
       134u,
-      directions05
+      directions05,
+      false
     },
     {
       "Mix of bidirectional text. With more paragraphs. Update from character 163",
@@ -927,13 +658,23 @@ int UtcDaliGetCharactersDirection(void)
       " مرحبا بالعالم שלום עולם hello world hello world\nبالعالم שלום hello world demo עולם\nשלום مرحبا بالعالم עולם hello",
       163u,
       35u,
-      directions05
+      directions05,
+      false
+    },
+    {
+      "Mix of bidirectional text. With brackets and LRM",
+      "שלום עולם &lrm;(hello)[world]&lrm;",
+      0u,
+      26u,
+      directions06,
+      true
     }
   };
-  const unsigned int numberOfTests = 8u;
+  const unsigned int numberOfTests = 9u;
 
   for( unsigned int index = 0u; index < numberOfTests; ++index )
   {
+    ToolkitTestApplication application;
     if( !GetCharactersDirectionTest( data[index] ) )
     {
       tet_result(TET_FAIL);