Fixing Bug: Caret is too big with LineSpacing
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-LogicalModel.cpp
index 833b546..8b15ad3 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -104,8 +104,7 @@ struct GetLogicalCursorIndexData
 bool CreateParagraphTest( const CreateParagraphData& data )
 {
   // 1) Create the model.
-  LogicalModelPtr logicalModel;
-  VisualModelPtr visualModel;
+  ModelPtr textModel;
   MetricsPtr metrics;
   Size textArea(100.f, 60.f);
   Size layoutSize;
@@ -117,10 +116,16 @@ bool CreateParagraphTest( const CreateParagraphData& data )
                    fontDescriptionRuns,
                    options,
                    layoutSize,
-                   logicalModel,
-                   visualModel,
+                   textModel,
                    metrics,
-                   false );
+                   false,
+                   LineWrap::WORD,
+                   false,
+                   Toolkit::DevelText::EllipsisPosition::END,
+                   0.f );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   // 2) Clear the paragraphs.
   Vector<ParagraphRun>& paragraphs = logicalModel->mParagraphInfo;
@@ -165,8 +170,7 @@ bool CreateParagraphTest( const CreateParagraphData& data )
 bool FindParagraphTest( const FindParagraphData& data )
 {
   // 1) Create the model.
-  LogicalModelPtr logicalModel;
-  VisualModelPtr visualModel;
+  ModelPtr textModel;
   MetricsPtr metrics;
   Size textArea(100.f, 60.f);
   Size layoutSize;
@@ -178,10 +182,16 @@ bool FindParagraphTest( const FindParagraphData& data )
                    fontDescriptionRuns,
                    options,
                    layoutSize,
-                   logicalModel,
-                   visualModel,
+                   textModel,
                    metrics,
-                   false );
+                   false,
+                   LineWrap::WORD,
+                   false,
+                   Toolkit::DevelText::EllipsisPosition::END,
+                   0.f );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   // 2) Find the paragraphs.
   Vector<ParagraphRunIndex> paragraphs;
@@ -214,8 +224,7 @@ bool FetchBidirectionalLineInfoTest( const FetchBidirectionalLineInfoData& data
 {
   std::cout << "  testing : " << data.description << std::endl;
   // Create the model.
-  LogicalModelPtr logicalModel;
-  VisualModelPtr visualModel;
+  ModelPtr textModel;
   MetricsPtr metrics;
   Size textArea( 100.f, 300.f );
   Size layoutSize;
@@ -228,10 +237,16 @@ bool FetchBidirectionalLineInfoTest( const FetchBidirectionalLineInfoData& data
                    fontDescriptions,
                    options,
                    layoutSize,
-                   logicalModel,
-                   visualModel,
+                   textModel,
                    metrics,
-                   false );
+                   false,
+                   LineWrap::WORD,
+                   false,
+                   Toolkit::DevelText::EllipsisPosition::END,
+                   0.f );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   for( unsigned int index = 0; index < data.numberOfTests; ++index )
   {
@@ -260,8 +275,7 @@ bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data )
 {
   std::cout << "  testing : " << data.description << std::endl;
   // Create the model.
-  LogicalModelPtr logicalModel;
-  VisualModelPtr visualModel;
+  ModelPtr textModel;
   MetricsPtr metrics;
   Size layoutSize;
 
@@ -273,10 +287,16 @@ bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data )
                    fontDescriptions,
                    options,
                    layoutSize,
-                   logicalModel,
-                   visualModel,
+                   textModel,
                    metrics,
-                   false );
+                   false,
+                   LineWrap::WORD,
+                   false,
+                   Toolkit::DevelText::EllipsisPosition::END,
+                   0.f );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
   {
@@ -301,7 +321,7 @@ bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data )
 
 bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data )
 {
-  std::cout << "  testing : " << data.description << std::endl;
+  tet_printf( "  testing : %s\n", data.description.c_str() );
 
   // Load some fonts.
   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
@@ -315,8 +335,7 @@ bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data )
   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" );
 
   // Create the model.
-  LogicalModelPtr logicalModel;
-  VisualModelPtr visualModel;
+  ModelPtr textModel;
   MetricsPtr metrics;
   Size layoutSize;
 
@@ -335,27 +354,35 @@ bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data )
                    fontDescriptionRuns,
                    options,
                    layoutSize,
-                   logicalModel,
-                   visualModel,
+                   textModel,
                    metrics,
