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-paragraph-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;
63 struct SplitParagraphTest
65 std::string description;
67 std::size_t wordIndex;
68 std::size_t characterIndex;
69 std::size_t characterParagraphIndex;
70 float lineHeightOffset;
71 std::string firstResult;
72 std::string lastResult;
77 std::string description;
78 std::string inputFirst;
79 std::string inputLast;
83 struct MergeParagraphsTest
85 std::string description;
86 std::string inputFirst;
87 std::string inputLast;
88 float lineHeightOffset;
92 struct RemoveCharactersFromWordTest
94 std::string description;
97 std::size_t numberOfCharacters;
101 struct RemoveWordsFromParagraphTest
103 std::string description;
105 std::size_t wordIndex;
106 std::size_t numberOfWords;
107 float lineHeightOffset;
111 enum UpdateTextInfoOperation
118 struct UpdateTextInfoTest
120 std::string description;
121 UpdateTextInfoOperation operation;
123 std::size_t position;
124 std::size_t numberOfCharacters;
125 std::string inputText;
126 float lineHeightOffset;
130 // Useful Print functions when something goes wrong.
132 void Print( const TextViewProcessor::CharacterLayoutInfo& character )
134 std::cout << " height : " << character.mSize.height << std::endl;
135 std::cout << " advance : " << character.mSize.width << std::endl;
136 std::cout << " bearing : " << character.mBearing << std::endl;
137 std::cout << " ascender : " << character.mAscender << std::endl;
138 std::cout << " position : " << character.mPosition << std::endl;
140 TextActor textActor = TextActor::DownCast( character.mGlyphActor );
143 std::cout << "[" << textActor.GetText() << "]";
147 void Print( const TextViewProcessor::WordLayoutInfo& word )
150 std::cout << " mSize : " << word.mSize << std::endl;
151 std::cout << " mAscender : " << word.mAscender << std::endl;
152 std::cout << " mType : " << word.mType << std::endl;
153 std::cout << "mNumberOfCharacters : " << word.mCharactersLayoutInfo.size() << std::endl;
155 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it = word.mCharactersLayoutInfo.begin(), endIt = word.mCharactersLayoutInfo.end(); it != endIt; ++it )
159 std::cout << "]"; std::cout << std::endl;
160 std::cout << "]"; std::cout << std::endl;
163 void Print( const TextViewProcessor::ParagraphLayoutInfo& paragraph )
166 std::cout << " mSize : " << paragraph.mSize << std::endl;
167 std::cout << " mAscender : " << paragraph.mAscender << std::endl;
168 std::cout << "mNumberOfCharacters : " << paragraph.mNumberOfCharacters << std::endl;
169 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = paragraph.mWordsLayoutInfo.begin(), endIt = paragraph.mWordsLayoutInfo.end(); it != endIt; ++it )
173 std::cout << ">" << std::endl;
176 void Print( const TextViewProcessor::TextLayoutInfo& text )
179 for( TextViewProcessor::ParagraphLayoutInfoContainer::const_iterator it = text.mParagraphsLayoutInfo.begin(), endIt = text.mParagraphsLayoutInfo.end(); it != endIt; ++it )
183 std::cout << "||" << std::endl;
186 std::string GetText( const TextViewProcessor::WordLayoutInfo& word, const Text& paragraphText )
190 paragraphText.GetSubText( word.mFirstCharacter, word.mFirstCharacter + word.mCharactersLayoutInfo.size() - 1u, text );
192 return text.GetText();
195 std::string GetText( const TextViewProcessor::ParagraphLayoutInfo& paragraph )
199 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = paragraph.mWordsLayoutInfo.begin(), endIt = paragraph.mWordsLayoutInfo.end(); it != endIt; ++it )
201 text += GetText( *it, paragraph.mText );
207 // Test functions used to check if two data structures are equal.
209 bool TestEqual( float x, float y )
211 return ( fabsf( x - y ) < 0.001f );
214 bool TestEqual( const TextViewProcessor::CharacterLayoutInfo& character1,
215 const TextViewProcessor::CharacterLayoutInfo& character2 )
217 if( !TestEqual( character1.mSize.height, character2.mSize.height ) )
221 if( !TestEqual( character1.mSize.width, character2.mSize.width ) )
225 if( !TestEqual( character1.mBearing, character2.mBearing ) )
230 if( !TestEqual( character1.mPosition.x, character2.mPosition.x ) )
234 if( !TestEqual( character1.mPosition.y, character2.mPosition.y ) )
239 if( !TestEqual( character1.mAscender, character2.mAscender ) )
244 if( character1.mGlyphActor && !character2.mGlyphActor )
249 if( !character1.mGlyphActor && character2.mGlyphActor )
259 TextActor textActor1 = TextActor::DownCast( character1.mGlyphActor );
260 TextActor textActor2 = TextActor::DownCast( character2.mGlyphActor );
263 text1 = textActor1.GetText();
264 style1 = textActor1.GetTextStyle();
266 text2 = textActor2.GetText();
267 style2 = textActor2.GetTextStyle();
275 if( style1 != style2 )
283 bool TestEqual( const TextViewProcessor::WordLayoutInfo& word1,
284 const TextViewProcessor::WordLayoutInfo& word2 )
286 if( !TestEqual( word1.mSize.x, word2.mSize.x ) )
290 if( !TestEqual( word1.mSize.y, word2.mSize.y ) )
295 if( !TestEqual( word1.mAscender, word2.mAscender ) )
300 if( word1.mType != word2.mType )
305 if( word1.mCharactersLayoutInfo.size() != word2.mCharactersLayoutInfo.size() )
310 for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it1 = word1.mCharactersLayoutInfo.begin(), endIt1 = word1.mCharactersLayoutInfo.end(),
311 it2 = word2.mCharactersLayoutInfo.begin(), endIt2 = word2.mCharactersLayoutInfo.end();
312 ( it1 != endIt1 ) && ( it2 != endIt2 );
315 if( !TestEqual( *it1, *it2 ) )
324 bool TestEqual( const TextViewProcessor::ParagraphLayoutInfo& paragraph1,
325 const TextViewProcessor::ParagraphLayoutInfo& paragraph2 )
327 if( !TestEqual( paragraph1.mSize.x, paragraph2.mSize.x ) )
331 if( !TestEqual( paragraph1.mSize.y, paragraph2.mSize.y ) )
336 if( !TestEqual( paragraph1.mAscender, paragraph2.mAscender ) )
341 if( paragraph1.mNumberOfCharacters != paragraph2.mNumberOfCharacters )
346 if( paragraph1.mWordsLayoutInfo.size() != paragraph2.mWordsLayoutInfo.size() )
351 for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it1 = paragraph1.mWordsLayoutInfo.begin(), endIt1 = paragraph1.mWordsLayoutInfo.end(),
352 it2 = paragraph2.mWordsLayoutInfo.begin(), endIt2 = paragraph2.mWordsLayoutInfo.end();
353 ( it1 != endIt1 ) && ( it2 != endIt2 );
356 if( !TestEqual( *it1, *it2 ) )
365 bool TestEqual( const TextViewProcessor::TextLayoutInfo& text1,
366 const TextViewProcessor::TextLayoutInfo& text2 )
368 if( !TestEqual( text1.mWholeTextSize.x, text2.mWholeTextSize.x ) )
372 if( !TestEqual( text1.mWholeTextSize.y, text2.mWholeTextSize.y ) )
377 if( !TestEqual( text1.mMaxWordWidth, text2.mMaxWordWidth ) )
382 if( text1.mNumberOfCharacters != text2.mNumberOfCharacters )
387 if( text1.mParagraphsLayoutInfo.size() != text2.mParagraphsLayoutInfo.size() )
392 for( TextViewProcessor::ParagraphLayoutInfoContainer::const_iterator it1 = text1.mParagraphsLayoutInfo.begin(), endIt1 = text1.mParagraphsLayoutInfo.end(),
393 it2 = text2.mParagraphsLayoutInfo.begin(), endIt2 = text2.mParagraphsLayoutInfo.end();
394 ( it1 != endIt1 ) && ( it2 != endIt2 );
397 if( !TestEqual( *it1, *it2 ) )
407 * Splits the \e input word in two by the given \e position and checks the results with \e firstResult and \e lastResult.
409 * If the test fails it prints a short description and the line where this function was called.
411 * @param description Short description of the experiment. i.e. "Split the word from the beginning. (position 0)".
412 * @param input The input word.
413 * @param position Where to split the word.
414 * @param firstResult First part of the split word.
415 * @param lastResult Last part of the split word.
416 * @param location Where this function has been called.
418 * @return \e true if the experiment is successful. Otherwise returns \e false.
420 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 )
422 tet_printf( "%s\n", description.c_str() );
424 // Create layout info for the input word.
425 Toolkit::Internal::TextView::RelayoutData relayoutData;
426 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
428 MarkupProcessor::StyledTextArray inputStyledText;
429 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
431 TextViewProcessor::CreateTextInfo( inputStyledText,
432 DEFAULT_LAYOUT_PARAMETERS,
435 // Get the input word
436 TextViewProcessor::WordLayoutInfo inputWordLayout;
438 if( !inputLayout.mParagraphsLayoutInfo.empty() )
440 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLayout.mParagraphsLayoutInfo.begin() );
441 if( !paragraph.mWordsLayoutInfo.empty() )
443 inputWordLayout = *( *inputLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
447 // Create layout info for the first part of the result (after split the word)
449 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
450 TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo );
452 MarkupProcessor::StyledTextArray firstResultStyledText;
453 MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true );
455 TextViewProcessor::CreateTextInfo( firstResultStyledText,
456 DEFAULT_LAYOUT_PARAMETERS,
459 // Get the first result word
460 TextViewProcessor::WordLayoutInfo firstResultWordLayout;
462 if( !firstResultLayout.mParagraphsLayoutInfo.empty() )
464 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *firstResultLayout.mParagraphsLayoutInfo.begin() );
465 if( !paragraph.mWordsLayoutInfo.empty() )
467 firstResultWordLayout = *( *firstResultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
471 // Create layout info for the last part of the result (after split the word)
473 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
474 TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo );
476 MarkupProcessor::StyledTextArray lastResultStyledText;
477 MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true );
479 TextViewProcessor::CreateTextInfo( lastResultStyledText,
480 DEFAULT_LAYOUT_PARAMETERS,
483 // Get the last result word
484 TextViewProcessor::WordLayoutInfo lastResultWordLayout;
486 if( !lastResultLayout.mParagraphsLayoutInfo.empty() )
488 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *lastResultLayout.mParagraphsLayoutInfo.begin() );
489 if( !paragraph.mWordsLayoutInfo.empty() )
491 lastResultWordLayout = *( *lastResultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
497 TextViewProcessor::WordLayoutInfo lastWordLayoutInfo;
501 lastWordLayoutInfo );
504 if( !TestEqual( inputWordLayout, firstResultWordLayout ) )
506 tet_printf( "Fail. different layout info. %s\n", location );
510 if( !TestEqual( lastWordLayoutInfo, lastResultWordLayout ) )
512 tet_printf( "Fail. different layout info. %s\n", location );
520 * Splits the \e input paragraph in two by the given \e wordIndex and \e characterIndex and checks the results with \e firstResult and \e lastResult.
522 * If the test fails it prints a short description and the line where this function was called.
524 * @param description Short description of the experiment. i.e. "Split the paragraph from the beginning. (wordIndex 0 and characterIndex 0)".
525 * @param input The input word.
526 * @param wordIndex Index to the word within the paragraph where to split it.
527 * @param characterIndex Where to split the word.
528 * @param characterIndex Character index within the paragraph.
529 * @param lineHeightOffset Offset between lines.
530 * @param firstResult First part of the split paragraph.
531 * @param lastResult Last part of the split paragraph.
532 * @param location Where this function has been called.
534 * @return \e true if the experiment is successful. Otherwise returns \e false.
536 bool TestSplitParagraph( const std::string& description,
537 const std::string& input,
539 size_t characterIndex,
540 size_t characterParagraphIndex,
541 float lineHeightOffset,
542 const std::string& firstResult,
543 const std::string& lastResult,
544 const char* location )
546 tet_printf( "%s\n", description.c_str() );
548 // Create layout info for the input paragraph.
549 Toolkit::Internal::TextView::RelayoutData relayoutData;
550 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
552 MarkupProcessor::StyledTextArray inputStyledText;
553 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
555 TextViewProcessor::CreateTextInfo( inputStyledText,
556 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
557 Toolkit::TextView::Original,
558 Toolkit::TextView::Original,
559 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
560 Toolkit::TextView::Center,
561 PointSize( lineHeightOffset ),
565 // Get the input paragraph
566 TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout;
568 if( !inputLayout.mParagraphsLayoutInfo.empty() )
570 inputParagraphLayout = *inputLayout.mParagraphsLayoutInfo.begin();
573 // Create layout info for the first part of the result (after split the paragraph)
575 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
576 TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo );
578 MarkupProcessor::StyledTextArray firstResultStyledText;
579 MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true );
581 TextViewProcessor::CreateTextInfo( firstResultStyledText,
582 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
583 Toolkit::TextView::Original,
584 Toolkit::TextView::Original,
585 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
586 Toolkit::TextView::Center,
587 PointSize( lineHeightOffset ),
591 // Get the first result paragraph
592 TextViewProcessor::ParagraphLayoutInfo firstResultParagraphLayout;
594 if( !firstResultLayout.mParagraphsLayoutInfo.empty() )
596 firstResultParagraphLayout = *firstResultLayout.mParagraphsLayoutInfo.begin();
599 // Create layout info for the last part of the result (after split the paragraph)
601 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
602 TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo );
604 MarkupProcessor::StyledTextArray lastResultStyledText;
605 MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true );
607 TextViewProcessor::CreateTextInfo( lastResultStyledText,
608 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
609 Toolkit::TextView::Original,
610 Toolkit::TextView::Original,
611 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
612 Toolkit::TextView::Center,
613 PointSize( lineHeightOffset ),
617 // Get the last result paragraph
618 TextViewProcessor::ParagraphLayoutInfo lastResultParagraphLayout;
620 if( !lastResultLayout.mParagraphsLayoutInfo.empty() )
622 lastResultParagraphLayout = *lastResultLayout.mParagraphsLayoutInfo.begin();
625 // Split the paragraph.
627 TextViewProcessor::ParagraphLayoutInfo lastParagraphLayoutInfo;
629 TextViewProcessor::TextInfoIndices indices( 0, wordIndex, characterIndex );
630 indices.mCharacterParagraphIndex = characterParagraphIndex;
632 SplitParagraph( indices,
633 PointSize( lineHeightOffset ),
634 inputParagraphLayout,
635 lastParagraphLayoutInfo );
638 if( !TestEqual( inputParagraphLayout, firstResultParagraphLayout ) )
640 tet_printf( "Fail. different first layout info. %s\n", location );
644 if( !TestEqual( lastParagraphLayoutInfo, lastResultParagraphLayout ) )
646 tet_printf( "Fail. different last layout info. %s\n", location );
654 * Merges the \e inputFirst word and the \e inputLast word, and checks the results with \e result.
656 * If the test fails it prints a short description and the line where this function was called.
658 * @param description Short description of the experiment. i.e. "Merge two words with same style".
659 * @param inputFirst The first part of the word.
660 * @param inputLast The last part of the word.
661 * @param result The merged word.
662 * @param location Where this function has been called.
664 * @return \e true if the experiment is successful. Otherwise returns \e false.
666 bool TestMergeWords( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const std::string& result, const char* location )
668 tet_printf( "%s\n", description.c_str() );
670 // Create layout info for the inputFirst word.
671 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
672 TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo );
674 MarkupProcessor::StyledTextArray inputFirstStyledText;
675 MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true );
677 TextViewProcessor::CreateTextInfo( inputFirstStyledText,
678 DEFAULT_LAYOUT_PARAMETERS,
681 // Get the input word
682 TextViewProcessor::WordLayoutInfo inputFirstWordLayout;
684 if( !inputFirstLayout.mParagraphsLayoutInfo.empty() )
686 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputFirstLayout.mParagraphsLayoutInfo.begin() );
687 if( !paragraph.mWordsLayoutInfo.empty() )
689 inputFirstWordLayout = *( *inputFirstLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
693 // Create layout info for the inputLast word.
694 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
695 TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo );
697 MarkupProcessor::StyledTextArray inputLastStyledText;
698 MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true );
700 TextViewProcessor::CreateTextInfo( inputLastStyledText,
701 DEFAULT_LAYOUT_PARAMETERS,
704 // Get the input word
705 TextViewProcessor::WordLayoutInfo inputLastWordLayout;
707 if( !inputLastLayout.mParagraphsLayoutInfo.empty() )
709 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLastLayout.mParagraphsLayoutInfo.begin() );
710 if( !paragraph.mWordsLayoutInfo.empty() )
712 inputLastWordLayout = *( *inputLastLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
716 // Create layout info for the result word.
717 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
718 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
720 MarkupProcessor::StyledTextArray resultStyledText;
721 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
723 TextViewProcessor::CreateTextInfo( resultStyledText,
724 DEFAULT_LAYOUT_PARAMETERS,
725 resultRelayoutData );
727 // Get the result word
728 TextViewProcessor::WordLayoutInfo resultWordLayout;
730 if( !resultLayout.mParagraphsLayoutInfo.empty() )
732 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *resultLayout.mParagraphsLayoutInfo.begin() );
733 if( !paragraph.mWordsLayoutInfo.empty() )
735 resultWordLayout = *( *resultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
739 MergeWord( inputFirstWordLayout,
740 inputLastWordLayout );
742 if( !TestEqual( inputFirstWordLayout, resultWordLayout ) )
744 tet_printf( "Fail. different layout info. %s\n", location );
752 * Merges the \e inputFirst paragraph and the \e inputLast paragraph, and checks the results with \e result.
754 * If the test fails it prints a short description and the line where this function was called.
756 * @param description Short description of the experiment.
757 * @param inputFirst The first part of the paragraph.
758 * @param inputLast The last part of the paragraph.
759 * @param lineHeightOffset Offset between lines.
760 * @param result The merged paragraph.
761 * @param location Where this function has been called.
763 * @return \e true if the experiment is successful. Otherwise returns \e false.
765 bool TestMergeParagraphs( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const float lineHeightOffset, const std::string& result, const char* location )
767 tet_printf( "%s\n", description.c_str() );
769 // Create layout info for the inputFirst paragraph.
770 Toolkit::Internal::TextView::RelayoutData firstRelayoutData;
771 TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo );
773 MarkupProcessor::StyledTextArray inputFirstStyledText;
774 MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true );
776 TextViewProcessor::CreateTextInfo( inputFirstStyledText,
777 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
778 Toolkit::TextView::Original,
779 Toolkit::TextView::Original,
780 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
781 Toolkit::TextView::Center,
782 PointSize( lineHeightOffset ),
786 // Get the input word
787 TextViewProcessor::ParagraphLayoutInfo inputFirstParagraphLayout;
789 if( !inputFirstLayout.mParagraphsLayoutInfo.empty() )
791 inputFirstParagraphLayout = *inputFirstLayout.mParagraphsLayoutInfo.begin();
794 // Create layout info for the inputLast paragraph.
795 Toolkit::Internal::TextView::RelayoutData lastRelayoutData;
796 TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo );
798 MarkupProcessor::StyledTextArray inputLastStyledText;
799 MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true );
801 TextViewProcessor::CreateTextInfo( inputLastStyledText,
802 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
803 Toolkit::TextView::Original,
804 Toolkit::TextView::Original,
805 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
806 Toolkit::TextView::Center,
807 PointSize( lineHeightOffset ),
811 // Get the input word
812 TextViewProcessor::ParagraphLayoutInfo inputLastParagraphLayout;
814 if( !inputLastLayout.mParagraphsLayoutInfo.empty() )
816 inputLastParagraphLayout = *inputLastLayout.mParagraphsLayoutInfo.begin();
819 // Create layout info for the result word.
820 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
821 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
823 MarkupProcessor::StyledTextArray resultStyledText;
824 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
826 TextViewProcessor::CreateTextInfo( resultStyledText,
827 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
828 Toolkit::TextView::Original,
829 Toolkit::TextView::Original,
830 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
831 Toolkit::TextView::Center,
832 PointSize( lineHeightOffset ),
834 resultRelayoutData );
836 // Get the result word
837 TextViewProcessor::ParagraphLayoutInfo resultParagraphLayout;
839 if( !resultLayout.mParagraphsLayoutInfo.empty() )
841 resultParagraphLayout = *resultLayout.mParagraphsLayoutInfo.begin();
844 MergeParagraph( inputFirstParagraphLayout,
845 inputLastParagraphLayout );
847 if( !TestEqual( inputFirstParagraphLayout, resultParagraphLayout ) )
849 tet_printf( "Fail. different layout info. %s\n", location );
857 * Removes from the \e input word the \e numberOfCharacters characters starting from the given \e position and checks the results with \e result.
859 * If the test fails it prints a short description and the line where this function was called.
861 * @param description Short description of the experiment. i.e. "Remove a whole word. Merge".
862 * @param input The input word.
863 * @param position Where to start to remove characters
864 * @param numberOfCharacters The number of characters to remove.
865 * @param result The word without the removed characters.
866 * @param location Where this function has been called.
868 * @return \e true if the experiment is successful. Otherwise returns \e false.
870 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 )
872 tet_printf( "%s\n", description.c_str() );
874 // Create layout info for the input word.
875 Toolkit::Internal::TextView::RelayoutData relayoutData;
876 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
878 MarkupProcessor::StyledTextArray inputStyledText;
879 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
881 TextViewProcessor::CreateTextInfo( inputStyledText,
882 DEFAULT_LAYOUT_PARAMETERS,
885 // Get the input word
886 TextViewProcessor::WordLayoutInfo inputWordLayout;
888 if( !inputLayout.mParagraphsLayoutInfo.empty() )
890 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLayout.mParagraphsLayoutInfo.begin() );
891 if( !paragraph.mWordsLayoutInfo.empty() )
893 inputWordLayout = *( *inputLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
897 // Create layout info for the result word.
898 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
899 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
901 MarkupProcessor::StyledTextArray resultStyledText;
902 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
904 TextViewProcessor::CreateTextInfo( resultStyledText,
905 DEFAULT_LAYOUT_PARAMETERS,
906 resultRelayoutData );
908 // Get the result word
909 TextViewProcessor::WordLayoutInfo resultWordLayout;
911 if( !resultLayout.mParagraphsLayoutInfo.empty() )
913 const TextViewProcessor::ParagraphLayoutInfo& paragraph( *resultLayout.mParagraphsLayoutInfo.begin() );
914 if( !paragraph.mWordsLayoutInfo.empty() )
916 resultWordLayout = *( *resultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
920 RemoveCharactersFromWord( position,
924 if( !TestEqual( inputWordLayout, resultWordLayout ) )
926 tet_printf( "Fail. different layout info. %s\n", location );
934 * Removes from the \e input paragraph the \e numberOfWords words starting from the given \e wordIndex and checks the results with \e result.
936 * If the test fails it prints a short description and the line where this function was called.
938 * @param description Short description of the experiment.
939 * @param input The input paragraph.
940 * @param wordIndex Index within the paragraph where to start to remove words.
941 * @param numberOfWords The number of words to remove.
942 * @param lineHeightOffset Offset between lines.
943 * @param result The paragraph without the removed words.
944 * @param location Where this function has been called.
946 * @return \e true if the experiment is successful. Otherwise returns \e false.
948 bool TestRemoveWordsFromParagraph( 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 )
950 tet_printf( "%s\n", description.c_str() );
952 // Create layout info for the input paragraph.
953 Toolkit::Internal::TextView::RelayoutData relayoutData;
954 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
956 MarkupProcessor::StyledTextArray inputStyledText;
957 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
959 TextViewProcessor::CreateTextInfo( inputStyledText,
960 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
961 Toolkit::TextView::Original,
962 Toolkit::TextView::Original,
963 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
964 Toolkit::TextView::Center,
965 PointSize( lineHeightOffset ),
969 // Get the input paragraph
970 TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout;
972 if( !inputLayout.mParagraphsLayoutInfo.empty() )
974 inputParagraphLayout = *inputLayout.mParagraphsLayoutInfo.begin();
977 // Create layout info for the result paragraph.
978 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
979 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
981 MarkupProcessor::StyledTextArray resultStyledText;
982 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
984 TextViewProcessor::CreateTextInfo( resultStyledText,
985 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
986 Toolkit::TextView::Original,
987 Toolkit::TextView::Original,
988 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
989 Toolkit::TextView::Center,
990 PointSize( lineHeightOffset ),
992 resultRelayoutData );
994 // Get the result paragraph
995 TextViewProcessor::ParagraphLayoutInfo resultParagraphLayout;
997 if( !resultLayout.mParagraphsLayoutInfo.empty() )
999 resultParagraphLayout = *resultLayout.mParagraphsLayoutInfo.begin();
1002 RemoveWordsFromParagraph( wordIndex,
1005 inputParagraphLayout );
1007 if( !TestEqual( inputParagraphLayout, resultParagraphLayout ) )
1009 tet_printf( "Fail. different layout info. %s\n", location );
1010 tet_printf( " input : [%s]\n", input.c_str() );
1011 tet_printf( " result : [%s]\n", GetText( resultParagraphLayout ).c_str() );
1012 tet_printf( " expected result : [%s]\n\n", result.c_str() );
1014 Print(inputParagraphLayout); std::cout << std::endl << std::endl;
1015 Print(resultParagraphLayout); std::cout << std::endl;
1023 * Tests inserts, removes and updates operation in the given \e input text and checks with the given \e result.
1025 * If the test fails it prints a short description and the line where this function was called.
1027 * @param description Short description of the experiment.
1028 * @param operation Type of update operation (insert, remove, replace)
1029 * @param input The input text.
1030 * @param position Where to insert, remove or replace text.
1031 * @param numberOfCharacters Number of characters to remove or replace.
1032 * @param inputText Inserted or updated text.
1033 * @param lineHeightOffset Offset between lines.
1034 * @param result Expected result.
1035 * @param location Where this function has been called.
1037 * @return \e true if the experiment is successful. Otherwise returns \e false.
1039 bool TestUpdateTextInfo( const std::string& description,
1040 UpdateTextInfoOperation operation,
1041 const std::string& input,
1042 std::size_t position,
1043 std::size_t numberOfCharacters,
1044 const std::string& inputText,
1045 float lineHeightOffset,
1046 const std::string& result,
1047 const char* location )
1049 tet_printf( "%s\n", description.c_str() );
1051 // Create layout info for the input.
1052 Toolkit::Internal::TextView::RelayoutData relayoutData;
1053 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
1055 MarkupProcessor::StyledTextArray inputStyledText;
1056 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
1058 TextViewProcessor::CreateTextInfo( inputStyledText,
1059 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1060 Toolkit::TextView::Original,
1061 Toolkit::TextView::Original,
1062 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1063 Toolkit::TextView::Center,
1064 PointSize( lineHeightOffset ),
1068 // Create layout info for the result.
1069 Toolkit::Internal::TextView::RelayoutData resultRelayoutData;
1070 TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo );
1072 MarkupProcessor::StyledTextArray resultStyledText;
1073 MarkupProcessor::GetStyledTextArray( result, resultStyledText, true );
1075 TextViewProcessor::CreateTextInfo( resultStyledText,
1076 Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar,
1077 Toolkit::TextView::Original,
1078 Toolkit::TextView::Original,
1079 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1080 Toolkit::TextView::Center,
1081 PointSize( lineHeightOffset ),
1083 resultRelayoutData );
1085 // Choose operation and call appropiate UpdateTextInfo() method.
1086 const Toolkit::Internal::TextView::LayoutParameters layoutParameters( Toolkit::TextView::SplitByNewLineChar,
1087 Toolkit::TextView::Original,
1088 Toolkit::TextView::Original,
1089 static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ),
1090 Toolkit::TextView::Center,
1091 PointSize( lineHeightOffset ),
1098 MarkupProcessor::StyledTextArray inputStyledText;
1099 MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true );
1101 TextViewProcessor::UpdateTextInfo( position,
1109 TextViewProcessor::UpdateTextInfo( position,
1113 TextViewProcessor::CLEAR_TEXT );
1118 MarkupProcessor::StyledTextArray inputStyledText;
1119 MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true );
1121 TextViewProcessor::UpdateTextInfo( position,
1130 tet_printf( "TestUpdateTextInfo: unknown update operation. %s\n", location );
1135 if( !TestEqual( inputLayout, resultLayout ) )
1137 tet_printf( "Fail. different layout info. %s\n", location );
1139 // std::cout << " result : "; Print( inputLayout );
1140 // std::cout << " expected result : "; Print( resultLayout );
1150 int UtcDaliTextViewCreateTextInfo(void)
1152 ToolkitTestApplication application;
1154 tet_infoline("UtcDaliTextViewCreateTextInfo : ");
1156 // Metrics for characters
1159 // size : [9.48351, 9.48351]
1160 // advance : 9.48351
1161 // bearing : 8.53516
1162 // ascender : 8.53516
1165 // size : [11.3802, 11.3802]
1166 // advance : 11.3802
1167 // bearing : 10.2422
1168 // ascender : 10.2422
1171 // size : [13.2769, 13.2769]
1172 // advance : 13.2769
1173 // bearing : 11.9492
1174 // ascender : 11.9492
1176 const float HEIGHT_10( 9.48351f );
1177 const float ADVANCE_10( 9.48351f );
1178 const float BEARING_10( 8.53516f );
1179 const float ASCENDER_10( 8.53516f );
1181 const float HEIGHT_12( 11.3802f );
1182 const float ADVANCE_12( 11.3802f );
1183 const float BEARING_12( 10.2422f );
1184 const float ASCENDER_12( 10.2422f );
1188 Toolkit::Internal::TextView::RelayoutData relayoutData;
1189 TextViewProcessor::TextLayoutInfo& textLayoutInfo( relayoutData.mTextLayoutInfo );
1191 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
1194 MarkupProcessor::StyledTextArray styledText;
1195 MarkupProcessor::GetStyledTextArray( text, styledText, true );
1197 TextViewProcessor::CreateTextInfo( styledText,
1198 DEFAULT_LAYOUT_PARAMETERS,
1202 // Build the text info with metric values.
1206 TextViewProcessor::CharacterLayoutInfo layoutInfo10; // ( [lo wo])
1207 layoutInfo10.mSize.height = HEIGHT_10;
1208 layoutInfo10.mSize.width = ADVANCE_10;
1209 layoutInfo10.mBearing = BEARING_10;
1210 layoutInfo10.mAscender = ASCENDER_10;
1211 TextViewProcessor::CharacterLayoutInfo layoutInfo12; // ( [Hel], [rld!] and [CR])
1212 layoutInfo12.mSize.height = HEIGHT_12;
1213 layoutInfo12.mSize.width = ADVANCE_12;
1214 layoutInfo12.mBearing = BEARING_12;
1215 layoutInfo12.mAscender = ASCENDER_12;
1219 TextViewProcessor::WordLayoutInfo wordLayout1, wordLayout2, wordLayout3, wordLayout4;
1222 wordLayout1.mSize = Size( 3.f * ADVANCE_12 + 2.f * ADVANCE_10, HEIGHT_12 );
1223 wordLayout1.mAscender = ASCENDER_12;
1224 wordLayout1.mType = TextViewProcessor::NoSeparator;
1226 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // H
1227 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // e
1228 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l
1229 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // l
1230 wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o
1233 wordLayout2.mSize = Size( ADVANCE_10, HEIGHT_10 );
1234 wordLayout2.mAscender = ASCENDER_10;
1235 wordLayout2.mType = TextViewProcessor::WordSeparator;
1236 wordLayout2.mCharactersLayoutInfo.push_back( layoutInfo10 ); // (white space)
1239 wordLayout3.mSize = Size( 2.f * ADVANCE_10 + 4.f * ADVANCE_12, HEIGHT_12 );
1240 wordLayout3.mAscender = ASCENDER_12;
1241 wordLayout3.mType = TextViewProcessor::NoSeparator;
1242 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // w
1243 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o
1244 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // r
1245 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l
1246 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // d
1247 wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // !
1249 // (new paragraph character)
1250 wordLayout4.mSize = Size( 0.f, HEIGHT_12 );
1251 wordLayout4.mAscender = ASCENDER_12;
1252 wordLayout4.mType = TextViewProcessor::ParagraphSeparator;
1253 layoutInfo12.mSize.width = 0.f;
1254 wordLayout4.mCharactersLayoutInfo.push_back( layoutInfo12 ); // (new paragraph char)
1258 TextViewProcessor::ParagraphLayoutInfo paragraphLayout1, paragraphLayout2, paragraphLayout3;
1260 paragraphLayout1.mSize = Size( 5.f * ADVANCE_10 + 7.f * ADVANCE_12, HEIGHT_12 );
1261 paragraphLayout1.mAscender = ASCENDER_12;
1262 paragraphLayout1.mNumberOfCharacters = 13;
1263 paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout1 );
1264 paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout2 );
1265 paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout3 );
1266 paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout4 );
1268 paragraphLayout2.mSize = Size( 0.f, HEIGHT_12 );
1269 paragraphLayout2.mAscender = ASCENDER_12;
1270 paragraphLayout2.mNumberOfCharacters = 1;
1271 paragraphLayout2.mWordsLayoutInfo.push_back( wordLayout4 );
1273 paragraphLayout3.mSize = Size( 0.f, HEIGHT_12 );
1276 TextViewProcessor::TextLayoutInfo textLayout;
1278 textLayout.mWholeTextSize = Size( 5.f * ADVANCE_10 + 7.f * ADVANCE_12, 3.f * HEIGHT_12 );
1279 textLayout.mMaxWordWidth = 2.f * ADVANCE_10 + 4.f * ADVANCE_12;
1280 textLayout.mNumberOfCharacters = 14;
1281 textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout1 );
1282 textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout2 );
1283 textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout3 );
1285 if(!TestEqual( textLayout, textLayoutInfo ))
1287 std::cout << "Layout fails" << std::endl;
1288 Print(textLayout); std::cout << std::endl;
1289 Print(textLayoutInfo); std::cout << std::endl;
1292 DALI_TEST_CHECK( TestEqual( textLayout, textLayoutInfo ) );
1296 int UtcDaliTextViewSplitWord(void)
1298 ToolkitTestApplication application;
1300 tet_infoline("UtcDaliTextViewSplitWord : ");
1302 struct SplitWordTest splitWordTests[] =
1305 std::string( "Split word, position 0." ),
1306 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1309 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1312 std::string( "Split word, position 8." ),
1313 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1315 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1319 std::string( "Split word, position 2." ),
1320 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1322 std::string( "<font size='10'>He</font>" ),
1323 std::string( "<font size='12'>ll</font><font size='10'>oooo</font>" ),
1326 std::string( "Split word, position 3." ),
1327 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1329 std::string( "<font size='10'>He</font><font size='12'>l</font>" ),
1330 std::string( "<font size='12'>l</font><font size='10'>oooo</font>" ),
1333 std::string( "Split word, position 4." ),
1334 std::string( "<font size='10'>He<font size='12'>ll</font>oooo</font>" ),
1336 std::string( "<font size='10'>He</font><font size='12'>ll</font>" ),
1337 std::string( "<font size='10'>oooo</font>" ),
1340 const std::size_t numberOfTests( 5u );
1342 for( std::size_t index = 0u; index < numberOfTests; ++index )
1344 const SplitWordTest& test = splitWordTests[index];
1346 if( !TestSplitWord( test.description, test.input, test.position, test.firstResult, test.lastResult, TEST_LOCATION ) )
1348 tet_result( TET_FAIL );
1352 tet_result( TET_PASS );
1356 int UtcDaliTextViewUpdateTextInfo(void)
1358 ToolkitTestApplication application;
1360 tet_infoline("UtcDaliTextViewUpdateTextInfo : ");
1362 struct UpdateTextInfoTest updateTextInfoTest[] =
1364 // Remove operations
1367 std::string( "Remove from new paragraph character to first character next paragraph." ),
1369 std::string("Hello world\nhello world."),
1374 std::string("Hello worldello world."),
1377 std::string( "Replace style from new paragraph character to first character next paragraph." ),
1379 std::string("Hello world\nhello world."),
1382 std::string("<b>\nh</b>"),
1384 std::string("Hello world<b>\nh</b>ello world."),
1387 std::string( "Remove from the beginning to the middle of last word." ),
1389 std::string("Hello world, hello world."),
1392 std::string(), // Not used.
1397 std::string( "Remove from the beginning to the middle of the text." ),
1399 std::string("Hello world hello world."),
1402 std::string(), // Not used.
1404 std::string("hello world."),
1406 // Remove within the same word:
1407 // * within the same group of characters with same style.
1409 std::string( "Remove within the same word, within the same group of characters with same style" ),
1411 std::string("Hello <font size='30'>world\nhello</font> world"),
1414 std::string(), // Not used.
1416 std::string( "Hello <font size='30'>wd\nhello</font> world" )
1418 // * whole group of characters (merge adjacent group of characters)
1420 std::string( "Remove within the same word, whole group of characters (merge adjacent group of characters)" ),
1422 std::string("Hello <font size='30'>w<font size='20'>orl</font>d\nhello</font> world"),
1425 std::string(), // Not used.
1427 std::string( "Hello <font size='30'>wd\nhello</font> world" )
1429 // * whole group of characters (don't merge adjacent gtoup of characters)
1431 std::string( "Remove within the same word, whole group of characters (don't merge adjacent gtoup of characters)" ),
1433 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1436 std::string(), // Not used.
1438 std::string( "Hello <font size='30'>w</font><font size='10'>d\nhello</font> world" )
1440 // * Remove whole word (merge words)
1442 std::string( "Remove within the same word, whole word (merge words)" ),
1444 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1447 std::string(), // Not used.
1449 std::string( "Hello<font size='30'>w</font>orl<font size='10'>d\nhello</font> world" )
1451 // * Remove whole word (don't merge words)
1453 std::string( "Remove within the same word, whole word (don't merge words)" ),
1455 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1458 std::string(), // Not used.
1460 std::string( "Hello <font size='10'>\nhello</font> world" )
1462 // * Remove whole word (merge paragraphs)
1464 std::string( "Remove within the same word, whole word (merge paragraphs)" ),
1466 std::string("Hello <font size='30'>w</font>orl<font size='10'>d\nhello</font> world"),
1469 std::string(), // Not used.
1471 std::string( "Hello <font size='30'>w</font>orl<font size='10'>dhello</font> world" )
1473 // * Remove RTL text within LTR
1475 std::string( "Remove within the same paragraph, RTL text within LTR." ),
1477 std::string("Hello world, שלום עולם, hello world"),
1480 std::string(), // Not used.
1482 std::string( "Hello worlello world" )
1484 // * Remove whole paragraph
1486 std::string( "Remove whole paragraph" ),
1488 std::string("Hello world, hello world\n"
1489 "Hello world, hello world\n"
1490 "Hello world, hello world\n"
1491 "Hello world, hello world\n"),
1494 std::string(), // Not used.
1496 std::string("Hello world, hello world\n"
1497 "Hello world, hello world\n"
1498 "Hello world, hello world\n"),
1501 std::string( "Remove whole paragraph" ),
1503 std::string("Hello world, hello world\n"
1507 std::string(), // Not used.
1509 std::string("Hello world, hello world\n"),
1513 // Insert operations
1515 std::string( "insert some text" ),
1517 std::string("inpuext"),
1520 std::string( "t t" ),
1522 std::string( "input text" )
1525 std::string( "Insert text at the end" ),
1527 std::string("touch "),
1530 std::string("me\nhello"),
1532 std::string("touch me\nhello")
1535 // Replace operations.
1537 std::string( "Replace style from the beginning to some point in the middle of the text." ),
1539 std::string( "Hello <font color='green'>world</font>" ),
1542 std::string( "<font color='red'>Hello w</font>" ),
1544 std::string( "<font color='red'>Hello w</font><font color='green'>orld</font>" )
1547 std::string( "Replace style from the middle of the text to the end." ),
1549 std::string( "Touch me\nhello" ),
1552 std::string( "<b>me\nhello</b>" ),
1554 std::string( "Touch <b>me\nhello</b>" )
1557 std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 1." ),
1559 std::string( "Touch me\nhello\nworld" ),
1564 std::string( "Touch \nworld" )
1567 std::string( "Insert styled text in the middle of a text. Previous: Replace style from the middle of the text 1." ),
1569 std::string( "Touch \nworld" ),
1572 std::string( "<b>me\nhello</b>" ),
1574 std::string( "Touch <b>me\nhello</b>\nworld" )
1577 std::string( "Replace style from the middle of the text 1." ),
1579 std::string( "Touch me\nhello\nworld" ),
1582 std::string( "<b>me\nhello</b>" ),
1584 std::string( "Touch <b>me\nhello</b>\nworld" )
1587 std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 2." ),
1589 std::string( "Touch me\nhello\nworld" ),
1594 std::string( "Touch world" )
1597 std::string( "Replace style from the middle of the text 2." ),
1599 std::string( "Touch me\nhello\nworld" ),
1602 std::string( "<b>me\nhello\n</b>" ),
1604 std::string( "Touch <b>me\nhello\n</b>world" )
1607 const std::size_t numberOfTests( 22u );
1609 for( std::size_t index = 0u; index < numberOfTests; ++index )
1611 const UpdateTextInfoTest& test = updateTextInfoTest[index];
1613 if( !TestUpdateTextInfo( test.description, test.operation, test.input, test.position, test.numberOfCharacters, test.inputText, test.lineHeightOffset, test.result, TEST_LOCATION ) )
1615 tet_result( TET_FAIL );
1619 tet_result( TET_PASS );
1623 int UtcDaliTextViewSplitParagraph(void)
1625 ToolkitTestApplication application;
1627 tet_infoline("UtcDaliTextViewSplitParagraph : ");
1629 struct SplitParagraphTest splitParagraphTests[] =
1632 std::string( "Split paragraph, wordPosition 0, position 0." ),
1633 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1639 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1642 std::string( "Split paragraph, wordPosition 10, position 4." ),
1643 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1648 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1652 std::string( "Split paragraph, wordPosition 2, position 4." ),
1653 std::string("<font size='10'>Hello </font>wor<font size='12'>ld, hello wo</font>rld"),
1658 std::string("<font size='10'>Hello </font>wor<font size='12'>l</font>"),
1659 std::string("<font size='12'>d, hello wo</font>rld")
1662 std::string( "Split paragraph, wordPosition 6, position 0." ),
1663 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1668 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום " ),
1669 std::string( "עולם text text" ),
1672 std::string( "Split paragraph, wordPosition 4, position 0." ),
1673 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1678 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> " ),
1679 std::string( "שלום עולם text text" ),
1682 std::string( "Split paragraph2, wordPosition 8, position 0." ),
1683 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם text text" ),
1688 std::string( "<font size='10'>He<font size='12'>ll</font>oooo wooorld</font> שלום עולם " ),
1689 std::string( "text text" ),
1692 const std::size_t numberOfTests( 6u );
1694 for( std::size_t index = 0u; index < numberOfTests; ++index )
1696 const SplitParagraphTest& test = splitParagraphTests[index];
1698 if( !TestSplitParagraph( test.description,
1701 test.characterIndex,
1702 test.characterParagraphIndex,
1703 test.lineHeightOffset,
1708 tet_result( TET_FAIL );
1712 tet_result( TET_PASS );
1716 int UtcDaliTextViewMergeWord01(void)
1718 ToolkitTestApplication application;
1720 tet_infoline("UtcDaliTextViewMergeWord01 : ");
1722 struct MergeWordsTest mergeWordsTests[] =
1725 std::string( "Merge words with same style." ),
1726 std::string( "Hel" ),
1727 std::string( "lo" ),
1728 std::string( "Hello" ),
1731 std::string( "Merge words with different styles." ),
1732 std::string( "<font size='10>Hel</font>" ),
1733 std::string( "<font size='20'>lo</font>" ),
1734 std::string( "<font size='10'>Hel</font><font size='20'>lo</font>" )
1737 const std::size_t numberOfTests( 2u );
1739 for( std::size_t index = 0u; index < numberOfTests; ++index )
1741 const MergeWordsTest& test = mergeWordsTests[index];
1743 if( !TestMergeWords( test.description, test.inputFirst, test.inputLast, test.result, TEST_LOCATION ) )
1745 tet_result( TET_FAIL );
1749 tet_result( TET_PASS );
1753 int UtcDaliTextViewMergeWord02(void)
1756 // It test white spaces and new paragraph characters can't be merged to other words.
1758 ToolkitTestApplication application;
1760 tet_infoline("UtcDaliTextViewMergeWord02 : ");
1762 // Generate three words
1764 Toolkit::Internal::TextView::RelayoutData relayoutData01;
1765 Toolkit::Internal::TextView::RelayoutData relayoutData02;
1766 Toolkit::Internal::TextView::RelayoutData relayoutData03;
1767 TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo );
1768 TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo );
1769 TextViewProcessor::TextLayoutInfo& textLayoutInfo03( relayoutData03.mTextLayoutInfo );
1771 std::string text01( " " );
1772 std::string text02( "\n" );
1773 std::string text03( "a" );
1774 MarkupProcessor::StyledTextArray styledText01;
1775 MarkupProcessor::StyledTextArray styledText02;
1776 MarkupProcessor::StyledTextArray styledText03;
1777 MarkupProcessor::GetStyledTextArray( text01, styledText01, true );
1778 MarkupProcessor::GetStyledTextArray( text02, styledText02, true );
1779 MarkupProcessor::GetStyledTextArray( text03, styledText03, true );
1781 TextViewProcessor::CreateTextInfo( styledText01,
1782 DEFAULT_LAYOUT_PARAMETERS,
1785 TextViewProcessor::WordLayoutInfo wordLayoutInfo01;
1787 wordLayoutInfo01 = *( *textLayoutInfo01.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1789 TextViewProcessor::CreateTextInfo( styledText02,
1790 DEFAULT_LAYOUT_PARAMETERS,
1793 TextViewProcessor::WordLayoutInfo wordLayoutInfo02;
1795 wordLayoutInfo02 = *( *textLayoutInfo02.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1797 TextViewProcessor::CreateTextInfo( styledText03,
1798 DEFAULT_LAYOUT_PARAMETERS,
1801 TextViewProcessor::WordLayoutInfo wordLayoutInfo03;
1803 wordLayoutInfo03 = *( *textLayoutInfo03.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin();
1805 // Test MergeWord() asserts if white spaces or new paragraph chars are merged.
1806 bool assert1 = false;
1807 bool assert2 = false;
1808 bool assert3 = false;
1809 bool assert4 = false;
1810 bool assert5 = false;
1811 bool assert6 = false;
1815 MergeWord( wordLayoutInfo01,
1818 catch( Dali::DaliException& e )
1820 DALI_TEST_PRINT_ASSERT( e );
1821 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1826 MergeWord( wordLayoutInfo01,
1829 catch( Dali::DaliException& e )
1831 DALI_TEST_PRINT_ASSERT( e );
1832 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1837 MergeWord( wordLayoutInfo02,
1840 catch( Dali::DaliException& e )
1842 DALI_TEST_PRINT_ASSERT( e );
1843 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1848 MergeWord( wordLayoutInfo02,
1851 catch( Dali::DaliException& e )
1853 DALI_TEST_PRINT_ASSERT( e );
1854 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1859 MergeWord( wordLayoutInfo03,
1862 catch( Dali::DaliException& e )
1864 DALI_TEST_PRINT_ASSERT( e );
1865 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1870 MergeWord( wordLayoutInfo03,
1873 catch( Dali::DaliException& e )
1875 DALI_TEST_PRINT_ASSERT( e );
1876 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION );
1880 if( assert1 && assert2 && assert3 && assert4 && assert5 && assert6 )
1882 tet_result( TET_PASS );
1886 tet_result( TET_FAIL );
1891 int UtcDaliTextViewMergeParagraph01(void)
1893 ToolkitTestApplication application;
1895 tet_infoline("UtcDaliTextViewMergeParagraph01 : ");
1897 struct MergeParagraphsTest mergeParagraphsTests[] =
1900 std::string( "Merge a void first paragraph." ),
1902 std::string( "Hello world, this is a whole paragraph" ),
1904 std::string( "Hello world, this is a whole paragraph" )
1907 std::string( "Merge a void last paragraph." ),
1908 std::string( "Hello world, this is a whole paragraph" ),
1911 std::string( "Hello world, this is a whole paragraph" )
1914 std::string( "Merge paragraphs: last starting with RTL text and first ending with RTL" ),
1915 std::string( "Hello world, שלום" ),
1916 std::string( " עולם, hello world." ),
1918 std::string( "Hello world, שלום עולם, hello world." )
1921 std::string( "Merge paragraphs and don't merge last and first words." ),
1922 std::string( "Hello world, " ),
1923 std::string( "שלום עולם, hello world." ),
1925 std::string( "Hello world, שלום עולם, hello world." )
1928 std::string( "Merge paragraphs. Don't merge words" ),
1929 std::string( "Hello world," ),
1930 std::string( " this is a whole paragraph" ),
1932 std::string( "Hello world, this is a whole paragraph" )
1935 std::string( "Merge paragraphs. Merge words" ),
1936 std::string( "Hello world, th" ),
1937 std::string( "is is a whole paragraph" ),
1939 std::string( "Hello world, this is a whole paragraph" )
1942 const std::size_t numberOfTests( 6u );
1944 for( std::size_t index = 0u; index < numberOfTests; ++index )
1946 const MergeParagraphsTest& test = mergeParagraphsTests[index];
1948 if( !TestMergeParagraphs( test.description, test.inputFirst, test.inputLast, test.lineHeightOffset, test.result, TEST_LOCATION ) )
1950 tet_result( TET_FAIL );
1954 tet_result( TET_PASS );
1958 int UtcDaliTextViewMergeParagraph02(void)
1960 ToolkitTestApplication application;
1962 tet_infoline("UtcDaliTextViewMergeParagraph02 : ");
1964 Toolkit::Internal::TextView::RelayoutData relayoutData01;
1965 Toolkit::Internal::TextView::RelayoutData relayoutData02;
1966 TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo );
1967 TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo );
1969 std::string text01( "Hello world\n" );
1970 std::string text02( "hello world" );
1971 MarkupProcessor::StyledTextArray styledText01;
1972 MarkupProcessor::StyledTextArray styledText02;
1973 MarkupProcessor::GetStyledTextArray( text01, styledText01, true );
1974 MarkupProcessor::GetStyledTextArray( text02, styledText02, true );
1976 TextViewProcessor::CreateTextInfo( styledText01,
1977 DEFAULT_LAYOUT_PARAMETERS,
1980 TextViewProcessor::ParagraphLayoutInfo paragraphLayoutInfo01;
1982 paragraphLayoutInfo01 = *textLayoutInfo01.mParagraphsLayoutInfo.begin();
1984 TextViewProcessor::CreateTextInfo( styledText02,
1985 DEFAULT_LAYOUT_PARAMETERS,
1988 TextViewProcessor::ParagraphLayoutInfo paragraphLayoutInfo02;
1990 paragraphLayoutInfo02 = *textLayoutInfo02.mParagraphsLayoutInfo.begin();
1992 bool assert1 = false;
1996 MergeParagraph( paragraphLayoutInfo01,
1997 paragraphLayoutInfo02 );
1999 catch( Dali::DaliException& e )
2001 DALI_TEST_PRINT_ASSERT( e );
2002 DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeParagraph(). ERROR: A paragraph can't be merged to another paragraph which finishes with a new paragraph character.\"", TEST_LOCATION );
2008 tet_result( TET_PASS );
2012 tet_result( TET_FAIL );
2017 int UtcDaliTextViewRemoveCharactersFromWord(void)
2019 ToolkitTestApplication application;
2021 tet_infoline("UtcDaliTextViewMergeWord02 : ");
2023 struct RemoveCharactersFromWordTest removeCharactersFromWordTests[] =
2026 std::string( "Delete 0 characters." ),
2027 std::string( "Hello" ),
2030 std::string( "Hello" ),
2033 std::string( "Delete within the same group of characters. Starting from the beginning" ),
2034 std::string( "Hello" ),
2037 std::string( "lo" ),
2040 std::string( "Delete within the same group of characters. Somewhere in the middle" ),
2041 std::string( "Hello" ),
2044 std::string( "Heo" ),
2047 std::string( "Delete within the same group of characters. Starting somewhere in the middle to the end" ),
2048 std::string( "Hello" ),
2051 std::string( "Hel" ),
2054 std::string( "Delete within the same group of characters. Finish just before a new one." ),
2055 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2058 std::string( "<font size='10'>H</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2061 std::string( "Delete starting in one group of characters and finishing in a different one. No merge of groups." ),
2062 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2065 std::string( "<font size='10'>He</font><font size='20'>Wo</font><font size='30'>rld</font>" ),
2068 std::string( "Delete within the same group of characters. Starting just after a different one." ),
2069 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2072 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>d</font>" ),
2075 std::string( "Delete whole group of characters. No merge" ),
2076 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2079 std::string( "<font size='10'>Hel</font><font size='30'>rld</font>" ),
2082 std::string( "Delete whole group of characters and part of the adjacent ones. No merge" ),
2083 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='30'>rld</font>" ),
2086 std::string( "<font size='10'>He</font><font size='30'>ld</font>" ),
2089 std::string( "Delete whole group of characters. Merge" ),
2090 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='10'>rld</font>" ),
2093 std::string( "<font size='10'>Helrld</font>" ),
2096 std::string( "Delete whole group of characters and part of the adjacent ones. Merge" ),
2097 std::string( "<font size='10'>Hel</font><font size='20'>loWo</font><font size='10'>rld</font>" ),
2100 std::string( "<font size='10'>Held</font>" ),
2103 const std::size_t numberOfTests( 11u );
2105 for( std::size_t index = 0u; index < numberOfTests; ++index )
2107 const RemoveCharactersFromWordTest& test = removeCharactersFromWordTests[index];
2109 if( !TestRemoveCharactersFromWord( test.description, test.input, test.position, test.numberOfCharacters, test.result, TEST_LOCATION ) )
2111 tet_result( TET_FAIL );
2115 tet_result( TET_PASS );
2119 int UtcDaliTextViewRemoveWordsFromParagraph(void)
2121 // Note: Currently RemoveWordsFromParagraph() function is only used to remove a number of words from the beginning, or
2122 // from a given index to the end.
2124 ToolkitTestApplication application;
2126 tet_infoline("UtcDaliTextViewRemoveWordsFromParagraph : ");
2127 struct RemoveWordsFromParagraphTest removeWordsFromParagraphTest[] =
2130 std::string( "Delete 0 words." ),
2131 std::string( "Hello hello, שלום עולם hello hello" ),
2135 std::string( "Hello hello, שלום עולם hello hello" ),
2138 std::string( "Delete from the middle to the end." ),
2139 std::string( "Hello hello, שלום עולם hello hello" ),
2143 std::string( "Hello hello, " ),
2146 std::string( "Delete from the beginning to the middle." ),
2147 std::string( "Hello hello, שלום עולם hello hello" ),
2151 std::string( "hello hello" ),
2154 const std::size_t numberOfTests( 3u );
2156 for( std::size_t index = 0u; index < numberOfTests; ++index )
2158 const RemoveWordsFromParagraphTest& test = removeWordsFromParagraphTest[index];
2160 if( !TestRemoveWordsFromParagraph( test.description, test.input, test.wordIndex, test.numberOfWords, test.lineHeightOffset, test.result, TEST_LOCATION ) )
2162 tet_result( TET_FAIL );
2166 tet_result( TET_PASS );