[dali_1.0.14] Merge branch 'tizen'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextView-Relayout-Utilities.cpp
index be24681..c556e08 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <iostream>
 
@@ -53,14 +54,14 @@ bool TestEqual( float x, float y )
 
 //////////////////////////////////////////////////////////////////
 
-struct CalculateSubLineLayoutTest
+struct CalculateLineLayoutTest
 {
   std::string description;
-  std::string inputLine;
+  std::string inputParagraph;
   float parentWidth;
-  std::size_t groupIndex;
   std::size_t wordIndex;
   std::size_t characterIndex;
+  std::size_t characterParagraphIndex;
   TextViewRelayout::HorizontalWrapType splitPolicy;
   float shrinkFactor;
 
@@ -69,13 +70,13 @@ struct CalculateSubLineLayoutTest
   float resultMaxAscender;
 };
 
-bool TestCalculateSubLineLayout( const CalculateSubLineLayoutTest& test,  const char* location )
+bool TestCalculateLineLayout( const CalculateLineLayoutTest& test,  const char* location )
 {
   tet_printf( "%s", test.description.c_str() );
 
   // Create styled text.
   MarkupProcessor::StyledTextArray inputStyledText;
-  MarkupProcessor::GetStyledTextArray( test.inputLine, inputStyledText, true );
+  MarkupProcessor::GetStyledTextArray( test.inputParagraph, inputStyledText, true );
 
   // Create styled text layout info.
   Toolkit::Internal::TextView::RelayoutData relayoutData;
@@ -86,25 +87,26 @@ bool TestCalculateSubLineLayout( const CalculateSubLineLayoutTest& test,  const
   // Prepare input parameters and the result structure and call the function to be tested.
 
   // Creaqte indices.
-  TextViewProcessor::TextInfoIndices indices( 0, test.groupIndex, test.wordIndex, test.characterIndex );
+  TextViewProcessor::TextInfoIndices indices( 0u, test.wordIndex, test.characterIndex );
+  indices.mCharacterParagraphIndex = test.characterParagraphIndex;
 
-  // Get the input line.
-  TextViewProcessor::LineLayoutInfo inputLineLayout;
+  // Get the input paragraph.
+  TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout;
 
-  if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
+  if( !relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.empty() )
   {
-    inputLineLayout = *relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin();
+    inputParagraphLayout = *relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.begin();
   }
 
   // Result struct.
-  TextViewRelayout::SubLineLayoutInfo resultLayoutInfo;
+  TextViewRelayout::LineLayoutInfo resultLayoutInfo;
 
-  CalculateSubLineLayout( test.parentWidth,
-                          indices,
-                          inputLineLayout,
-                          test.splitPolicy,
-                          test.shrinkFactor,
-                          resultLayoutInfo  );
+  CalculateLineLayout( test.parentWidth,
+                       indices,
+                       inputParagraphLayout,
+                       test.splitPolicy,
+                       test.shrinkFactor,
+                       resultLayoutInfo  );
 
   // Check results.
   if( !TestEqual( test.resultLineLength, resultLayoutInfo.mLineLength ) )
@@ -234,18 +236,17 @@ int UtcDaliTextViewDefaultConstructorDestructor_RU(void)
   TextViewRelayout::RelayoutParameters relayoutParameters;
 
   DALI_TEST_EQUALS( relayoutParameters.mPositionOffset, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
-  DALI_TEST_EQUALS( relayoutParameters.mLineSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+  DALI_TEST_EQUALS( relayoutParameters.mParagraphSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
   DALI_TEST_EQUALS( relayoutParameters.mWordSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
   DALI_TEST_EQUALS( relayoutParameters.mCharacterSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
-  DALI_TEST_EQUALS( relayoutParameters.mIndices.mLineIndex, 0u, TEST_LOCATION );
-  DALI_TEST_EQUALS( relayoutParameters.mIndices.mGroupIndex, 0u, TEST_LOCATION );
+  DALI_TEST_EQUALS( relayoutParameters.mIndices.mParagraphIndex, 0u, TEST_LOCATION );
   DALI_TEST_EQUALS( relayoutParameters.mIndices.mWordIndex, 0u, TEST_LOCATION );
   DALI_TEST_EQUALS( relayoutParameters.mIndices.mCharacterIndex, 0u, TEST_LOCATION );
   DALI_TEST_EQUALS( relayoutParameters.mCharacterGlobalIndex, 0u, TEST_LOCATION );
   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacter );
   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacterOfWord );
   DALI_TEST_CHECK( !relayoutParameters.mIsNewLine );
-  DALI_TEST_CHECK( !relayoutParameters.mIsNewLineCharacter );
+  DALI_TEST_CHECK( !relayoutParameters.mIsNewParagraphCharacter );
   DALI_TEST_CHECK( !relayoutParameters.mIsWhiteSpace );
   DALI_TEST_CHECK( !relayoutParameters.mIsVisible );
 
@@ -306,30 +307,30 @@ int UtcDaliTextViewDefaultConstructorDestructor_RU(void)
   DALI_TEST_EQUALS( textUnderlineStatus.mLineGlobalIndex, 0u, TEST_LOCATION );
   DALI_TEST_CHECK( !textUnderlineStatus.mCurrentUnderlineStatus );
 
-  // Test SubLineLayoutInfo defaults
-  TextViewRelayout::SubLineLayoutInfo subLineLayoutInfo;
+  // Test LineLayoutInfo defaults
+  TextViewRelayout::LineLayoutInfo lineLayoutInfo;
 
-  DALI_TEST_EQUALS( subLineLayoutInfo.mLineLength, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
-  DALI_TEST_EQUALS( subLineLayoutInfo.mMaxCharHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
-  DALI_TEST_EQUALS( subLineLayoutInfo.mMaxAscender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineLayoutInfo.mLineLength, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineLayoutInfo.mMaxCharHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+  DALI_TEST_EQUALS( lineLayoutInfo.mMaxAscender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
   END_TEST;
 }
 
-int UtcDaliTextViewCalculateSubLineLayout(void)
+int UtcDaliTextViewCalculateLineLayout(void)
 {
   ToolkitTestApplication application;
 
-  tet_infoline("UtcDaliTextViewCalculateSubLineLayout : ");
+  tet_infoline("UtcDaliTextViewCalculateLineLayout : ");
 
-  struct CalculateSubLineLayoutTest calculateSubLineLayoutTest[] =
+  struct CalculateLineLayoutTest calculateLineLayoutTest[] =
   {
     //WrapByCharacter
     {
-      "The line is wraped by character. All characters have the same size.",
-      "Hello world", // input line
+      "The paragraph is wraped by character. All characters have the same size.",
+      "Hello world", // input paragraph
       100.f,         // parent width
+      0,             // indices
       0,
-      0,              // indices
       0,
       TextViewRelayout::WrapByCharacter, // split policy
       1.f,
@@ -339,12 +340,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by character. There are characters with different sizes.",
-      "Hello <font size='14'>world</font>", // input line
+      "The paragraph is wraped by character. There are characters with different sizes.",
+      "Hello <font size='14'>world</font>", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices
       0,
+      0,
       TextViewRelayout::WrapByCharacter, // split policy
       1.f,
       // results
@@ -353,12 +354,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       11.949220f  // max ascender
     },
     {
-      "The line is wraped by character. There are characters with different sizes. It calculates the layout for the second line.",
-      "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input line
+      "The paragraph is wraped by character. There are characters with different sizes. It calculates the layout for the second line.",
+      "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input paragraph
       100.f,         // parent width
-      0,
       2,              // indices. The third character of the third word starts in a new line.
       2,
+      8,
       TextViewRelayout::WrapByCharacter, // split policy
       1.f,
       // results
@@ -367,12 +368,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by character. There are characters with different sizes. It calculates the layout for the third line.",
-      "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input line
+      "The paragraph is wraped by character. There are characters with different sizes. It calculates the layout for the third line.",
+      "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input paragraph
       100.f,         // parent width
-      0,
       4,              // indices. The fifth character of the fifth word starts in a new line.
       4,
+      16,
       TextViewRelayout::WrapByCharacter, // split policy
       1.f,
       // results
@@ -383,12 +384,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
 
     //WrapByWord
     {
-      "The line is wraped by word. All characters have the same size.",
-      "Hello world", // input line
+      "The paragraph is wraped by word. All characters have the same size.",
+      "Hello world", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices. It shouldn't use the index character so 9999999 shouldn't make it crash.
       9999999,
+      9999999,
       TextViewRelayout::WrapByWord, // split policy
       1.f,
       // results
@@ -397,12 +398,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by word. There are characters with different sizes.",
-      "Hell<font size='14'>o</font> world", // input line
+      "The paragraph is wraped by word. There are characters with different sizes.",
+      "Hell<font size='14'>o</font> world", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices.
       0,
+      0,
       TextViewRelayout::WrapByWord, // split policy
       1.f,
       // results
@@ -411,12 +412,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       11.949220f  // max ascender
     },
     {
-      "The line is wraped by word. There are characters with different sizes. It calculates the layout for the second line.",
-      "Hello <font size='14'>wo</font>rld <font size='16'>hello world</font>", // input line
+      "The paragraph is wraped by word. There are characters with different sizes. It calculates the layout for the second line.",
+      "Hello <font size='14'>wo</font>rld <font size='16'>hello world</font>", // input paragraph
       100.f,         // parent width
-      0,
       2,              // indices. The third word starts in a new line.
       0,
+      6,
       TextViewRelayout::WrapByWord, // split policy
       1.f,
       // results
@@ -425,12 +426,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       11.949220f  // max ascender
     },
     {
-      "The line is wraped by word. The word doen't fit.",
-      "Hello world", // input line
+      "The paragraph is wraped by word. The word doen't fit.",
+      "Hello world", // input paragraph
       40.f,          // parent width
-      0,
       0,              // indices. The third word starts in a new line.
       0,
+      0,
       TextViewRelayout::WrapByWord, // split policy
       1.f,
       // results
@@ -441,12 +442,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
 
     //WrapByWordAndSplit
     {
-      "The line is wraped by word and by character. All characters have the same size. There is not a long word.",
-      "Hello world hello world", // input line
+      "The paragraph is wraped by word and by character. All characters have the same size. There is not a long word.",
+      "Hello world hello world", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices.
       0,
+      0,
       TextViewRelayout::WrapByWordAndSplit, // split policy
       1.f,
       // results
@@ -455,12 +456,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by word and by character. All characters have the same size. There is a long word.",
-      "Helloooooooo world", // input line
+      "The paragraph is wraped by word and by character. All characters have the same size. There is a long word.",
+      "Helloooooooo world", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices.
       0,
+      0,
       TextViewRelayout::WrapByWordAndSplit, // split policy
       1.f,
       // results
@@ -469,12 +470,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by word and by character. There are characters with different sizes. There is a long word. It calculates the layout for the second line.",
-      "Helloooooooo <font size='14'>world</font>", // input line
+      "The paragraph is wraped by word and by character. There are characters with different sizes. There is a long word. It calculates the layout for the second line.",
+      "Helloooooooo <font size='14'>world</font>", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices.
       8,
+      8,
       TextViewRelayout::WrapByWordAndSplit, // split policy
       1.f,
       // results
@@ -483,12 +484,12 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by word and by character. There are characters with different sizes. There is a shrink factor.",
-      "Helloooooooo<font size='14'> world</font>", // input line
+      "The paragraph is wraped by word and by character. There are characters with different sizes. There is a shrink factor.",
+      "Helloooooooo<font size='14'> world</font>", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices.
       8,
+      8,
       TextViewRelayout::WrapByWordAndSplit, // split policy
       0.7f,
       // results
@@ -497,15 +498,15 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       7.169531f  // max ascender
     },
 
-    //WrapByLineAndSplit
+    //WrapByParagraphCharacterAndSplit
     {
-      "The line is wraped by end of line and by character. All characters have the same size.",
-      "Hello world", // input line
+      "The paragraph is wraped by end of paragraph and by character. All characters have the same size.",
+      "Hello world", // input paragraph
       100.f,         // parent width
-      0,
       0,              // indices
       0,
-      TextViewRelayout::WrapByLineAndSplit, // split policy
+      0,
+      TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
       1.f,
       // results
       91.041672f, // line length. (only fits 8 characters 8x11.38)
@@ -513,13 +514,13 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line fits in the width.",
-      "Hello", // input line
+      "The paragraph fits in the width.",
+      "Hello", // input paragraph
       100.f,         // parent width
-      0,
       0,             // indices
       0,
-      TextViewRelayout::WrapByLineAndSplit, // split policy
+      0,
+      TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
       1.f,
       // results
       56.901047f, // line length. (only fits 5 characters 5x11.38)
@@ -527,13 +528,13 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
       10.242188f  // max ascender
     },
     {
-      "The line is wraped by end of line and by character. All characters have the same size. It calculates the layout for the second line.",
-      "Hello world, hello world", // input line
+      "The paragraph is wraped by end of paragraph and by character. All characters have the same size. It calculates the layout for the second line.",
+      "Hello world, hello world", // input paragraph
       100.f,         // parent width
-      0,
       2,             // indices
       2,
-      TextViewRelayout::WrapByLineAndSplit, // split policy
+      8,
+      TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
       1.f,
       // results
       91.041672f, // line length. (only fits 8 characters 8x11.38)
@@ -545,9 +546,9 @@ int UtcDaliTextViewCalculateSubLineLayout(void)
 
   for( std::size_t index = 0; index < numberOfTests; ++index )
   {
-    const CalculateSubLineLayoutTest& test = calculateSubLineLayoutTest[index];
+    const CalculateLineLayoutTest& test = calculateLineLayoutTest[index];
 
-    if( !TestCalculateSubLineLayout( test, TEST_LOCATION ) )
+    if( !TestCalculateLineLayout( test, TEST_LOCATION ) )
     {
       tet_result( TET_FAIL );
     }