-                   false );
+                   false,
+                   LineWrap::WORD,
+                   false,
+                   Toolkit::DevelText::EllipsisPosition::END,
+                   0.f );
+
+  LogicalModelPtr logicalModel = textModel->mLogicalModel;
+  VisualModelPtr visualModel = textModel->mVisualModel;
 
   for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
   {
     const bool fetched = logicalModel->FetchBidirectionalLineInfo( data.characterIndex[index] );
+    tet_printf("  fetched %d, line index %d, expected line index %d\n", fetched, logicalModel->mBidirectionalLineIndex, data.cachedBidiLine[index] );
 
     if( logicalModel->mBidirectionalLineIndex != data.cachedBidiLine[index] )
     {
-      std::cout << "  test : " << index << ", different cached line index : " << logicalModel->mBidirectionalLineIndex << ", expected : " << data.cachedBidiLine[index] << std::endl;
+      tet_printf( "  test : %d, different cached line index : %d, expected : %d\n", index, logicalModel->mBidirectionalLineIndex, data.cachedBidiLine[index] );
       return false;
     }
 
     const CharacterIndex visualCharacterIndex = data.visualCursorIndex[index];
     const CharacterIndex logicalCursorIndex = fetched ? logicalModel->GetLogicalCursorIndex( visualCharacterIndex ) : visualCharacterIndex;
+    tet_printf("  visual index %d, logical index %d\n", visualCharacterIndex, logicalCursorIndex);
 
     if( logicalCursorIndex != data.logicalCursorIndex[index] )
     {
-      std::cout << "  test : " << index << ", visual index : " << visualCharacterIndex << ", different logical cursor index : " << logicalCursorIndex << ", expected : " << data.logicalCursorIndex[index] << std::endl;
+      tet_printf( "  test : %d, visual index : %d, different logical cursor index :%d, expected : %d\n", index, visualCharacterIndex, logicalCursorIndex, data.logicalCursorIndex[index] );
       return false;
     }
   }
@@ -1053,18 +1080,19 @@ int UtcDaliGetLogicalCursorIndex(void)
   unsigned int bidirectionalLineIndex05[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
                                               0u, 0u, 0u, 0u };
 
-// LO      ק  ר  א  ט  ו  ן  ם  פ  ש  ד  ג
-//        0  1  2  3  4  5  6  7  8  9  10 11
-// VO      ג  ד  ש  פ  ם  ן  ו  ט  א  ר  ק
+// LO      ק  ר  א  ט  ו  ן  ם  פ  ש  ד  ג  כ
+//        0  1  2  3  4  5  6  7  8  9  10 11 12
+// VO      כ  ג  ד  ש  פ  ם  ן  ו  ט  א  ר  ק
+
+// LO      ע  י  ח  ל
+//       12 13 14 15 16
+// VO      ל  ח  י  ע
 
-// LO      כ  ע  י  ח  ל
-//       11 12 13 14 15 16
-// VO      ל  ח  י  ע  כ
 
   // Set a known font description
   FontDescriptionRun fontDescriptionRun0601;
   fontDescriptionRun0601.characterRun.characterIndex = 0u;
-  fontDescriptionRun0601.characterRun.numberOfCharacters = 14u;
+  fontDescriptionRun0601.characterRun.numberOfCharacters = 16u;
   fontDescriptionRun0601.familyLength = fontFamilyHebrew.size();
   fontDescriptionRun0601.familyName = new char[fontDescriptionRun0601.familyLength];
   memcpy( fontDescriptionRun0601.familyName, fontFamilyHebrew.c_str(), fontDescriptionRun0601.familyLength );
@@ -1077,17 +1105,17 @@ int UtcDaliGetLogicalCursorIndex(void)
   Vector<FontDescriptionRun> fontDescriptionRuns06;
   fontDescriptionRuns06.PushBack( fontDescriptionRun0601 );
 
-  unsigned int  visualIndex06[] = {  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u, 10u, 11u,
-                                    11u, 12u, 13u, 14u, 15u, 16u };
+  unsigned int  visualIndex06[] = {  0u,  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u, 10u, 11u, 12u,
+                                    12u, 13u, 14u, 15u, 16u };
 
-  unsigned int characterIndex06[] = {  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,
-                                      12u, 12u, 12u, 12u, 12u, 12u };
+  unsigned int characterIndex06[] = {  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,  0u,
+                                      12u, 12u, 12u, 12u, 12u };
 
-  unsigned int logicalIndex06[] = { 11u, 10u,  9u,  8u,  7u,  6u,  5u,  4u,  3u,  2u,  1u,
-                                    13u, 16u, 15u, 14u, 13u, 12u };
+  unsigned int logicalIndex06[] = { 12u, 11u, 10u,  9u,  8u,  7u,  6u,  5u,  4u,  3u,  2u,  1u, 0u,
+                                    16u, 15u, 14u, 13u, 12u };
 
-  unsigned int bidirectionalLineIndex06[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
-                                              1u, 1u, 1u, 1u, 1u, 1u };
+  unsigned int bidirectionalLineIndex06[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+                                              1u, 1u, 1u, 1u, 1u, };
 
   struct GetLogicalCursorIndexData data[] =
   {
@@ -1157,7 +1185,7 @@ int UtcDaliGetLogicalCursorIndex(void)
       Size( 100.f, 300.f ),
       1u,
       fontDescriptionRuns06.Begin(),
-      15u,
+      18u,
       visualIndex06,
       characterIndex06,
       logicalIndex06,
@@ -1171,6 +1199,7 @@ int UtcDaliGetLogicalCursorIndex(void)
     ToolkitTestApplication application;
     if( !GetLogicalCursorIndexTest( data[index] ) )
     {
+      tet_printf("Test %d failed : [%s]\n", index, data[index].description.c_str());
       tet_result(TET_FAIL);
     }
   }