2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 // Internal headers are allowed here
25 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
26 #include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
27 #include <dali-toolkit/internal/controls/text-view/text-view-line-processor.h>
28 #include <dali-toolkit/internal/controls/text-view/text-view-word-processor.h>
29 #include <dali-toolkit/internal/controls/text-view/relayout-utilities.h>
32 using namespace Dali::Toolkit;
33 using namespace Dali::Toolkit::Internal;
35 void dali_text_view_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_text_view_cleanup(void)
42 test_return_value = TET_PASS;
49 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
50 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
52 // Data structures used to create an 'experiment' in TET cases
56 std::string description;
59 std::string firstResult;
60 std::string lastResult;
65 std::string description;
67 std::size_t wordIndex;
68 std::size_t characterIndex;
69 float lineHeightOffset;
70 std::string firstResult;
71 std::string lastResult;
76 std::string description;
77 std::string inputFirst;
78 std::string inputLast;
84 std::string description;
85 std::string inputFirst;
86 std::string inputLast;
87 float lineHeightOffset;
91 struct RemoveCharactersFromWordTest
93 std::string description;
96 std::size_t numberOfCharacters;
100 struct RemoveWordsFromLineTest
102 std::string description;
104 std::size_t wordIndex;
105 std::size_t numberOfWords;
106 float lineHeightOffset;
110 enum UpdateTextInfoOperation
117 struct UpdateTextInfoTest
119 std::string description;
120 UpdateTextInfoOperation operation;
122 std::size_t position;
123 std::size_t numberOfCharacters;
124 std::string inputText;
125 float lineHeightOffset;
129 // Useful Print functions when something goes wrong.
131 void Print( const TextViewProcessor::CharacterLayoutInfo& character )
133 std::cout << " height : " << character.mHeight << std::endl;
134 std::cout << " advance : " << character.mAdvance << std::endl;
135 std::cout << " bearing : " << character.mBearing << std::endl;
136 std::cout << " mPosition : " << character.mPosition << std::endl;
137 std::cout << " mSize : " << character.mSize << std::endl;
138 std::cout << " mAscender : " << character.mAscender << std::endl;
140 TextActor textActor = TextActor::DownCast( character.mGlyphActor );
143 std::cout << "[" << textActor.GetText() << "]";
147 std::cout << "{" << character.mStyledText.mText.GetText() << "}";
151 void Print( const TextViewProcessor::WordLayoutInfo& word )
154 std::cout << " mSize : " << word.mSize << std::endl;
155 std::cout << " mAscender : " << word.mAscender << std::endl;
156 std::cout << " mType : " << word.mType << std::endl;
157 std::cout << "mNumberOfCharacters : " << word.mCharactersLayoutInfo.size() << std::endl;
159 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it = word.mCharactersLayoutInfo.begin(), endIt = word.mCharactersLayoutInfo.end(); it != endIt; ++it )
163 std::cout << "]"; std::cout << std::endl;
164 std::cout << "]"; std::cout << std::endl;
167 void Print( const TextViewProcessor::LineLayoutInfo& line )
170 std::cout << " mSize : " << line.mSize << std::endl;
171 std::cout << " mAscender : " << line.mAscender << std::endl;
172 std::cout << "mNumberOfCharacters : " << line.mNumberOfCharacters << std::endl;
173 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = line.mWordsLayoutInfo.begin(), endIt = line.mWordsLayoutInfo.end(); it != endIt; ++it )
177 std::cout << ">" << std::endl;
180 void Print( const TextViewProcessor::TextLayoutInfo& text )
183 for( TextViewProcessor::LineLayoutInfoContainer::const_iterator it = text.mLinesLayoutInfo.begin(), endIt = text.mLinesLayoutInfo.end(); it != endIt; ++it )
187 std::cout << "||" << std::endl;
190 std::string GetText( const TextViewProcessor::CharacterLayoutInfo& character )
192 return character.mStyledText.mText.GetText();
195 std::string GetText( const TextViewProcessor::WordLayoutInfo& word )
199 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it = word.mCharactersLayoutInfo.begin(), endIt = word.mCharactersLayoutInfo.end(); it != endIt; ++it )
201 text += GetText( *it );
207 std::string GetText( const TextViewProcessor::LineLayoutInfo& line )
211 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = line.mWordsLayoutInfo.begin(), endIt = line.mWordsLayoutInfo.end(); it != endIt; ++it )
213 text += GetText( *it );
219 // Test functions used to check if two data structures are equal.
221 bool TestEqual( float x, float y )
223 return ( fabsf( x - y ) < 0.001f );
226 bool TestEqual( const TextViewProcessor::CharacterLayoutInfo& character1,
227 const TextViewProcessor::CharacterLayoutInfo& character2 )
229 if( !TestEqual( character1.mHeight, character2.mHeight ) )
233 if( !TestEqual( character1.mAdvance, character2.mAdvance ) )
237 if( !TestEqual( character1.mBearing, character2.mBearing ) )
242 if( !TestEqual( character1.mPosition.x, character2.mPosition.x ) )
246 if( !TestEqual( character1.mPosition.y, character2.mPosition.y ) )
251 if( !TestEqual( character1.mSize.x, character2.mSize.x ) )
255 if( !TestEqual( character1.mSize.y, character2.mSize.y ) )
260 if( !TestEqual( character1.mAscender, character2.mAscender ) )
265 if( character1.mGlyphActor && !character2.mGlyphActor )
270 if( !character1.mGlyphActor && character2.mGlyphActor )
280 TextActor textActor1 = TextActor::DownCast( character1.mGlyphActor );
281 TextActor textActor2 = TextActor::DownCast( character2.mGlyphActor );
284 text1 = textActor1.GetText();
285 style1 = textActor1.GetTextStyle();
287 text2 = textActor2.GetText();
288 style2 = textActor2.GetTextStyle();
296 if( style1 != style2 )
301 text1 = character1.mStyledText.mText.GetText();
302 style1 = character1.mStyledText.mStyle;
304 text2 = character2.mStyledText.mText.GetText();
305 style2 = character2.mStyledText.mStyle;
312 if( style1 != style2 )
314 std::cout << " style1 : " << std::endl;
315 TextViewProcessor::dbgPrint( style1 );
317 std::cout << " style2 : " << std::endl;
318 TextViewProcessor::dbgPrint( style2 );
325 bool TestEqual( const TextViewProcessor::WordLayoutInfo& word1,
326 const TextViewProcessor::WordLayoutInfo& word2 )
328 if( !TestEqual( word1.mSize.x, word2.mSize.x ) )
332 if( !TestEqual( word1.mSize.y, word2.mSize.y ) )
337 if( !TestEqual( word1.mAscender, word2.mAscender ) )
342 if( word1.mType != word2.mType )
347 if( word1.mCharactersLayoutInfo.size() != word2.mCharactersLayoutInfo.size() )
352 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it1 = word1.mCharactersLayoutInfo.begin(), endIt1 = word1.mCharactersLayoutInfo.end(),
353 it2 = word2.mCharactersLayoutInfo.begin(), endIt2 = word2.mCharactersLayoutInfo.end();
354 ( it1 != endIt1 ) && ( it2 != endIt2 );
357 if( !TestEqual( *it1, *it2 ) )
366 bool TestEqual( const TextViewProcessor::LineLayoutInfo& line1,
367 const TextViewProcessor::LineLayoutInfo& line2 )
369 if( !TestEqual( line1.mSize.x, line2.mSize.x ) )
373 if( !TestEqual( line1.mSize.y, line2.mSize.y ) )
378 if( !TestEqual( line1.mAscender, line2.mAscender ) )
383 if( line1.mNumberOfCharacters != line2.mNumberOfCharacters )
388 if( line1.mWordsLayoutInfo.size() != line2.mWordsLayoutInfo.size() )
393 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it1 = line1.mWordsLayoutInfo.begin(), endIt1 = line1.mWordsLayoutInfo.end(),
394 it2 = line2.mWordsLayoutInfo.begin(), endIt2 = line2.mWordsLayoutInfo.end();
395 ( it1 != endIt1 ) && ( it2 != endIt2 );
398 if( !TestEqual( *it1, *it2 ) )
407 bool TestEqual( const TextViewProcessor::TextLayoutInfo& text1,
408 const TextViewProcessor::TextLayoutInfo& text2 )
410 if( !TestEqual( text1.mWholeTextSize.x, text2.mWholeTextSize.x ) )
414 if( !TestEqual( text1.mWholeTextSize.y, text2.mWholeTextSize.y ) )
419 if( !TestEqual( text1.mMaxWordWidth, text2.mMaxWordWidth ) )
424 if( text1.mNumberOfCharacters != text2.mNumberOfCharacters )
429 if( text1.mLinesLayoutInfo.size() != text2.mLinesLayoutInfo.size() )
434 for( TextViewProcessor::LineLayoutInfoContainer::const_iterator it1 = text1.mLinesLayoutInfo.begin(), endIt1 = text1.mLinesLayoutInfo.end(),
435 it2 = text2.mLinesLayoutInfo.begin(), endIt2 = text2.mLinesLayoutInfo.end();
436 ( it1 != endIt1 ) && ( it2 != endIt2 );
439 if( !TestEqual( *it1, *it2 ) )
449 * Splits the \e input word in two by the given \e position and checks the results with \e firstResult and \e lastResult.
451 * If the test fails it prints a short description and the line where this function was called.
453 * @param description Short description of the experiment. i.e. "Split the word from the beginning. (position 0)".
454 * @param input The input word.
455 * @param position Where to split the word.
456 * @param firstResult First part of the split word.
457 * @param lastResult Last part of the split word.
458 * @param location Where this function has been called.
460 * @return \e true if the experiment is successful. Otherwise returns \e false.
462 bool TestSplitWord( const std::string& description, const std::string& input, const size_t position, const std::string& firstResult, const std::string& lastResult, const char* location )
464 tet_printf( "%s\n", description.c_str() );
466 // Create layout info for the input word.
467 Toolkit::Internal::TextView::RelayoutData relayoutData;
468 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
470 MarkupProcessor::StyledTextArray inputStyledText;
471 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
473 TextViewProcessor::CreateTextInfo( inputStyledText,
474 DEFAULT_LAYOUT_PARAMETERS,
477 // Get the input word
478 TextViewProcessor::WordLayoutInfo inputWordLayout;
480 if( !inputLayout.mLinesLayoutInfo.empty() )
482 const TextViewProcessor::LineLayoutInfo& line( *inputLayout.mLinesLayoutInfo.begin() );
483 if( !line.mWordsLayoutInfo.empty() )
485 inputWordLayout = *( *inputLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
489 // Create layout info for the first part of the result (after split the word)
491 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
492 TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo );
494 MarkupProcessor::StyledTextArray firstResultStyledText;
495 MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true );
497 TextViewProcessor::CreateTextInfo( firstResultStyledText,
498 DEFAULT_LAYOUT_PARAMETERS,
501 // Get the first result word
502 TextViewProcessor::WordLayoutInfo firstResultWordLayout;
504 if( !firstResultLayout.mLinesLayoutInfo.empty() )
506 const TextViewProcessor::LineLayoutInfo& line( *firstResultLayout.mLinesLayoutInfo.begin() );
507 if( !line.mWordsLayoutInfo.empty() )
509 firstResultWordLayout = *( *firstResultLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
513 // Create layout info for the last part of the result (after split the word)
515 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
516 TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo );
518 MarkupProcessor::StyledTextArray lastResultStyledText;
519 MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true );
521 TextViewProcessor::CreateTextInfo( lastResultStyledText,
522 DEFAULT_LAYOUT_PARAMETERS,
525 // Get the last result word
526 TextViewProcessor::WordLayoutInfo lastResultWordLayout;
528 if( !lastResultLayout.mLinesLayoutInfo.empty() )
530 const TextViewProcessor::LineLayoutInfo& line( *lastResultLayout.mLinesLayoutInfo.begin() );
531 if( !line.mWordsLayoutInfo.empty() )
533 lastResultWordLayout = *( *lastResultLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
539 TextViewProcessor::WordLayoutInfo lastWordLayoutInfo;
543 lastWordLayoutInfo );
546 if( !TestEqual( inputWordLayout, firstResultWordLayout ) )
548 tet_printf( "Fail. different layout info. %s\n", location );
552 if( !TestEqual( lastWordLayoutInfo, lastResultWordLayout ) )
554 tet_printf( "Fail. different layout info. %s\n", location );
562 * Splits the \e input line in two by the given \e wordIndex and \e characterIndex and checks the results with \e firstResult and \e lastResult.
564 * If the test fails it prints a short description and the line where this function was called.
566 * @param description Short description of the experiment. i.e. "Split the line from the beginning. (wordIndex 0 and characterIndex 0)".
567 * @param input The input word.
568 * @param wordIndex Index to the word within the line where to split it.
569 * @param characterIndex Where to split the word.
570 * @param lineHeightOffset Offset between lines.
571 * @param firstResult First part of the split line.
572 * @param lastResult Last part of the split line.
573 * @param location Where this function has been called.
575 * @return \e true if the experiment is successful. Otherwise returns \e false.
577 bool TestSplitLine( const std::string& description,
578 const std::string& input,
579 const size_t wordIndex,
580 const size_t characterIndex,
581 const float lineHeightOffset,
582 const std::string& firstResult,
583 const std::string& lastResult,
584 const char* location )
586 tet_printf( "%s\n", description.c_str() );
588 // Create layout info for the input line.
589 Toolkit::Internal::TextView::RelayoutData relayoutData;
590 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
592 MarkupProcessor::StyledTextArray inputStyledText;
593 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
595 TextViewProcessor::CreateTextInfo( inputStyledText,
596 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
597 Toolkit::TextView::Original,
598 Toolkit::TextView::Original,
599 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
600 Toolkit::TextView::Center,
601 PointSize( lineHeightOffset ),
602 std::string( "..." ),
606 // Get the input line
607 TextViewProcessor::LineLayoutInfo inputLineLayout;
609 if( !inputLayout.mLinesLayoutInfo.empty() )
611 inputLineLayout = *inputLayout.mLinesLayoutInfo.begin();
614 // Create layout info for the first part of the result (after split the line)
616 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
617 TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo );
619 MarkupProcessor::StyledTextArray firstResultStyledText;
620 MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true );
622 TextViewProcessor::CreateTextInfo( firstResultStyledText,
623 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
624 Toolkit::TextView::Original,
625 Toolkit::TextView::Original,
626 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
627 Toolkit::TextView::Center,
628 PointSize( lineHeightOffset ),
629 std::string( "..." ),
633 // Get the first result line
634 TextViewProcessor::LineLayoutInfo firstResultLineLayout;
636 if( !firstResultLayout.mLinesLayoutInfo.empty() )
638 firstResultLineLayout = *firstResultLayout.mLinesLayoutInfo.begin();
641 // Create layout info for the last part of the result (after split the line)
643 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
644 TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo );
646 MarkupProcessor::StyledTextArray lastResultStyledText;
647 MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true );
649 TextViewProcessor::CreateTextInfo( lastResultStyledText,
650 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
651 Toolkit::TextView::Original,
652 Toolkit::TextView::Original,
653 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
654 Toolkit::TextView::Center,
655 PointSize( lineHeightOffset ),
660 // Get the last result line
661 TextViewProcessor::LineLayoutInfo lastResultLineLayout;
663 if( !lastResultLayout.mLinesLayoutInfo.empty() )
665 lastResultLineLayout = *lastResultLayout.mLinesLayoutInfo.begin();
670 TextViewProcessor::LineLayoutInfo lastLineLayoutInfo;
672 TextViewProcessor::TextInfoIndices indices( 0, wordIndex, characterIndex );
675 PointSize( lineHeightOffset ),
677 lastLineLayoutInfo );
680 if( !TestEqual( inputLineLayout, firstResultLineLayout ) )
682 tet_printf( "Fail. different first layout info. %s\n", location );
686 if( !TestEqual( lastLineLayoutInfo, lastResultLineLayout ) )
688 tet_printf( "Fail. different last layout info. %s\n", location );
696 * Merges the \e inputFirst word and the \e inputLast word, and checks the results with \e result.
698 * If the test fails it prints a short description and the line where this function was called.
700 * @param description Short description of the experiment. i.e. "Merge two words with same style".
701 * @param inputFirst The first part of the word.
702 * @param inputLast The last part of the word.
703 * @param result The merged word.
704 * @param location Where this function has been called.
706 * @return \e true if the experiment is successful. Otherwise returns \e false.
708 bool TestMergeWords( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const std::string& result, const char* location )
710 tet_printf( "%s\n", description.c_str() );
712 // Create layout info for the inputFirst word.
713 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
714 TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo );
716 MarkupProcessor::StyledTextArray inputFirstStyledText;
717 MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true );
719 TextViewProcessor::CreateTextInfo( inputFirstStyledText,
720 DEFAULT_LAYOUT_PARAMETERS,
723 // Get the input word
724 TextViewProcessor::WordLayoutInfo inputFirstWordLayout;
726 if( !inputFirstLayout.mLinesLayoutInfo.empty() )
728 const TextViewProcessor::LineLayoutInfo& line( *inputFirstLayout.mLinesLayoutInfo.begin() );
729 if( !line.mWordsLayoutInfo.empty() )
731 inputFirstWordLayout = *( *inputFirstLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
735 // Create layout info for the inputLast word.
736 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
737 TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo );
739 MarkupProcessor::StyledTextArray inputLastStyledText;
740 MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true );
742 TextViewProcessor::CreateTextInfo( inputLastStyledText,
743 DEFAULT_LAYOUT_PARAMETERS,
746 // Get the input word
747 TextViewProcessor::WordLayoutInfo inputLastWordLayout;
749 if( !inputLastLayout.mLinesLayoutInfo.empty() )
751 const TextViewProcessor::LineLayoutInfo& line( *inputLastLayout.mLinesLayoutInfo.begin() );
752 if( !line.mWordsLayoutInfo.empty() )
754 inputLastWordLayout = *( *inputLastLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
758 // Create layout info for the result word.
759 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
760 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
762 MarkupProcessor::StyledTextArray resultStyledText;
763 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
765 TextViewProcessor::CreateTextInfo( resultStyledText,
766 DEFAULT_LAYOUT_PARAMETERS,
767 resultRelayoutData );
769 // Get the result word
770 TextViewProcessor::WordLayoutInfo resultWordLayout;
772 if( !resultLayout.mLinesLayoutInfo.empty() )
774 const TextViewProcessor::LineLayoutInfo& line( *resultLayout.mLinesLayoutInfo.begin() );
775 if( !line.mWordsLayoutInfo.empty() )
777 resultWordLayout = *( *resultLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
781 MergeWord( inputFirstWordLayout,
782 inputLastWordLayout );
784 if( !TestEqual( inputFirstWordLayout, resultWordLayout ) )
786 tet_printf( "Fail. different layout info. %s\n", location );
794 * Merges the \e inputFirst line and the \e inputLast line, and checks the results with \e result.
796 * If the test fails it prints a short description and the line where this function was called.
798 * @param description Short description of the experiment.
799 * @param inputFirst The first part of the line.
800 * @param inputLast The last part of the line.
801 * @param lineHeightOffset Offset between lines.
802 * @param result The merged line.
803 * @param location Where this function has been called.
805 * @return \e true if the experiment is successful. Otherwise returns \e false.
807 bool TestMergeLines( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const float lineHeightOffset, const std::string& result, const char* location )
809 tet_printf( "%s\n", description.c_str() );
811 // Create layout info for the inputFirst line.
812 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
813 TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo );
815 MarkupProcessor::StyledTextArray inputFirstStyledText;
816 MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true );
818 TextViewProcessor::CreateTextInfo( inputFirstStyledText,
819 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
820 Toolkit::TextView::Original,
821 Toolkit::TextView::Original,
822 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
823 Toolkit::TextView::Center,
824 PointSize( lineHeightOffset ),
825 std::string( "..." ),
829 // Get the input word
830 TextViewProcessor::LineLayoutInfo inputFirstLineLayout;
832 if( !inputFirstLayout.mLinesLayoutInfo.empty() )
834 inputFirstLineLayout = *inputFirstLayout.mLinesLayoutInfo.begin();
837 // Create layout info for the inputLast line.
838 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
839 TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo );
841 MarkupProcessor::StyledTextArray inputLastStyledText;
842 MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true );
844 TextViewProcessor::CreateTextInfo( inputLastStyledText,
845 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
846 Toolkit::TextView::Original,
847 Toolkit::TextView::Original,
848 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
849 Toolkit::TextView::Center,
850 PointSize( lineHeightOffset ),
851 std::string( "..." ),
855 // Get the input word
856 TextViewProcessor::LineLayoutInfo inputLastLineLayout;
858 if( !inputLastLayout.mLinesLayoutInfo.empty() )
860 inputLastLineLayout = *inputLastLayout.mLinesLayoutInfo.begin();
863 // Create layout info for the result word.
864 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
865 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
867 MarkupProcessor::StyledTextArray resultStyledText;
868 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
870 TextViewProcessor::CreateTextInfo( resultStyledText,
871 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
872 Toolkit::TextView::Original,
873 Toolkit::TextView::Original,
874 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
875 Toolkit::TextView::Center,
876 PointSize( lineHeightOffset ),
877 std::string( "..." ),
879 resultRelayoutData );
881 // Get the result word
882 TextViewProcessor::LineLayoutInfo resultLineLayout;
884 if( !resultLayout.mLinesLayoutInfo.empty() )
886 resultLineLayout = *resultLayout.mLinesLayoutInfo.begin();
889 MergeLine( inputFirstLineLayout,
890 inputLastLineLayout );
892 if( !TestEqual( inputFirstLineLayout, resultLineLayout ) )
894 tet_printf( "Fail. different layout info. %s\n", location );
902 * Removes from the \e input word the \e numberOfCharacters characters starting from the given \e position and checks the results with \e result.
904 * If the test fails it prints a short description and the line where this function was called.
906 * @param description Short description of the experiment. i.e. "Remove a whole word. Merge".
907 * @param input The input word.
908 * @param position Where to start to remove characters
909 * @param numberOfCharacters The number of characters to remove.
910 * @param result The word without the removed characters.
911 * @param location Where this function has been called.
913 * @return \e true if the experiment is successful. Otherwise returns \e false.
915 bool TestRemoveCharactersFromWord( const std::string& description, const std::string& input, const std::size_t position, const std::size_t numberOfCharacters, const std::string& result, const char* location )
917 tet_printf( "%s\n", description.c_str() );
919 // Create layout info for the input word.
920 Toolkit::Internal::TextView::RelayoutData relayoutData;
921 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
923 MarkupProcessor::StyledTextArray inputStyledText;
924 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
926 TextViewProcessor::CreateTextInfo( inputStyledText,
927 DEFAULT_LAYOUT_PARAMETERS,
930 // Get the input word
931 TextViewProcessor::WordLayoutInfo inputWordLayout;
933 if( !inputLayout.mLinesLayoutInfo.empty() )
935 const TextViewProcessor::LineLayoutInfo& line( *inputLayout.mLinesLayoutInfo.begin() );
936 if( !line.mWordsLayoutInfo.empty() )
938 inputWordLayout = *( *inputLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
942 // Create layout info for the result word.
943 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
944 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
946 MarkupProcessor::StyledTextArray resultStyledText;
947 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
949 TextViewProcessor::CreateTextInfo( resultStyledText,
950 DEFAULT_LAYOUT_PARAMETERS,
951 resultRelayoutData );
953 // Get the result word
954 TextViewProcessor::WordLayoutInfo resultWordLayout;
956 if( !resultLayout.mLinesLayoutInfo.empty() )
958 const TextViewProcessor::LineLayoutInfo& line( *resultLayout.mLinesLayoutInfo.begin() );
959 if( !line.mWordsLayoutInfo.empty() )
961 resultWordLayout = *( *resultLayout.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
965 RemoveCharactersFromWord( position,
969 if( !TestEqual( inputWordLayout, resultWordLayout ) )
971 tet_printf( "Fail. different layout info. %s\n", location );
979 * Removes from the \e input line the \e numberOfWords words starting from the given \e wordIndex and checks the results with \e result.
981 * If the test fails it prints a short description and the line where this function was called.
983 * @param description Short description of the experiment.
984 * @param input The input line.
985 * @param wordIndex Index within the line where to start to remove words.
986 * @param numberOfWords The number of words to remove.
987 * @param lineHeightOffset Offset between lines.
988 * @param result The line without the removed words.
989 * @param location Where this function has been called.
991 * @return \e true if the experiment is successful. Otherwise returns \e false.
993 bool TestRemoveWordsFromLine( const std::string& description, const std::string& input, const std::size_t wordIndex, const std::size_t numberOfWords, const float lineHeightOffset, const std::string& result, const char* location )
995 tet_printf( "%s\n", description.c_str() );
997 // Create layout info for the input line.
998 Toolkit::Internal::TextView::RelayoutData relayoutData;
999 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
1001 MarkupProcessor::StyledTextArray inputStyledText;
1002 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
1004 TextViewProcessor::CreateTextInfo( inputStyledText,
1005 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1006 Toolkit::TextView::Original,
1007 Toolkit::TextView::Original,
1008 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1009 Toolkit::TextView::Center,
1010 PointSize( lineHeightOffset ),
1011 std::string( "..." ),
1015 // Get the input line
1016 TextViewProcessor::LineLayoutInfo inputLineLayout;
1018 if( !inputLayout.mLinesLayoutInfo.empty() )
1020 inputLineLayout = *inputLayout.mLinesLayoutInfo.begin();
1023 // Create layout info for the result line.
1024 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
1025 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
1027 MarkupProcessor::StyledTextArray resultStyledText;
1028 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
1030 TextViewProcessor::CreateTextInfo( resultStyledText,
1031 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1032 Toolkit::TextView::Original,
1033 Toolkit::TextView::Original,
1034 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1035 Toolkit::TextView::Center,
1036 PointSize( lineHeightOffset ),
1037 std::string( "..." ),
1039 resultRelayoutData );
1041 // Get the result line
1042 TextViewProcessor::LineLayoutInfo resultLineLayout;
1044 if( !resultLayout.mLinesLayoutInfo.empty() )
1046 resultLineLayout = *resultLayout.mLinesLayoutInfo.begin();
1049 RemoveWordsFromLine( wordIndex,
1054 if( !TestEqual( inputLineLayout, resultLineLayout ) )
1056 tet_printf( "Fail. different layout info. %s\n", location );
1057 tet_printf( " input : [%s]\n", input.c_str() );
1058 tet_printf( " result : [%s]\n", GetText( resultLineLayout ).c_str() );
1059 tet_printf( " expected result : [%s]\n\n", result.c_str() );
1061 Print(inputLineLayout); std::cout << std::endl << std::endl;
1062 Print(resultLineLayout); std::cout << std::endl;
1070 * Tests inserts, removes and updates operation in the given \e input text and checks with the given \e result.
1072 * If the test fails it prints a short description and the line where this function was called.
1074 * @param description Short description of the experiment.
1075 * @param operation Type of update operation (insert, remove, replace)
1076 * @param input The input text.
1077 * @param position Where to insert, remove or replace text.
1078 * @param numberOfCharacters Number of characters to remove or replace.
1079 * @param inputText Inserted or updated text.
1080 * @param lineHeightOffset Offset between lines.
1081 * @param result Expected result.
1082 * @param location Where this function has been called.
1084 * @return \e true if the experiment is successful. Otherwise returns \e false.
1086 bool TestUpdateTextInfo( const std::string& description,
1087 const UpdateTextInfoOperation operation,
1088 const std::string& input,
1089 const std::size_t position,
1090 const std::size_t numberOfCharacters,
1091 const std::string& inputText,
1092 const float lineHeightOffset,
1093 const std::string& result,
1094 const char* location )
1096 tet_printf( "%s\n", description.c_str() );
1098 // Create layout info for the input.
1099 Toolkit::Internal::TextView::RelayoutData relayoutData;
1100 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
1102 MarkupProcessor::StyledTextArray inputStyledText;
1103 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
1105 TextViewProcessor::CreateTextInfo( inputStyledText,
1106 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1107 Toolkit::TextView::Original,
1108 Toolkit::TextView::Original,
1109 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1110 Toolkit::TextView::Center,
1111 PointSize( lineHeightOffset ),
1112 std::string( "..." ),
1116 // Create layout info for the result.
1117 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
1118 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
1120 MarkupProcessor::StyledTextArray resultStyledText;
1121 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
1123 TextViewProcessor::CreateTextInfo( resultStyledText,
1124 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1125 Toolkit::TextView::Original,
1126 Toolkit::TextView::Original,
1127 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1128 Toolkit::TextView::Center,
1129 PointSize( lineHeightOffset ),
1130 std::string( "..." ),
1132 resultRelayoutData );
1134 // Choose operation and call appropiate UpdateTextInfo() method.
1135 const Toolkit::Internal::TextView::LayoutParameters layoutParameters( Toolkit::TextView::SplitByNewLineChar,
1136 Toolkit::TextView::Original,
1137 Toolkit::TextView::Original,
1138 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1139 Toolkit::TextView::Center,
1140 PointSize( lineHeightOffset ),
1141 std::string( "..." ),
1148 MarkupProcessor::StyledTextArray inputStyledText;
1149 MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true );
1151 TextViewProcessor::UpdateTextInfo( position,
1159 TextViewProcessor::UpdateTextInfo( position,
1163 TextViewProcessor::CLEAR_TEXT );
1168 MarkupProcessor::StyledTextArray inputStyledText;
1169 MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true );
1171 TextViewProcessor::UpdateTextInfo( position,
1180 tet_printf( "TestUpdateTextInfo: unknown update operation. %s\n", location );
1185 if( !TestEqual( inputLayout, resultLayout ) )
1187 tet_printf( "Fail. different layout info. %s\n", location );
1189 // std::cout << " result : "; Print( inputLayout );
1190 // std::cout << " expected result : "; Print( resultLayout );
1200 int UtcDaliTextViewCreateTextInfo(void)
1202 ToolkitTestApplication application;
1204 tet_infoline("UtcDaliTextViewCreateTextInfo : ");
1206 // Metrics for characters
1209 // size : [9.48351, 9.48351]
1210 // advance : 9.48351
1211 // bearing : 8.53516
1212 // ascender : 8.53516
1215 // size : [11.3802, 11.3802]
1216 // advance : 11.3802
1217 // bearing : 10.2422
1218 // ascender : 10.2422
1221 // size : [13.2769, 13.2769]
1222 // advance : 13.2769
1223 // bearing : 11.9492
1224 // ascender : 11.9492
1226 const float WIDTH_10( 9.48351f );
1227 const float HEIGHT_10( 9.48351f );
1228 const float ADVANCE_10( 9.48351f );
1229 const float BEARING_10( 8.53516f );
1230 const float ASCENDER_10( 8.53516f );
1232 const float WIDTH_12( 11.3802f );
1233 const float HEIGHT_12( 11.3802f );
1234 const float ADVANCE_12( 11.3802f );
1235 const float BEARING_12( 10.2422f );
1236 const float ASCENDER_12( 10.2422f );
1240 Toolkit::Internal::TextView::RelayoutData relayoutData;
1241 TextViewProcessor::TextLayoutInfo& textLayoutInfo( relayoutData.mTextLayoutInfo );
1243 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
1246 MarkupProcessor::StyledTextArray styledText;
1247 MarkupProcessor::GetStyledTextArray( text, styledText, true );
1249 TextViewProcessor::CreateTextInfo( styledText,
1250 DEFAULT_LAYOUT_PARAMETERS,
1254 // Build the text info with metric values.
1258 TextViewProcessor::CharacterLayoutInfo layoutInfo10; // ( [lo wo])
1259 layoutInfo10.mHeight = HEIGHT_10;
1260 layoutInfo10.mAdvance = ADVANCE_10;
1261 layoutInfo10.mBearing = BEARING_10;
1262 layoutInfo10.mSize = Size( WIDTH_10, HEIGHT_10 );
1263 layoutInfo10.mAscender = ASCENDER_10;
1264 TextViewProcessor::CharacterLayoutInfo layoutInfo12; // ( [Hel], [rld!] and [CR])
1265 layoutInfo12.mHeight = HEIGHT_12;
1266 layoutInfo12.mAdvance = ADVANCE_12;
1267 layoutInfo12.mBearing = BEARING_12;
1268 layoutInfo12.mSize = Size( WIDTH_12, HEIGHT_12 );
1269 layoutInfo12.mAscender = ASCENDER_12;
1272 style10.SetFontName( "" );
1273 style10.SetFontPointSize( PointSize( 10.f ) );
1275 style12.SetFontName( "" );
1277 layoutInfo12.mStyledText.mStyle = style12;
1278 layoutInfo10.mStyledText.mStyle = style10;
1282 TextViewProcessor::WordLayoutInfo wordLayout1, wordLayout2, wordLayout3, wordLayout4;
1285 wordLayout1.mSize = Size( 3.f * WIDTH_12 + 2.f * WIDTH_10, HEIGHT_12 );
1286 wordLayout1.mAscender = ASCENDER_12;
1287 wordLayout1.mType = TextViewProcessor::NoSeparator;
1289 layoutInfo12.mStyledText.mText = Text( "H" );
1290 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // H
1291 layoutInfo12.mStyledText.mText = Text( "e" );
1292 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // e
1293 layoutInfo12.mStyledText.mText = Text( "l" );
1294 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l
1295 layoutInfo10.mStyledText.mText = Text( "l" );
1296 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // l
1297 layoutInfo10.mStyledText.mText = Text( "o" );
1298 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o
1301 wordLayout2.mSize = Size( WIDTH_10, HEIGHT_10 );
1302 wordLayout2.mAscender = ASCENDER_10;
1303 wordLayout2.mType = TextViewProcessor::WordSeparator;
1304 layoutInfo10.mStyledText.mText = Text( " " );
1305 wordLayout2.mCharactersLayoutInfo.push_back( layoutInfo10 ); // (white space)
1308 wordLayout3.mSize = Size( 2.f * WIDTH_10 + 4.f * WIDTH_12, HEIGHT_12 );
1309 wordLayout3.mAscender = ASCENDER_12;
1310 wordLayout3.mType = TextViewProcessor::NoSeparator;
1311 layoutInfo10.mStyledText.mText = Text( "w" );
1312 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // w
1313 layoutInfo10.mStyledText.mText = Text( "o" );
1314 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o
1315 layoutInfo12.mStyledText.mText = Text( "r" );
1316 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // r
1317 layoutInfo12.mStyledText.mText = Text( "l" );
1318 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l
1319 layoutInfo12.mStyledText.mText = Text( "d" );
1320 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // d
1321 layoutInfo12.mStyledText.mText = Text( "!" );
1322 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // !
1324 // (new line character)
1325 wordLayout4.mSize = Size( 0.f, HEIGHT_12 );
1326 wordLayout4.mAscender = ASCENDER_12;
1327 wordLayout4.mType = TextViewProcessor::LineSeparator;
1328 layoutInfo12.mStyledText.mText = Text( "\n" );
1329 layoutInfo12.mSize.width = 0.f;
1330 wordLayout4.mCharactersLayoutInfo.push_back( layoutInfo12 ); // (new line char)
1334 TextViewProcessor::LineLayoutInfo lineLayout1, lineLayout2, lineLayout3;
1336 lineLayout1.mSize = Size( 5.f * WIDTH_10 + 7.f * WIDTH_12, HEIGHT_12 );
1337 lineLayout1.mAscender = ASCENDER_12;
1338 lineLayout1.mNumberOfCharacters = 13;
1339 lineLayout1.mWordsLayoutInfo.push_back( wordLayout1 );
1340 lineLayout1.mWordsLayoutInfo.push_back( wordLayout2 );
1341 lineLayout1.mWordsLayoutInfo.push_back( wordLayout3 );
1342 lineLayout1.mWordsLayoutInfo.push_back( wordLayout4 );
1344 lineLayout2.mSize = Size( 0.f, HEIGHT_12 );
1345 lineLayout2.mAscender = ASCENDER_12;
1346 lineLayout2.mNumberOfCharacters = 1;
1347 lineLayout2.mWordsLayoutInfo.push_back( wordLayout4 );
1349 lineLayout3.mSize = Size( 0.f, HEIGHT_12 );
1352 TextViewProcessor::TextLayoutInfo textLayout;
1354 textLayout.mWholeTextSize = Size( 5.f * WIDTH_10 + 7.f * WIDTH_12, 3.f * HEIGHT_12 );
1355 textLayout.mMaxWordWidth = 2.f * WIDTH_10 + 4.f * WIDTH_12;
1356 textLayout.mNumberOfCharacters = 14;
1357 textLayout.mLinesLayoutInfo.push_back( lineLayout1 );
1358 textLayout.mLinesLayoutInfo.push_back( lineLayout2 );
1359 textLayout.mLinesLayoutInfo.push_back( lineLayout3 );
1361 if(!TestEqual( textLayout, textLayoutInfo ))
1363 std::cout << "Layout fails" << std::endl;
1364 Print(textLayout); std::cout << std::endl;
1365 Print(textLayoutInfo); std::cout << std::endl;
1368 DALI_TEST_CHECK( TestEqual( textLayout, textLayoutInfo ) );
1372 int UtcDaliTextViewSplitWord(void)
1374 ToolkitTestApplication application;
1376 tet_infoline("UtcDaliTextViewSplitWord : ");
1378 struct SplitWordTest splitWordTests[] =
1381 std::string( "Split word, position 0." ),
1382 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1385 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1388 std::string( "Split word, position 8." ),
1389 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1391 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1395 std::string( "Split word, position 2." ),
1396 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1398 std::string( "<font size='10'>He</font>" ),
1399 std::string( "<font size='12'>ll</font><font size='10'>oooo</font>" ),
1402 std::string( "Split word, position 3." ),
1403 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1405 std::string( "<font size='10'>He</font><font size='12'>l</font>" ),
1406 std::string( "<font size='12'>l</font><font size='10'>oooo</font>" ),
1409 std::string( "Split word, position 4." ),
1410 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1412 std::string( "<font size='10'>He</font><font size='12'>ll</font>" ),
1413 std::string( "<font size='10'>oooo</font>" ),
1416 const std::size_t numberOfTests( 5 );
1418 for( std::size_t index = 0; index < numberOfTests; ++index )
1420 const SplitWordTest& test = splitWordTests[index];
1422 if( !TestSplitWord( test.description, test.input, test.position, test.firstResult, test.lastResult, TEST_LOCATION ) )
1424 tet_result( TET_FAIL );
1428 tet_result( TET_PASS );
1432 int UtcDaliTextViewUpdateTextInfo(void)
1434 ToolkitTestApplication application;
1436 tet_infoline("UtcDaliTextViewUpdateTextInfo : ");
1438 struct UpdateTextInfoTest updateTextInfoTest[] =
1440 // Remove operations
1443 std::string( "Remove from new line character to first character next line." ),
1445 std::string("Hello world\nhello world."),
1450 std::string("Hello worldello world."),
1453 std::string( "Replace style from new line character to first character next line." ),
1455 std::string("Hello world\nhello world."),
1458 std::string("<b>\nh</b>"),
1460 std::string("Hello world<b>\nh</b>ello world."),
1463 std::string( "Remove from the beginning to the middle of last word." ),
1465 std::string("Hello world, hello world."),
1468 std::string(), // Not used.
1473 std::string( "Remove from the beginning to the middle of the text." ),
1475 std::string("Hello world hello world."),
1478 std::string(), // Not used.
1480 std::string("hello world."),
1482 // Remove within the same word:
1483 // * within the same group of characters with same style.
1485 std::string( "Remove within the same word, within the same group of characters with same style" ),
1487 std::string("Hello <font size='30'>world\nhello</font> world"),
1490 std::string(), // Not used.
1492 std::string( "Hello <font size='30'>wd\nhello</font> world" )
1494 // * whole group of characters (merge adjacent group of characters)
1496 std::string( "Remove within the same word, whole group of characters (merge adjacent group of characters)" ),
1498 std::string("Hello <font size='30'>w<font size='20'>orl</font>d\nhello</font> world"),
1501 std::string(), // Not used.
1503 std::string( "Hello <font size='30'>wd\nhello</font> world" )
1505 // * whole group of characters (don't merge adjacent gtoup of characters)
1507 std::string( "Remove within the same word, whole group of characters (don't merge adjacent gtoup of characters)" ),
1509 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1512 std::string(), // Not used.
1514 std::string( "Hello <font size='30'>w</font><font size='10'>d\nhello</font> world" )
1516 // * Remove whole word (merge words)
1518 std::string( "Remove within the same word, whole word (merge words)" ),
1520 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1523 std::string(), // Not used.
1525 std::string( "Hello<font size='30'>w</font>orl<font size='10'>d\nhello</font> world" )
1527 // * Remove whole word (don't merge words)
1529 std::string( "Remove within the same word, whole word (don't merge words)" ),
1531 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1534 std::string(), // Not used.
1536 std::string( "Hello <font size='10'>\nhello</font> world" )
1538 // * Remove whole word (merge lines)
1540 std::string( "Remove within the same word, whole word (merge lines)" ),
1542 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1545 std::string(), // Not used.
1547 std::string( "Hello <font size='30'>w</font>orl<font size='10'>dhello</font> world" )
1549 // * Remove RTL text within LTR
1550 /* TODO check this when RTL text is working
1552 std::string( "Remove within the same line, RTL text within LTR." ),
1554 std::string("Hello world, שלום עולם, hello world"),
1557 std::string(), // Not used.
1559 std::string( "Hello worlello world" )
1562 // * Remove whole line
1564 std::string( "Remove whole line" ),
1566 std::string("Hello world, hello world\n"
1567 "Hello world, hello world\n"
1568 "Hello world, hello world\n"
1569 "Hello world, hello world\n"),
1572 std::string(), // Not used.
1574 std::string("Hello world, hello world\n"
1575 "Hello world, hello world\n"
1576 "Hello world, hello world\n"),
1579 std::string( "Remove whole line" ),
1581 std::string("Hello world, hello world\n"
1585 std::string(), // Not used.
1587 std::string("Hello world, hello world\n"),
1591 // Insert operations
1593 std::string( "insert some text" ),
1595 std::string("inpuext"),
1598 std::string( "t t" ),
1600 std::string( "input text" )
1603 std::string( "Insert text at the end" ),
1605 std::string("touch "),
1608 std::string("me\nhello"),
1610 std::string("touch me\nhello")
1613 // Replace operations.
1615 std::string( "Replace style from the beginning to some point in the middle of the text." ),
1617 std::string( "Hello <font color='green'>world</font>" ),
1620 std::string( "<font color='red'>Hello w</font>" ),
1622 std::string( "<font color='red'>Hello w</font><font color='green'>orld</font>" )
1625 std::string( "Replace style from the middle of the text to the end." ),
1627 std::string( "Touch me\nhello" ),
1630 std::string( "<b>me\nhello</b>" ),
1632 std::string( "Touch <b>me\nhello</b>" )
1635 std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 1." ),
1637 std::string( "Touch me\nhello\nworld" ),
1642 std::string( "Touch \nworld" )
1645 std::string( "Insert styled text in the middle of a text. Previous: Replace style from the middle of the text 1." ),
1647 std::string( "Touch \nworld" ),
1650 std::string( "<b>me\nhello</b>" ),
1652 std::string( "Touch <b>me\nhello</b>\nworld" )
1655 std::string( "Replace style from the middle of the text 1." ),
1657 std::string( "Touch me\nhello\nworld" ),
1660 std::string( "<b>me\nhello</b>" ),
1662 std::string( "Touch <b>me\nhello</b>\nworld" )
1665 std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 2." ),
1667 std::string( "Touch me\nhello\nworld" ),
1672 std::string( "Touch world" )
1675 std::string( "Replace style from the middle of the text 2." ),
1677 std::string( "Touch me\nhello\nworld" ),
1680 std::string( "<b>me\nhello\n</b>" ),
1682 std::string( "Touch <b>me\nhello\n</b>world" )
1685 const std::size_t numberOfTests( 21 );
1687 for( std::size_t index = 0; index < numberOfTests; ++index )
1689 const UpdateTextInfoTest& test = updateTextInfoTest[index];
1691 if( !TestUpdateTextInfo( test.description, test.operation, test.input, test.position, test.numberOfCharacters, test.inputText, test.lineHeightOffset, test.result, TEST_LOCATION ) )
1693 tet_result( TET_FAIL );
1697 tet_result( TET_PASS );
1701 int UtcDaliTextViewSplitLine(void)
1703 ToolkitTestApplication application;
1705 tet_infoline("UtcDaliTextViewSplitLine : ");
1707 struct SplitLineTest splitLineTests[] =
1710 std::string( "Split line, wordPosition 0, position 0." ),
1711 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1716 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1719 std::string( "Split line, wordPosition 10, position 4." ),
1720 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1724 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1728 std::string( "Split line, wordPosition 2, position 4." ),
1729 std::string("<font size='10'>Hello </font>wor<font size='12'>ld, hello wo</font>rld"),
1733 std::string("<font size='10'>Hello </font>wor<font size='12'>l</font>"),
1734 std::string("<font size='12'>d, hello wo</font>rld")
1738 std::string( "Split line, wordPosition 6, position 0." ),
1739 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1743 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום" ),
1744 std::string( " עולם text text" ),
1747 std::string( "Split line, wordPosition 4, position 0." ),
1748 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1752 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> " ),
1753 std::string( "שלום עולם text text" ),
1756 std::string( "Split line2, wordPosition 8, position 0." ),
1757 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1761 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם " ),
1762 std::string( "text text" ),
1766 const std::size_t numberOfTests( 3 );
1768 for( std::size_t index = 0; index < numberOfTests; ++index )
1770 const SplitLineTest& test = splitLineTests[index];
1772 if( !TestSplitLine( test.description,
1775 test.characterIndex,
1776 test.lineHeightOffset,
1781 tet_result( TET_FAIL );
1785 tet_result( TET_PASS );
1789 int UtcDaliTextViewMergeWord01(void)
1791 ToolkitTestApplication application;
1793 tet_infoline("UtcDaliTextViewMergeWord01 : ");
1795 struct MergeWordsTest mergeWordsTests[] =
1798 std::string( "Merge words with same style." ),
1799 std::string( "Hel" ),
1800 std::string( "lo" ),
1801 std::string( "Hello" ),
1804 std::string( "Merge words with different styles." ),
1805 std::string( "<font size='10>Hel</font>" ),
1806 std::string( "<font size='20'>lo</font>" ),
1807 std::string( "<font size='10'>Hel</font><font size='20'>lo</font>" )
1810 const std::size_t numberOfTests( 2 );
1812 for( std::size_t index = 0; index < numberOfTests; ++index )
1814 const MergeWordsTest& test = mergeWordsTests[index];
1816 if( !TestMergeWords( test.description, test.inputFirst, test.inputLast, test.result, TEST_LOCATION ) )
1818 tet_result( TET_FAIL );
1822 tet_result( TET_PASS );
1826 int UtcDaliTextViewMergeWord02(void)
1829 // It test white spaces and new line characters can't be merged to other words.
1831 ToolkitTestApplication application;
1833 tet_infoline("UtcDaliTextViewMergeWord02 : ");
1835 // Generate three words
1837 Toolkit::Internal::TextView::RelayoutData relayoutData01;
1838 Toolkit::Internal::TextView::RelayoutData relayoutData02;
1839 Toolkit::Internal::TextView::RelayoutData relayoutData03;
1840 TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo );
1841 TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo );
1842 TextViewProcessor::TextLayoutInfo& textLayoutInfo03( relayoutData03.mTextLayoutInfo );
1844 std::string text01( " " );
1845 std::string text02( "\n" );
1846 std::string text03( "a" );
1847 MarkupProcessor::StyledTextArray styledText01;
1848 MarkupProcessor::StyledTextArray styledText02;
1849 MarkupProcessor::StyledTextArray styledText03;
1850 MarkupProcessor::GetStyledTextArray( text01, styledText01, true );
1851 MarkupProcessor::GetStyledTextArray( text02, styledText02, true );
1852 MarkupProcessor::GetStyledTextArray( text03, styledText03, true );
1854 TextViewProcessor::CreateTextInfo( styledText01,
1855 DEFAULT_LAYOUT_PARAMETERS,
1858 TextViewProcessor::WordLayoutInfo wordLayoutInfo01;
1860 wordLayoutInfo01 = *( *textLayoutInfo01.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1862 TextViewProcessor::CreateTextInfo( styledText02,
1863 DEFAULT_LAYOUT_PARAMETERS,
1866 TextViewProcessor::WordLayoutInfo wordLayoutInfo02;
1868 wordLayoutInfo02 = *( *textLayoutInfo02.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1870 TextViewProcessor::CreateTextInfo( styledText03,
1871 DEFAULT_LAYOUT_PARAMETERS,
1874 TextViewProcessor::WordLayoutInfo wordLayoutInfo03;
1876 wordLayoutInfo03 = *( *textLayoutInfo03.mLinesLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1878 // Test MergeWord() asserts if white spaces or new line chars are merged.
1879 bool assert1 = false;
1880 bool assert2 = false;
1881 bool assert3 = false;
1882 bool assert4 = false;
1883 bool assert5 = false;
1884 bool assert6 = false;
1888 MergeWord( wordLayoutInfo01,
1891 catch( Dali::DaliException& e )
1893 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1894 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1899 MergeWord( wordLayoutInfo01,
1902 catch( Dali::DaliException& e )
1904 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1905 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1910 MergeWord( wordLayoutInfo02,
1913 catch( Dali::DaliException& e )
1915 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1916 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1921 MergeWord( wordLayoutInfo02,
1924 catch( Dali::DaliException& e )
1926 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1927 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1932 MergeWord( wordLayoutInfo03,
1935 catch( Dali::DaliException& e )
1937 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1938 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1943 MergeWord( wordLayoutInfo03,
1946 catch( Dali::DaliException& e )
1948 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
1949 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new line characters can't be merged with other words.\"", TEST_LOCATION );
1953 if( assert1 && assert2 && assert3 && assert4 && assert5 && assert6 )
1955 tet_result( TET_PASS );
1959 tet_result( TET_FAIL );
1964 int UtcDaliTextViewMergeLine01(void)
1966 ToolkitTestApplication application;
1968 tet_infoline("UtcDaliTextViewMergeLine01 : ");
1970 struct MergeLinesTest mergeLinesTests[] =
1973 std::string( "Merge a void first line." ),
1975 std::string( "Hello world, this is a whole line" ),
1977 std::string( "Hello world, this is a whole line" )
1980 std::string( "Merge a void last line." ),
1981 std::string( "Hello world, this is a whole line" ),
1984 std::string( "Hello world, this is a whole line" )
1988 std::string( "Merge lines: last starting with RTL text and first ending with RTL" ),
1989 std::string( "Hello world, שלום" ),
1990 std::string( " עולם, hello world." ),
1992 std::string( "Hello world, שלום עולם, hello world." )
1995 std::string( "Merge lines and don't merge last and first words." ),
1996 std::string( "Hello world, " ),
1997 std::string( "שלום עולם, hello world." ),
1999 std::string( "Hello world, שלום עולם, hello world." )
2003 std::string( "Merge lines. Don't merge words" ),
2004 std::string( "Hello world," ),
2005 std::string( " this is a whole line" ),
2007 std::string( "Hello world, this is a whole line" )
2010 std::string( "Merge lines. Merge words" ),
2011 std::string( "Hello world, th" ),
2012 std::string( "is is a whole line" ),
2014 std::string( "Hello world, this is a whole line" )
2017 const std::size_t numberOfTests( 4 );
2019 for( std::size_t index = 0; index < numberOfTests; ++index )
2021 const MergeLinesTest& test = mergeLinesTests[index];
2023 if( !TestMergeLines( test.description, test.inputFirst, test.inputLast, test.lineHeightOffset, test.result, TEST_LOCATION ) )
2025 tet_result( TET_FAIL );
2029 tet_result( TET_PASS );
2033 int UtcDaliTextViewMergeLine02(void)
2035 ToolkitTestApplication application;
2037 tet_infoline("UtcDaliTextViewMergeLine02 : ");
2039 Toolkit::Internal::TextView::RelayoutData relayoutData01;
2040 Toolkit::Internal::TextView::RelayoutData relayoutData02;
2041 TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo );
2042 TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo );
2044 std::string text01( "Hello world\n" );
2045 std::string text02( "hello world" );
2046 MarkupProcessor::StyledTextArray styledText01;
2047 MarkupProcessor::StyledTextArray styledText02;
2048 MarkupProcessor::GetStyledTextArray( text01, styledText01, true );
2049 MarkupProcessor::GetStyledTextArray( text02, styledText02, true );
2051 TextViewProcessor::CreateTextInfo( styledText01,
2052 DEFAULT_LAYOUT_PARAMETERS,
2055 TextViewProcessor::LineLayoutInfo lineLayoutInfo01;
2057 lineLayoutInfo01 = *textLayoutInfo01.mLinesLayoutInfo.begin();
2059 TextViewProcessor::CreateTextInfo( styledText02,
2060 DEFAULT_LAYOUT_PARAMETERS,
2063 TextViewProcessor::LineLayoutInfo lineLayoutInfo02;
2065 lineLayoutInfo02 = *textLayoutInfo02.mLinesLayoutInfo.begin();
2067 bool assert1 = false;
2071 MergeLine( lineLayoutInfo01,
2074 catch( Dali::DaliException& e )
2076 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
2077 DALI_TEST_EQUALS( e.mCondition, "!\"TextViewProcessor::MergeLine(). ERROR: A line can't be merged to another line which finishes with a new line character.\"", TEST_LOCATION );
2083 tet_result( TET_PASS );
2087 tet_result( TET_FAIL );
2092 int UtcDaliTextViewRemoveCharactersFromWord(void)
2094 ToolkitTestApplication application;
2096 tet_infoline("UtcDaliTextViewMergeWord02 : ");
2098 struct RemoveCharactersFromWordTest removeCharactersFromWordTests[] =
2101 std::string( "Delete 0 characters." ),
2102 std::string( "Hello" ),
2105 std::string( "Hello" ),
2108 std::string( "Delete within the same group of characters. Starting from the beginning" ),
2109 std::string( "Hello" ),
2112 std::string( "lo" ),
2115 std::string( "Delete within the same group of characters. Somewhere in the middle" ),
2116 std::string( "Hello" ),
2119 std::string( "Heo" ),
2122 std::string( "Delete within the same group of characters. Starting somewhere in the middle to the end" ),
2123 std::string( "Hello" ),
2126 std::string( "Hel" ),
2129 std::string( "Delete within the same group of characters. Finish just before a new one." ),
2130 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2133 std::string( "<font size='10'>H</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2136 std::string( "Delete starting in one group of characters and finishing in a different one. No merge of groups." ),
2137 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2140 std::string( "<font size='10'>He</font><font size='20'>Wo</font><font size='30'>rld</font>" ),
2143 std::string( "Delete within the same group of characters. Starting just after a different one." ),
2144 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2147 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>d</font>" ),
2150 std::string( "Delete whole group of characters. No merge" ),
2151 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2154 std::string( "<font size='10'>Hel</font><font size='30'>rld</font>" ),
2157 std::string( "Delete whole group of characters and part of the adjacent ones. No merge" ),
2158 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2161 std::string( "<font size='10'>He</font><font size='30'>ld</font>" ),
2164 std::string( "Delete whole group of characters. Merge" ),
2165 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='10'>rld</font>" ),
2168 std::string( "<font size='10'>Helrld</font>" ),
2171 std::string( "Delete whole group of characters and part of the adjacent ones. Merge" ),
2172 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='10'>rld</font>" ),
2175 std::string( "<font size='10'>Held</font>" ),
2178 const std::size_t numberOfTests( 11 );
2180 for( std::size_t index = 0; index < numberOfTests; ++index )
2182 const RemoveCharactersFromWordTest& test = removeCharactersFromWordTests[index];
2184 if( !TestRemoveCharactersFromWord( test.description, test.input, test.position, test.numberOfCharacters, test.result, TEST_LOCATION ) )
2186 tet_result( TET_FAIL );
2190 tet_result( TET_PASS );
2194 int UtcDaliTextViewRemoveWordsFromLine(void)
2196 // Note: Currently RemoveWordsFromLine() function is only used to remove a number of words from the beginning, or
2197 // from a given index to the end.
2199 ToolkitTestApplication application;
2201 tet_infoline("UtcDaliTextViewRemoveWordsFromLine : ");
2202 struct RemoveWordsFromLineTest removeWordsFromLineTest[] =
2205 std::string( "Delete 0 words." ),
2206 std::string( "Hello hello, שלום עולם hello hello" ),
2210 std::string( "Hello hello, שלום עולם hello hello" ),
2213 std::string( "Delete from the middle to the end." ),
2214 std::string( "Hello hello, שלום עולם hello hello" ),
2218 std::string( "Hello hello, " ),
2221 std::string( "Delete from the beginning to the middle." ),
2222 std::string( "Hello hello, שלום עולם hello hello" ),
2226 std::string( "hello hello" ),
2229 const std::size_t numberOfTests( 3 );
2231 for( std::size_t index = 0; index < numberOfTests; ++index )
2233 const RemoveWordsFromLineTest& test = removeWordsFromLineTest[index];
2235 if( !TestRemoveWordsFromLine( test.description, test.input, test.wordIndex, test.numberOfWords, test.lineHeightOffset, test.result, TEST_LOCATION ) )
2237 tet_result( TET_FAIL );
2241 tet_result( TET_PASS );