From 7f336e4318945301ac6ecc5bcb19bdb3eb120be1 Mon Sep 17 00:00:00 2001 From: Kingsley Stephens Date: Mon, 30 Mar 2015 16:39:46 +0100 Subject: [PATCH] Remove TextView and TextInput tests Change-Id: I6ec9b1bee202f55c82aac72760b066f7cc3db140 --- .../src/dali-toolkit-internal/CMakeLists.txt | 1 - .../dali-toolkit-internal/utc-Dali-TextView.cpp | 2168 -------------------- automated-tests/src/dali-toolkit/CMakeLists.txt | 2 - .../src/dali-toolkit/utc-Dali-TextInput.cpp | 968 --------- .../src/dali-toolkit/utc-Dali-TextView.cpp | 823 -------- 5 files changed, 3962 deletions(-) delete mode 100644 automated-tests/src/dali-toolkit-internal/utc-Dali-TextView.cpp delete mode 100644 automated-tests/src/dali-toolkit/utc-Dali-TextInput.cpp delete mode 100644 automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index 5a88e73..029c12d 100644 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -12,7 +12,6 @@ SET(TC_SOURCES utc-Dali-TextView-Processor-Types.cpp utc-Dali-TextView-Processor.cpp utc-Dali-TextView-Relayout-Utilities.cpp - utc-Dali-TextView.cpp ) # Append list of test harness files (Won't get parsed for test cases) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextView.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextView.cpp deleted file mode 100644 index 91dcc57..0000000 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextView.cpp +++ /dev/null @@ -1,2168 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include - - -// Internal headers are allowed here -#include -#include -#include -#include -#include - -using namespace Dali; -using namespace Dali::Toolkit; -using namespace Dali::Toolkit::Internal; - -void dali_text_view_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void dali_text_view_cleanup(void) -{ - test_return_value = TET_PASS; -} - - -namespace -{ - -const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS; -const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS; - -// Data structures used to create an 'experiment' in TET cases - -struct SplitWordTest -{ - std::string description; - std::string input; - std::size_t position; - std::string firstResult; - std::string lastResult; -}; - -struct SplitParagraphTest -{ - std::string description; - std::string input; - std::size_t wordIndex; - std::size_t characterIndex; - std::size_t characterParagraphIndex; - float lineHeightOffset; - std::string firstResult; - std::string lastResult; -}; - -struct MergeWordsTest -{ - std::string description; - std::string inputFirst; - std::string inputLast; - std::string result; -}; - -struct MergeParagraphsTest -{ - std::string description; - std::string inputFirst; - std::string inputLast; - float lineHeightOffset; - std::string result; -}; - -struct RemoveCharactersFromWordTest -{ - std::string description; - std::string input; - std::size_t position; - std::size_t numberOfCharacters; - std::string result; -}; - -struct RemoveWordsFromParagraphTest -{ - std::string description; - std::string input; - std::size_t wordIndex; - std::size_t numberOfWords; - float lineHeightOffset; - std::string result; -}; - -enum UpdateTextInfoOperation -{ - Insert, - Remove, - Replace -}; - -struct UpdateTextInfoTest -{ - std::string description; - UpdateTextInfoOperation operation; - std::string input; - std::size_t position; - std::size_t numberOfCharacters; - std::string inputText; - float lineHeightOffset; - std::string result; -}; - -// Useful Print functions when something goes wrong. - -void Print( const TextViewProcessor::CharacterLayoutInfo& character ) -{ - std::cout << " height : " << character.mSize.height << std::endl; - std::cout << " advance : " << character.mSize.width << std::endl; - std::cout << " bearing : " << character.mBearing << std::endl; - std::cout << " ascender : " << character.mAscender << std::endl; - std::cout << " position : " << character.mPosition << std::endl; - - TextActor textActor = TextActor::DownCast( character.mGlyphActor ); - if( textActor ) - { - std::cout << "[" << textActor.GetText() << "]"; - } -} - -void Print( const TextViewProcessor::WordLayoutInfo& word ) -{ - std::cout << "["; - std::cout << " mSize : " << word.mSize << std::endl; - std::cout << " mAscender : " << word.mAscender << std::endl; - std::cout << " mType : " << word.mType << std::endl; - std::cout << "mNumberOfCharacters : " << word.mCharactersLayoutInfo.size() << std::endl; - std::cout << "["; - for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it = word.mCharactersLayoutInfo.begin(), endIt = word.mCharactersLayoutInfo.end(); it != endIt; ++it ) - { - Print( *it ); - } - std::cout << "]"; std::cout << std::endl; - std::cout << "]"; std::cout << std::endl; -} - -void Print( const TextViewProcessor::ParagraphLayoutInfo& paragraph ) -{ - std::cout << "<"; - std::cout << " mSize : " << paragraph.mSize << std::endl; - std::cout << " mAscender : " << paragraph.mAscender << std::endl; - std::cout << "mNumberOfCharacters : " << paragraph.mNumberOfCharacters << std::endl; - for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = paragraph.mWordsLayoutInfo.begin(), endIt = paragraph.mWordsLayoutInfo.end(); it != endIt; ++it ) - { - Print( *it ); - } - std::cout << ">" << std::endl; -} - -void Print( const TextViewProcessor::TextLayoutInfo& text ) -{ - std::cout << "||"; - for( TextViewProcessor::ParagraphLayoutInfoContainer::const_iterator it = text.mParagraphsLayoutInfo.begin(), endIt = text.mParagraphsLayoutInfo.end(); it != endIt; ++it ) - { - Print( *it ); - } - std::cout << "||" << std::endl; -} - -std::string GetText( const TextViewProcessor::WordLayoutInfo& word, const Text& paragraphText ) -{ - Text text; - - paragraphText.GetSubText( word.mFirstCharacter, word.mFirstCharacter + word.mCharactersLayoutInfo.size() - 1u, text ); - - return text.GetText(); -} - -std::string GetText( const TextViewProcessor::ParagraphLayoutInfo& paragraph ) -{ - std::string text; - - for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it = paragraph.mWordsLayoutInfo.begin(), endIt = paragraph.mWordsLayoutInfo.end(); it != endIt; ++it ) - { - text += GetText( *it, paragraph.mText ); - } - - return text; -} - -// Test functions used to check if two data structures are equal. - -bool TestEqual( float x, float y ) -{ - return ( fabsf( x - y ) < 0.001f ); -} - -bool TestEqual( const TextViewProcessor::CharacterLayoutInfo& character1, - const TextViewProcessor::CharacterLayoutInfo& character2 ) -{ - if( !TestEqual( character1.mSize.height, character2.mSize.height ) ) - { - return false; - } - if( !TestEqual( character1.mSize.width, character2.mSize.width ) ) - { - return false; - } - if( !TestEqual( character1.mBearing, character2.mBearing ) ) - { - return false; - } - - if( !TestEqual( character1.mPosition.x, character2.mPosition.x ) ) - { - return false; - } - if( !TestEqual( character1.mPosition.y, character2.mPosition.y ) ) - { - return false; - } - - if( !TestEqual( character1.mAscender, character2.mAscender ) ) - { - return false; - } - - if( character1.mGlyphActor && !character2.mGlyphActor ) - { - return false; - } - - if( !character1.mGlyphActor && character2.mGlyphActor ) - { - return false; - } - - std::string text1; - std::string text2; - TextStyle style1; - TextStyle style2; - - TextActor textActor1 = TextActor::DownCast( character1.mGlyphActor ); - TextActor textActor2 = TextActor::DownCast( character2.mGlyphActor ); - if( textActor1 ) - { - text1 = textActor1.GetText(); - style1 = textActor1.GetTextStyle(); - - text2 = textActor2.GetText(); - style2 = textActor2.GetTextStyle(); - } - - if( text1 != text2 ) - { - return false; - } - - if( style1 != style2 ) - { - return false; - } - - return true; -} - -bool TestEqual( const TextViewProcessor::WordLayoutInfo& word1, - const TextViewProcessor::WordLayoutInfo& word2 ) -{ - if( !TestEqual( word1.mSize.x, word2.mSize.x ) ) - { - return false; - } - if( !TestEqual( word1.mSize.y, word2.mSize.y ) ) - { - return false; - } - - if( !TestEqual( word1.mAscender, word2.mAscender ) ) - { - return false; - } - - if( word1.mType != word2.mType ) - { - return false; - } - - if( word1.mCharactersLayoutInfo.size() != word2.mCharactersLayoutInfo.size() ) - { - return false; - } - - for( TextViewProcessor::CharacterLayoutInfoContainer::const_iterator it1 = word1.mCharactersLayoutInfo.begin(), endIt1 = word1.mCharactersLayoutInfo.end(), - it2 = word2.mCharactersLayoutInfo.begin(), endIt2 = word2.mCharactersLayoutInfo.end(); - ( it1 != endIt1 ) && ( it2 != endIt2 ); - ++it1, ++it2 ) - { - if( !TestEqual( *it1, *it2 ) ) - { - return false; - } - } - - return true; -} - -bool TestEqual( const TextViewProcessor::ParagraphLayoutInfo& paragraph1, - const TextViewProcessor::ParagraphLayoutInfo& paragraph2 ) -{ - if( !TestEqual( paragraph1.mSize.x, paragraph2.mSize.x ) ) - { - return false; - } - if( !TestEqual( paragraph1.mSize.y, paragraph2.mSize.y ) ) - { - return false; - } - - if( !TestEqual( paragraph1.mAscender, paragraph2.mAscender ) ) - { - return false; - } - - if( paragraph1.mNumberOfCharacters != paragraph2.mNumberOfCharacters ) - { - return false; - } - - if( paragraph1.mWordsLayoutInfo.size() != paragraph2.mWordsLayoutInfo.size() ) - { - return false; - } - - for( TextViewProcessor::WordLayoutInfoContainer::const_iterator it1 = paragraph1.mWordsLayoutInfo.begin(), endIt1 = paragraph1.mWordsLayoutInfo.end(), - it2 = paragraph2.mWordsLayoutInfo.begin(), endIt2 = paragraph2.mWordsLayoutInfo.end(); - ( it1 != endIt1 ) && ( it2 != endIt2 ); - ++it1, ++it2 ) - { - if( !TestEqual( *it1, *it2 ) ) - { - return false; - } - } - - return true; -} - -bool TestEqual( const TextViewProcessor::TextLayoutInfo& text1, - const TextViewProcessor::TextLayoutInfo& text2 ) -{ - if( !TestEqual( text1.mWholeTextSize.x, text2.mWholeTextSize.x ) ) - { - return false; - } - if( !TestEqual( text1.mWholeTextSize.y, text2.mWholeTextSize.y ) ) - { - return false; - } - - if( !TestEqual( text1.mMaxWordWidth, text2.mMaxWordWidth ) ) - { - return false; - } - - if( text1.mNumberOfCharacters != text2.mNumberOfCharacters ) - { - return false; - } - - if( text1.mParagraphsLayoutInfo.size() != text2.mParagraphsLayoutInfo.size() ) - { - return false; - } - - for( TextViewProcessor::ParagraphLayoutInfoContainer::const_iterator it1 = text1.mParagraphsLayoutInfo.begin(), endIt1 = text1.mParagraphsLayoutInfo.end(), - it2 = text2.mParagraphsLayoutInfo.begin(), endIt2 = text2.mParagraphsLayoutInfo.end(); - ( it1 != endIt1 ) && ( it2 != endIt2 ); - ++it1, ++it2 ) - { - if( !TestEqual( *it1, *it2 ) ) - { - return false; - } - } - - return true; -} - -/** - * Splits the \e input word in two by the given \e position and checks the results with \e firstResult and \e lastResult. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. i.e. "Split the word from the beginning. (position 0)". - * @param input The input word. - * @param position Where to split the word. - * @param firstResult First part of the split word. - * @param lastResult Last part of the split word. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -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 ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the input word. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( input, inputStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputStyledText, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData ); - - // Get the input word - TextViewProcessor::WordLayoutInfo inputWordLayout; - - if( !inputLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - inputWordLayout = *( *inputLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Create layout info for the first part of the result (after split the word) - - Toolkit::Internal::TextView::RelayoutData firstRelayoutData; - TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray firstResultStyledText; - MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true ); - - TextViewProcessor::CreateTextInfo( firstResultStyledText, - DEFAULT_LAYOUT_PARAMETERS, - firstRelayoutData ); - - // Get the first result word - TextViewProcessor::WordLayoutInfo firstResultWordLayout; - - if( !firstResultLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *firstResultLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - firstResultWordLayout = *( *firstResultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Create layout info for the last part of the result (after split the word) - - Toolkit::Internal::TextView::RelayoutData lastRelayoutData; - TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray lastResultStyledText; - MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true ); - - TextViewProcessor::CreateTextInfo( lastResultStyledText, - DEFAULT_LAYOUT_PARAMETERS, - lastRelayoutData ); - - // Get the last result word - TextViewProcessor::WordLayoutInfo lastResultWordLayout; - - if( !lastResultLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *lastResultLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - lastResultWordLayout = *( *lastResultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Split the word. - - TextViewProcessor::WordLayoutInfo lastWordLayoutInfo; - - SplitWord( position, - inputWordLayout, - lastWordLayoutInfo ); - - // Test results - if( !TestEqual( inputWordLayout, firstResultWordLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - return false; - } - - if( !TestEqual( lastWordLayoutInfo, lastResultWordLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - return false; - } - - return true; -} - -/** - * 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. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. i.e. "Split the paragraph from the beginning. (wordIndex 0 and characterIndex 0)". - * @param input The input word. - * @param wordIndex Index to the word within the paragraph where to split it. - * @param characterIndex Where to split the word. - * @param characterIndex Character index within the paragraph. - * @param lineHeightOffset Offset between lines. - * @param firstResult First part of the split paragraph. - * @param lastResult Last part of the split paragraph. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -bool TestSplitParagraph( const std::string& description, - const std::string& input, - size_t wordIndex, - size_t characterIndex, - size_t characterParagraphIndex, - float lineHeightOffset, - const std::string& firstResult, - const std::string& lastResult, - const char* location ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the input paragraph. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( input, inputStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - relayoutData ); - - // Get the input paragraph - TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout; - - if( !inputLayout.mParagraphsLayoutInfo.empty() ) - { - inputParagraphLayout = *inputLayout.mParagraphsLayoutInfo.begin(); - } - - // Create layout info for the first part of the result (after split the paragraph) - - Toolkit::Internal::TextView::RelayoutData firstRelayoutData; - TextViewProcessor::TextLayoutInfo& firstResultLayout( firstRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray firstResultStyledText; - MarkupProcessor::GetStyledTextArray( firstResult, firstResultStyledText, true ); - - TextViewProcessor::CreateTextInfo( firstResultStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - firstRelayoutData ); - - // Get the first result paragraph - TextViewProcessor::ParagraphLayoutInfo firstResultParagraphLayout; - - if( !firstResultLayout.mParagraphsLayoutInfo.empty() ) - { - firstResultParagraphLayout = *firstResultLayout.mParagraphsLayoutInfo.begin(); - } - - // Create layout info for the last part of the result (after split the paragraph) - - Toolkit::Internal::TextView::RelayoutData lastRelayoutData; - TextViewProcessor::TextLayoutInfo& lastResultLayout( lastRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray lastResultStyledText; - MarkupProcessor::GetStyledTextArray( lastResult, lastResultStyledText, true ); - - TextViewProcessor::CreateTextInfo( lastResultStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - lastRelayoutData ); - - // Get the last result paragraph - TextViewProcessor::ParagraphLayoutInfo lastResultParagraphLayout; - - if( !lastResultLayout.mParagraphsLayoutInfo.empty() ) - { - lastResultParagraphLayout = *lastResultLayout.mParagraphsLayoutInfo.begin(); - } - - // Split the paragraph. - - TextViewProcessor::ParagraphLayoutInfo lastParagraphLayoutInfo; - - TextViewProcessor::TextInfoIndices indices( 0, wordIndex, characterIndex ); - indices.mCharacterParagraphIndex = characterParagraphIndex; - - SplitParagraph( indices, - PointSize( lineHeightOffset ), - inputParagraphLayout, - lastParagraphLayoutInfo ); - - // Test results - if( !TestEqual( inputParagraphLayout, firstResultParagraphLayout ) ) - { - tet_printf( "Fail. different first layout info. %s\n", location ); - return false; - } - - if( !TestEqual( lastParagraphLayoutInfo, lastResultParagraphLayout ) ) - { - tet_printf( "Fail. different last layout info. %s\n", location ); - return false; - } - - return true; -} - -/** - * Merges the \e inputFirst word and the \e inputLast word, and checks the results with \e result. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. i.e. "Merge two words with same style". - * @param inputFirst The first part of the word. - * @param inputLast The last part of the word. - * @param result The merged word. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -bool TestMergeWords( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const std::string& result, const char* location ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the inputFirst word. - Toolkit::Internal::TextView::RelayoutData firstRelayoutData; - TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputFirstStyledText; - MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputFirstStyledText, - DEFAULT_LAYOUT_PARAMETERS, - firstRelayoutData ); - - // Get the input word - TextViewProcessor::WordLayoutInfo inputFirstWordLayout; - - if( !inputFirstLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputFirstLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - inputFirstWordLayout = *( *inputFirstLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Create layout info for the inputLast word. - Toolkit::Internal::TextView::RelayoutData lastRelayoutData; - TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputLastStyledText; - MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputLastStyledText, - DEFAULT_LAYOUT_PARAMETERS, - lastRelayoutData ); - - // Get the input word - TextViewProcessor::WordLayoutInfo inputLastWordLayout; - - if( !inputLastLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLastLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - inputLastWordLayout = *( *inputLastLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Create layout info for the result word. - Toolkit::Internal::TextView::RelayoutData resultRelayoutData; - TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray resultStyledText; - MarkupProcessor::GetStyledTextArray( result, resultStyledText, true ); - - TextViewProcessor::CreateTextInfo( resultStyledText, - DEFAULT_LAYOUT_PARAMETERS, - resultRelayoutData ); - - // Get the result word - TextViewProcessor::WordLayoutInfo resultWordLayout; - - if( !resultLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *resultLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - resultWordLayout = *( *resultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - MergeWord( inputFirstWordLayout, - inputLastWordLayout ); - - if( !TestEqual( inputFirstWordLayout, resultWordLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - return false; - } - - return true; -} - -/** - * Merges the \e inputFirst paragraph and the \e inputLast paragraph, and checks the results with \e result. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. - * @param inputFirst The first part of the paragraph. - * @param inputLast The last part of the paragraph. - * @param lineHeightOffset Offset between lines. - * @param result The merged paragraph. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -bool TestMergeParagraphs( const std::string& description, const std::string& inputFirst, const std::string& inputLast, const float lineHeightOffset, const std::string& result, const char* location ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the inputFirst paragraph. - Toolkit::Internal::TextView::RelayoutData firstRelayoutData; - TextViewProcessor::TextLayoutInfo& inputFirstLayout( firstRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputFirstStyledText; - MarkupProcessor::GetStyledTextArray( inputFirst, inputFirstStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputFirstStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - firstRelayoutData ); - - // Get the input word - TextViewProcessor::ParagraphLayoutInfo inputFirstParagraphLayout; - - if( !inputFirstLayout.mParagraphsLayoutInfo.empty() ) - { - inputFirstParagraphLayout = *inputFirstLayout.mParagraphsLayoutInfo.begin(); - } - - // Create layout info for the inputLast paragraph. - Toolkit::Internal::TextView::RelayoutData lastRelayoutData; - TextViewProcessor::TextLayoutInfo& inputLastLayout( lastRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputLastStyledText; - MarkupProcessor::GetStyledTextArray( inputLast, inputLastStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputLastStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - lastRelayoutData ); - - // Get the input word - TextViewProcessor::ParagraphLayoutInfo inputLastParagraphLayout; - - if( !inputLastLayout.mParagraphsLayoutInfo.empty() ) - { - inputLastParagraphLayout = *inputLastLayout.mParagraphsLayoutInfo.begin(); - } - - // Create layout info for the result word. - Toolkit::Internal::TextView::RelayoutData resultRelayoutData; - TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray resultStyledText; - MarkupProcessor::GetStyledTextArray( result, resultStyledText, true ); - - TextViewProcessor::CreateTextInfo( resultStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - resultRelayoutData ); - - // Get the result word - TextViewProcessor::ParagraphLayoutInfo resultParagraphLayout; - - if( !resultLayout.mParagraphsLayoutInfo.empty() ) - { - resultParagraphLayout = *resultLayout.mParagraphsLayoutInfo.begin(); - } - - MergeParagraph( inputFirstParagraphLayout, - inputLastParagraphLayout ); - - if( !TestEqual( inputFirstParagraphLayout, resultParagraphLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - return false; - } - - return true; -} - -/** - * Removes from the \e input word the \e numberOfCharacters characters starting from the given \e position and checks the results with \e result. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. i.e. "Remove a whole word. Merge". - * @param input The input word. - * @param position Where to start to remove characters - * @param numberOfCharacters The number of characters to remove. - * @param result The word without the removed characters. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -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 ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the input word. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( input, inputStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputStyledText, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData ); - - // Get the input word - TextViewProcessor::WordLayoutInfo inputWordLayout; - - if( !inputLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *inputLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - inputWordLayout = *( *inputLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - // Create layout info for the result word. - Toolkit::Internal::TextView::RelayoutData resultRelayoutData; - TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray resultStyledText; - MarkupProcessor::GetStyledTextArray( result, resultStyledText, true ); - - TextViewProcessor::CreateTextInfo( resultStyledText, - DEFAULT_LAYOUT_PARAMETERS, - resultRelayoutData ); - - // Get the result word - TextViewProcessor::WordLayoutInfo resultWordLayout; - - if( !resultLayout.mParagraphsLayoutInfo.empty() ) - { - const TextViewProcessor::ParagraphLayoutInfo& paragraph( *resultLayout.mParagraphsLayoutInfo.begin() ); - if( !paragraph.mWordsLayoutInfo.empty() ) - { - resultWordLayout = *( *resultLayout.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - } - } - - RemoveCharactersFromWord( position, - numberOfCharacters, - inputWordLayout ); - - if( !TestEqual( inputWordLayout, resultWordLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - return false; - } - - return true; -} - -/** - * Removes from the \e input paragraph the \e numberOfWords words starting from the given \e wordIndex and checks the results with \e result. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. - * @param input The input paragraph. - * @param wordIndex Index within the paragraph where to start to remove words. - * @param numberOfWords The number of words to remove. - * @param lineHeightOffset Offset between lines. - * @param result The paragraph without the removed words. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -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 ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the input paragraph. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( input, inputStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - relayoutData ); - - // Get the input paragraph - TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout; - - if( !inputLayout.mParagraphsLayoutInfo.empty() ) - { - inputParagraphLayout = *inputLayout.mParagraphsLayoutInfo.begin(); - } - - // Create layout info for the result paragraph. - Toolkit::Internal::TextView::RelayoutData resultRelayoutData; - TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray resultStyledText; - MarkupProcessor::GetStyledTextArray( result, resultStyledText, true ); - - TextViewProcessor::CreateTextInfo( resultStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - resultRelayoutData ); - - // Get the result paragraph - TextViewProcessor::ParagraphLayoutInfo resultParagraphLayout; - - if( !resultLayout.mParagraphsLayoutInfo.empty() ) - { - resultParagraphLayout = *resultLayout.mParagraphsLayoutInfo.begin(); - } - - RemoveWordsFromParagraph( wordIndex, - numberOfWords, - lineHeightOffset, - inputParagraphLayout ); - - if( !TestEqual( inputParagraphLayout, resultParagraphLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - tet_printf( " input : [%s]\n", input.c_str() ); - tet_printf( " result : [%s]\n", GetText( resultParagraphLayout ).c_str() ); - tet_printf( " expected result : [%s]\n\n", result.c_str() ); - - Print(inputParagraphLayout); std::cout << std::endl << std::endl; - Print(resultParagraphLayout); std::cout << std::endl; - return false; - } - - return true; -} - -/** - * Tests inserts, removes and updates operation in the given \e input text and checks with the given \e result. - * - * If the test fails it prints a short description and the line where this function was called. - * - * @param description Short description of the experiment. - * @param operation Type of update operation (insert, remove, replace) - * @param input The input text. - * @param position Where to insert, remove or replace text. - * @param numberOfCharacters Number of characters to remove or replace. - * @param inputText Inserted or updated text. - * @param lineHeightOffset Offset between lines. - * @param result Expected result. - * @param location Where this function has been called. - * - * @return \e true if the experiment is successful. Otherwise returns \e false. - */ -bool TestUpdateTextInfo( const std::string& description, - UpdateTextInfoOperation operation, - const std::string& input, - std::size_t position, - std::size_t numberOfCharacters, - const std::string& inputText, - float lineHeightOffset, - const std::string& result, - const char* location ) -{ - tet_printf( "%s\n", description.c_str() ); - - // Create layout info for the input. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( input, inputStyledText, true ); - - TextViewProcessor::CreateTextInfo( inputStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - relayoutData ); - - // Create layout info for the result. - Toolkit::Internal::TextView::RelayoutData resultRelayoutData; - TextViewProcessor::TextLayoutInfo& resultLayout( resultRelayoutData.mTextLayoutInfo ); - - MarkupProcessor::StyledTextArray resultStyledText; - MarkupProcessor::GetStyledTextArray( result, resultStyledText, true ); - - TextViewProcessor::CreateTextInfo( resultStyledText, - Toolkit::Internal::TextView::LayoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ), - resultRelayoutData ); - - // Choose operation and call appropiate UpdateTextInfo() method. - const Toolkit::Internal::TextView::LayoutParameters layoutParameters( Toolkit::TextView::SplitByNewLineChar, - Toolkit::TextView::Original, - Toolkit::TextView::Original, - static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), - Toolkit::TextView::Center, - PointSize( lineHeightOffset ), - true ); - - switch( operation ) - { - case Insert: - { - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true ); - - TextViewProcessor::UpdateTextInfo( position, - inputStyledText, - layoutParameters, - relayoutData ); - break; - } - case Remove: - { - TextViewProcessor::UpdateTextInfo( position, - numberOfCharacters, - layoutParameters, - relayoutData, - TextViewProcessor::CLEAR_TEXT ); - break; - } - case Replace: - { - MarkupProcessor::StyledTextArray inputStyledText; - MarkupProcessor::GetStyledTextArray( inputText, inputStyledText, true ); - - TextViewProcessor::UpdateTextInfo( position, - numberOfCharacters, - inputStyledText, - layoutParameters, - relayoutData ); - break; - } - default: - { - tet_printf( "TestUpdateTextInfo: unknown update operation. %s\n", location ); - return false; - } - } - - if( !TestEqual( inputLayout, resultLayout ) ) - { - tet_printf( "Fail. different layout info. %s\n", location ); - - // std::cout << " result : "; Print( inputLayout ); - // std::cout << " expected result : "; Print( resultLayout ); - return false; - } - - return true; -} - -} // namespace - - -int UtcDaliTextViewCreateTextInfo(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewCreateTextInfo : "); - - // Metrics for characters - - // Font size = 10 - // size : [9.48351, 9.48351] - // advance : 9.48351 - // bearing : 8.53516 - // ascender : 8.53516 - - // Font size = 12 - // size : [11.3802, 11.3802] - // advance : 11.3802 - // bearing : 10.2422 - // ascender : 10.2422 - - // Font size = 14 - // size : [13.2769, 13.2769] - // advance : 13.2769 - // bearing : 11.9492 - // ascender : 11.9492 - - const float HEIGHT_10( 9.48351f ); - const float ADVANCE_10( 9.48351f ); - const float BEARING_10( 8.53516f ); - const float ASCENDER_10( 8.53516f ); - - const float HEIGHT_12( 11.3802f ); - const float ADVANCE_12( 11.3802f ); - const float BEARING_12( 10.2422f ); - const float ASCENDER_12( 10.2422f ); - - - // Generate a text. - Toolkit::Internal::TextView::RelayoutData relayoutData; - TextViewProcessor::TextLayoutInfo& textLayoutInfo( relayoutData.mTextLayoutInfo ); - - std::string text( "Hello world!\n" - "\n" ); - - MarkupProcessor::StyledTextArray styledText; - MarkupProcessor::GetStyledTextArray( text, styledText, true ); - - TextViewProcessor::CreateTextInfo( styledText, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData ); - - - // Build the text info with metric values. - - // Characters - - TextViewProcessor::CharacterLayoutInfo layoutInfo10; // ( [lo wo]) - layoutInfo10.mSize.height = HEIGHT_10; - layoutInfo10.mSize.width = ADVANCE_10; - layoutInfo10.mBearing = BEARING_10; - layoutInfo10.mAscender = ASCENDER_10; - TextViewProcessor::CharacterLayoutInfo layoutInfo12; // ( [Hel], [rld!] and [CR]) - layoutInfo12.mSize.height = HEIGHT_12; - layoutInfo12.mSize.width = ADVANCE_12; - layoutInfo12.mBearing = BEARING_12; - layoutInfo12.mAscender = ASCENDER_12; - - // Words - - TextViewProcessor::WordLayoutInfo wordLayout1, wordLayout2, wordLayout3, wordLayout4; - - // Hello - wordLayout1.mSize = Size( 3.f * ADVANCE_12 + 2.f * ADVANCE_10, HEIGHT_12 ); - wordLayout1.mAscender = ASCENDER_12; - wordLayout1.mType = TextViewProcessor::NoSeparator; - - wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // H - wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // e - wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l - wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // l - wordLayout1.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o - - // (white space) - wordLayout2.mSize = Size( ADVANCE_10, HEIGHT_10 ); - wordLayout2.mAscender = ASCENDER_10; - wordLayout2.mType = TextViewProcessor::WordSeparator; - wordLayout2.mCharactersLayoutInfo.push_back( layoutInfo10 ); // (white space) - - // world! - wordLayout3.mSize = Size( 2.f * ADVANCE_10 + 4.f * ADVANCE_12, HEIGHT_12 ); - wordLayout3.mAscender = ASCENDER_12; - wordLayout3.mType = TextViewProcessor::NoSeparator; - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // w - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo10 ); // o - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // r - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // l - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // d - wordLayout3.mCharactersLayoutInfo.push_back( layoutInfo12 ); // ! - - // (new paragraph character) - wordLayout4.mSize = Size( 0.f, HEIGHT_12 ); - wordLayout4.mAscender = ASCENDER_12; - wordLayout4.mType = TextViewProcessor::ParagraphSeparator; - layoutInfo12.mSize.width = 0.f; - wordLayout4.mCharactersLayoutInfo.push_back( layoutInfo12 ); // (new paragraph char) - - // Paragraphs - - TextViewProcessor::ParagraphLayoutInfo paragraphLayout1, paragraphLayout2, paragraphLayout3; - - paragraphLayout1.mSize = Size( 5.f * ADVANCE_10 + 7.f * ADVANCE_12, HEIGHT_12 ); - paragraphLayout1.mAscender = ASCENDER_12; - paragraphLayout1.mNumberOfCharacters = 13; - paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout1 ); - paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout2 ); - paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout3 ); - paragraphLayout1.mWordsLayoutInfo.push_back( wordLayout4 ); - - paragraphLayout2.mSize = Size( 0.f, HEIGHT_12 ); - paragraphLayout2.mAscender = ASCENDER_12; - paragraphLayout2.mNumberOfCharacters = 1; - paragraphLayout2.mWordsLayoutInfo.push_back( wordLayout4 ); - - paragraphLayout3.mSize = Size( 0.f, HEIGHT_12 ); - - // Text (layout) - TextViewProcessor::TextLayoutInfo textLayout; - - textLayout.mWholeTextSize = Size( 5.f * ADVANCE_10 + 7.f * ADVANCE_12, 3.f * HEIGHT_12 ); - textLayout.mMaxWordWidth = 2.f * ADVANCE_10 + 4.f * ADVANCE_12; - textLayout.mNumberOfCharacters = 14; - textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout1 ); - textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout2 ); - textLayout.mParagraphsLayoutInfo.push_back( paragraphLayout3 ); - - if(!TestEqual( textLayout, textLayoutInfo )) - { - std::cout << "Layout fails" << std::endl; - Print(textLayout); std::cout << std::endl; - Print(textLayoutInfo); std::cout << std::endl; - } - - DALI_TEST_CHECK( TestEqual( textLayout, textLayoutInfo ) ); - END_TEST; -} - -int UtcDaliTextViewSplitWord(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewSplitWord : "); - - struct SplitWordTest splitWordTests[] = - { - { - std::string( "Split word, position 0." ), - std::string( "Helloooo" ), - 0, - std::string( "" ), - std::string( "Helloooo" ), - }, - { - std::string( "Split word, position 8." ), - std::string( "Helloooo" ), - 8, - std::string( "Helloooo" ), - std::string( "" ), - }, - { - std::string( "Split word, position 2." ), - std::string( "Helloooo" ), - 2, - std::string( "He" ), - std::string( "lloooo" ), - }, - { - std::string( "Split word, position 3." ), - std::string( "Helloooo" ), - 3, - std::string( "Hel" ), - std::string( "loooo" ), - }, - { - std::string( "Split word, position 4." ), - std::string( "Helloooo" ), - 4, - std::string( "Hell" ), - std::string( "oooo" ), - }, - }; - const std::size_t numberOfTests( 5u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const SplitWordTest& test = splitWordTests[index]; - - if( !TestSplitWord( test.description, test.input, test.position, test.firstResult, test.lastResult, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewUpdateTextInfo(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewUpdateTextInfo : "); - - struct UpdateTextInfoTest updateTextInfoTest[] = - { - // Remove operations - - { - std::string( "Remove from new paragraph character to first character next paragraph." ), - Remove, - std::string("Hello world\nhello world."), - 11, - 2, - std::string(""), - 0.f, - std::string("Hello worldello world."), - }, - { - std::string( "Replace style from new paragraph character to first character next paragraph." ), - Replace, - std::string("Hello world\nhello world."), - 11, - 2, - std::string("\nh"), - 0.f, - std::string("Hello world\nhello world."), - }, - { - std::string( "Remove from the beginning to the middle of last word." ), - Remove, - std::string("Hello world, hello world."), - 0, - 22, - std::string(), // Not used. - 0.f, - std::string("ld."), - }, - { - std::string( "Remove from the beginning to the middle of the text." ), - Remove, - std::string("Hello world hello world."), - 0, - 12, - std::string(), // Not used. - 0.f, - std::string("hello world."), - }, - // Remove within the same word: - // * within the same group of characters with same style. - { - std::string( "Remove within the same word, within the same group of characters with same style" ), - Remove, - std::string("Hello world\nhello world"), - 7, - 3, - std::string(), // Not used. - 0.f, - std::string( "Hello wd\nhello world" ) - }, - // * whole group of characters (merge adjacent group of characters) - { - std::string( "Remove within the same word, whole group of characters (merge adjacent group of characters)" ), - Remove, - std::string("Hello world\nhello world"), - 7, - 3, - std::string(), // Not used. - 0.f, - std::string( "Hello wd\nhello world" ) - }, - // * whole group of characters (don't merge adjacent gtoup of characters) - { - std::string( "Remove within the same word, whole group of characters (don't merge adjacent gtoup of characters)" ), - Remove, - std::string("Hello world\nhello world"), - 7, - 3, - std::string(), // Not used. - 0.f, - std::string( "Hello wd\nhello world" ) - }, - // * Remove whole word (merge words) - { - std::string( "Remove within the same word, whole word (merge words)" ), - Remove, - std::string("Hello world\nhello world"), - 5, - 1, - std::string(), // Not used. - 0.f, - std::string( "Helloworld\nhello world" ) - }, - // * Remove whole word (don't merge words) - { - std::string( "Remove within the same word, whole word (don't merge words)" ), - Remove, - std::string("Hello world\nhello world"), - 6, - 5, - std::string(), // Not used. - 0.f, - std::string( "Hello \nhello world" ) - }, - // * Remove whole word (merge paragraphs) - { - std::string( "Remove within the same word, whole word (merge paragraphs)" ), - Remove, - std::string("Hello world\nhello world"), - 11, - 1, - std::string(), // Not used. - 0.f, - std::string( "Hello worldhello world" ) - }, - // * Remove RTL text within LTR - { - std::string( "Remove within the same paragraph, RTL text within LTR." ), - Remove, - std::string("Hello world, שלום עולם, hello world"), - 10, - 15, - std::string(), // Not used. - 0.f, - std::string( "Hello worlello world" ) - }, - // * Remove whole paragraph - { - std::string( "Remove whole paragraph" ), - Remove, - std::string("Hello world, hello world\n" - "Hello world, hello world\n" - "Hello world, hello world\n" - "Hello world, hello world\n"), - 25, - 25, - std::string(), // Not used. - 0.f, - std::string("Hello world, hello world\n" - "Hello world, hello world\n" - "Hello world, hello world\n"), - }, - { - std::string( "Remove whole paragraph" ), - Remove, - std::string("Hello world, hello world\n" - "H"), - 25, - 1, - std::string(), // Not used. - 0.f, - std::string("Hello world, hello world\n"), - }, - - - // Insert operations - { - std::string( "insert some text" ), - Insert, - std::string("inpuext"), - 4, - 0, // Not used - std::string( "t t" ), - 0.f, - std::string( "input text" ) - }, - { - std::string( "Insert text at the end" ), - Insert, - std::string("touch "), - 6, - 0, - std::string("me\nhello"), - 0.f, - std::string("touch me\nhello") - }, - - // Replace operations. - { - std::string( "Replace style from the beginning to some point in the middle of the text." ), - Replace, - std::string( "Hello world" ), - 0, - 7, - std::string( "Hello w" ), - 0.f, - std::string( "Hello world" ) - }, - { - std::string( "Replace style from the middle of the text to the end." ), - Replace, - std::string( "Touch me\nhello" ), - 6, - 8, - std::string( "me\nhello" ), - 0.f, - std::string( "Touch me\nhello" ) - }, - { - std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 1." ), - Remove, - std::string( "Touch me\nhello\nworld" ), - 6, - 8, - std::string( "" ), - 0.f, - std::string( "Touch \nworld" ) - }, - { - std::string( "Insert styled text in the middle of a text. Previous: Replace style from the middle of the text 1." ), - Insert, - std::string( "Touch \nworld" ), - 6, - 0, - std::string( "me\nhello" ), - 0.f, - std::string( "Touch me\nhello\nworld" ) - }, - { - std::string( "Replace style from the middle of the text 1." ), - Replace, - std::string( "Touch me\nhello\nworld" ), - 6, - 8, - std::string( "me\nhello" ), - 0.f, - std::string( "Touch me\nhello\nworld" ) - }, - { - std::string( "Remove characters from text. Previous next test:Replace style from the middle of the text 2." ), - Remove, - std::string( "Touch me\nhello\nworld" ), - 6, - 9, - std::string( "" ), - 0.f, - std::string( "Touch world" ) - }, - { - std::string( "Replace style from the middle of the text 2." ), - Replace, - std::string( "Touch me\nhello\nworld" ), - 6, - 9, - std::string( "me\nhello\n" ), - 0.f, - std::string( "Touch me\nhello\nworld" ) - }, - }; - const std::size_t numberOfTests( 22u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const UpdateTextInfoTest& test = updateTextInfoTest[index]; - - if( !TestUpdateTextInfo( test.description, test.operation, test.input, test.position, test.numberOfCharacters, test.inputText, test.lineHeightOffset, test.result, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewSplitParagraph(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewSplitParagraph : "); - - struct SplitParagraphTest splitParagraphTests[] = - { - { - std::string( "Split paragraph, wordPosition 0, position 0." ), - std::string( "Helloooo wooorld שלום עולם text text" ), - 0, - 0, - 0, - 3.f, - std::string( "" ), - std::string( "Helloooo wooorld שלום עולם text text" ), - }, - { - std::string( "Split paragraph, wordPosition 10, position 4." ), - std::string( "Helloooo wooorld שלום עולם text text" ), - 10, - 4, - 36, - 0.f, - std::string( "Helloooo wooorld שלום עולם text text" ), - std::string( "" ), - }, - { - std::string( "Split paragraph, wordPosition 2, position 4." ), - std::string("Hello world, hello world"), - 2, - 4, - 10, - 0.f, - std::string("Hello worl"), - std::string("d, hello world") - }, - { - std::string( "Split paragraph, wordPosition 6, position 0." ), - std::string( "Helloooo wooorld שלום עולם text text" ), - 6, - 0, - 21, - 0.f, - std::string( "Helloooo wooorld שלום " ), - std::string( "עולם text text" ), - }, - { - std::string( "Split paragraph, wordPosition 4, position 0." ), - std::string( "Helloooo wooorld שלום עולם text text" ), - 4, - 0, - 17, - 0.f, - std::string( "Helloooo wooorld " ), - std::string( "שלום עולם text text" ), - }, - { - std::string( "Split paragraph2, wordPosition 8, position 0." ), - std::string( "Helloooo wooorld שלום עולם text text" ), - 8, - 0, - 27, - 6.f, - std::string( "Helloooo wooorld שלום עולם " ), - std::string( "text text" ), - }, - }; - const std::size_t numberOfTests( 6u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const SplitParagraphTest& test = splitParagraphTests[index]; - - if( !TestSplitParagraph( test.description, - test.input, - test.wordIndex, - test.characterIndex, - test.characterParagraphIndex, - test.lineHeightOffset, - test.firstResult, - test.lastResult, - TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewMergeWord01(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewMergeWord01 : "); - - struct MergeWordsTest mergeWordsTests[] = - { - { - std::string( "Merge words with same style." ), - std::string( "Hel" ), - std::string( "lo" ), - std::string( "Hello" ), - }, - { - std::string( "Merge words with different styles." ), - std::string( "lo" ), - std::string( "Hello" ) - }, - }; - const std::size_t numberOfTests( 2u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const MergeWordsTest& test = mergeWordsTests[index]; - - if( !TestMergeWords( test.description, test.inputFirst, test.inputLast, test.result, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewMergeWord02(void) -{ - // Negative test. - // It test white spaces and new paragraph characters can't be merged to other words. - - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewMergeWord02 : "); - - // Generate three words - - Toolkit::Internal::TextView::RelayoutData relayoutData01; - Toolkit::Internal::TextView::RelayoutData relayoutData02; - Toolkit::Internal::TextView::RelayoutData relayoutData03; - TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo ); - TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo ); - TextViewProcessor::TextLayoutInfo& textLayoutInfo03( relayoutData03.mTextLayoutInfo ); - - std::string text01( " " ); - std::string text02( "\n" ); - std::string text03( "a" ); - MarkupProcessor::StyledTextArray styledText01; - MarkupProcessor::StyledTextArray styledText02; - MarkupProcessor::StyledTextArray styledText03; - MarkupProcessor::GetStyledTextArray( text01, styledText01, true ); - MarkupProcessor::GetStyledTextArray( text02, styledText02, true ); - MarkupProcessor::GetStyledTextArray( text03, styledText03, true ); - - TextViewProcessor::CreateTextInfo( styledText01, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData01 ); - - TextViewProcessor::WordLayoutInfo wordLayoutInfo01; - - wordLayoutInfo01 = *( *textLayoutInfo01.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - - TextViewProcessor::CreateTextInfo( styledText02, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData02 ); - - TextViewProcessor::WordLayoutInfo wordLayoutInfo02; - - wordLayoutInfo02 = *( *textLayoutInfo02.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - - TextViewProcessor::CreateTextInfo( styledText03, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData03 ); - - TextViewProcessor::WordLayoutInfo wordLayoutInfo03; - - wordLayoutInfo03 = *( *textLayoutInfo03.mParagraphsLayoutInfo.begin() ).mWordsLayoutInfo.begin(); - - // Test MergeWord() asserts if white spaces or new paragraph chars are merged. - bool assert1 = false; - bool assert2 = false; - bool assert3 = false; - bool assert4 = false; - bool assert5 = false; - bool assert6 = false; - - try - { - MergeWord( wordLayoutInfo01, - wordLayoutInfo02 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert1 = true; - } - try - { - MergeWord( wordLayoutInfo01, - wordLayoutInfo03 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert2 = true; - } - try - { - MergeWord( wordLayoutInfo02, - wordLayoutInfo01 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert3 = true; - } - try - { - MergeWord( wordLayoutInfo02, - wordLayoutInfo03 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert4 = true; - } - try - { - MergeWord( wordLayoutInfo03, - wordLayoutInfo01 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert5 = true; - } - try - { - MergeWord( wordLayoutInfo03, - wordLayoutInfo02 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_EQUALS( e.condition, "!\"TextViewProcessor::MergeWord(). ERROR: White spaces or new paragraph characters can't be merged with other words.\"", TEST_LOCATION ); - assert6 = true; - } - - if( assert1 && assert2 && assert3 && assert4 && assert5 && assert6 ) - { - tet_result( TET_PASS ); - } - else - { - tet_result( TET_FAIL ); - } - END_TEST; -} - -int UtcDaliTextViewMergeParagraph01(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewMergeParagraph01 : "); - - struct MergeParagraphsTest mergeParagraphsTests[] = - { - { - std::string( "Merge a void first paragraph." ), - std::string( "" ), - std::string( "Hello world, this is a whole paragraph" ), - 2.f, - std::string( "Hello world, this is a whole paragraph" ) - }, - { - std::string( "Merge a void last paragraph." ), - std::string( "Hello world, this is a whole paragraph" ), - std::string( "" ), - 0.f, - std::string( "Hello world, this is a whole paragraph" ) - }, - { - std::string( "Merge paragraphs: last starting with RTL text and first ending with RTL" ), - std::string( "Hello world, שלום" ), - std::string( " עולם, hello world." ), - 6.f, - std::string( "Hello world, שלום עולם, hello world." ) - }, - { - std::string( "Merge paragraphs and don't merge last and first words." ), - std::string( "Hello world, " ), - std::string( "שלום עולם, hello world." ), - 3.f, - std::string( "Hello world, שלום עולם, hello world." ) - }, - { - std::string( "Merge paragraphs. Don't merge words" ), - std::string( "Hello world," ), - std::string( " this is a whole paragraph" ), - 0.f, - std::string( "Hello world, this is a whole paragraph" ) - }, - { - std::string( "Merge paragraphs. Merge words" ), - std::string( "Hello world, th" ), - std::string( "is is a whole paragraph" ), - 0.f, - std::string( "Hello world, this is a whole paragraph" ) - }, - }; - const std::size_t numberOfTests( 6u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const MergeParagraphsTest& test = mergeParagraphsTests[index]; - - if( !TestMergeParagraphs( test.description, test.inputFirst, test.inputLast, test.lineHeightOffset, test.result, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewMergeParagraph02(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewMergeParagraph02 : "); - - Toolkit::Internal::TextView::RelayoutData relayoutData01; - Toolkit::Internal::TextView::RelayoutData relayoutData02; - TextViewProcessor::TextLayoutInfo& textLayoutInfo01( relayoutData01.mTextLayoutInfo ); - TextViewProcessor::TextLayoutInfo& textLayoutInfo02( relayoutData02.mTextLayoutInfo ); - - std::string text01( "Hello world\n" ); - std::string text02( "hello world" ); - MarkupProcessor::StyledTextArray styledText01; - MarkupProcessor::StyledTextArray styledText02; - MarkupProcessor::GetStyledTextArray( text01, styledText01, true ); - MarkupProcessor::GetStyledTextArray( text02, styledText02, true ); - - TextViewProcessor::CreateTextInfo( styledText01, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData01 ); - - TextViewProcessor::ParagraphLayoutInfo paragraphLayoutInfo01; - - paragraphLayoutInfo01 = *textLayoutInfo01.mParagraphsLayoutInfo.begin(); - - TextViewProcessor::CreateTextInfo( styledText02, - DEFAULT_LAYOUT_PARAMETERS, - relayoutData02 ); - - TextViewProcessor::ParagraphLayoutInfo paragraphLayoutInfo02; - - paragraphLayoutInfo02 = *textLayoutInfo02.mParagraphsLayoutInfo.begin(); - - bool assert1 = false; - - try - { - MergeParagraph( paragraphLayoutInfo01, - paragraphLayoutInfo02 ); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - 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 ); - assert1 = true; - } - - if( assert1 ) - { - tet_result( TET_PASS ); - } - else - { - tet_result( TET_FAIL ); - } - END_TEST; -} - -int UtcDaliTextViewRemoveCharactersFromWord(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewMergeWord02 : "); - - struct RemoveCharactersFromWordTest removeCharactersFromWordTests[] = - { - { - std::string( "Delete 0 characters." ), - std::string( "Hello" ), - 3, - 0, - std::string( "Hello" ), - }, - { - std::string( "Delete within the same group of characters. Starting from the beginning" ), - std::string( "Hello" ), - 0, - 3, - std::string( "lo" ), - }, - { - std::string( "Delete within the same group of characters. Somewhere in the middle" ), - std::string( "Hello" ), - 2, - 2, - std::string( "Heo" ), - }, - { - std::string( "Delete within the same group of characters. Starting somewhere in the middle to the end" ), - std::string( "Hello" ), - 3, - 2, - std::string( "Hel" ), - }, - { - std::string( "Delete within the same group of characters. Finish just before a new one." ), - std::string( "HelloWorld" ), - 1, - 2, - std::string( "HloWorld" ), - }, - { - std::string( "Delete starting in one group of characters and finishing in a different one. No merge of groups." ), - std::string( "HelloWorld" ), - 2, - 3, - std::string( "HeWorld" ), - }, - { - std::string( "Delete within the same group of characters. Starting just after a different one." ), - std::string( "HelloWorld" ), - 7, - 2, - std::string( "HelloWod" ), - }, - { - std::string( "Delete whole group of characters. No merge" ), - std::string( "HelloWorld" ), - 3, - 4, - std::string( "Helrld" ), - }, - { - std::string( "Delete whole group of characters and part of the adjacent ones. No merge" ), - std::string( "HelloWorld" ), - 2, - 6, - std::string( "Held" ), - }, - { - std::string( "Delete whole group of characters. Merge" ), - std::string( "HelloWorld" ), - 3, - 4, - std::string( "Helrld" ), - }, - { - std::string( "Delete whole group of characters and part of the adjacent ones. Merge" ), - std::string( "HelloWorld" ), - 2, - 6, - std::string( "Held" ), - }, - }; - const std::size_t numberOfTests( 11u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const RemoveCharactersFromWordTest& test = removeCharactersFromWordTests[index]; - - if( !TestRemoveCharactersFromWord( test.description, test.input, test.position, test.numberOfCharacters, test.result, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} - -int UtcDaliTextViewRemoveWordsFromParagraph(void) -{ - // Note: Currently RemoveWordsFromParagraph() function is only used to remove a number of words from the beginning, or - // from a given index to the end. - - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextViewRemoveWordsFromParagraph : "); - struct RemoveWordsFromParagraphTest removeWordsFromParagraphTest[] = - { - { - std::string( "Delete 0 words." ), - std::string( "Hello hello, שלום עולם hello hello" ), - 0, - 0, - 2.f, - std::string( "Hello hello, שלום עולם hello hello" ), - }, - { - std::string( "Delete from the middle to the end." ), - std::string( "Hello hello, שלום עולם hello hello" ), - 4, - 7, - 0.f, - std::string( "Hello hello, " ), - }, - { - std::string( "Delete from the beginning to the middle." ), - std::string( "Hello hello, שלום עולם hello hello" ), - 0, - 8, - 6.f, - std::string( "hello hello" ), - }, - }; - const std::size_t numberOfTests( 3u ); - - for( std::size_t index = 0u; index < numberOfTests; ++index ) - { - const RemoveWordsFromParagraphTest& test = removeWordsFromParagraphTest[index]; - - if( !TestRemoveWordsFromParagraph( test.description, test.input, test.wordIndex, test.numberOfWords, test.lineHeightOffset, test.result, TEST_LOCATION ) ) - { - tet_result( TET_FAIL ); - } - } - - tet_result( TET_PASS ); - END_TEST; -} diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 03399af..a3f7172 100644 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -63,8 +63,6 @@ SET(TC_SOURCES utc-Dali-StyleManager.cpp utc-Dali-SuperBlurView.cpp utc-Dali-SwirlEffect.cpp - utc-Dali-TextInput.cpp - utc-Dali-TextView.cpp ) # Append list of test harness files (Won't get parsed for test cases) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextInput.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextInput.cpp deleted file mode 100644 index 9f8905e..0000000 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextInput.cpp +++ /dev/null @@ -1,968 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include -#include -#include -#include - -using namespace Dali; -using namespace Toolkit; - -void utc_dali_toolkit_text_input_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void utc_dali_toolkit_text_input_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ -static bool gObjectCreatedCallBackCalled; - -static void TestCallback(BaseHandle handle) -{ - Actor actor = Actor::DownCast(handle); - - if(actor) - { - TextInput handle = TextInput::DownCast(actor); - if (handle) - { - gObjectCreatedCallBackCalled = true; - } - } -} - -static bool gHasEndSignalBeenReceived; -static bool gHasStartSignalBeenReceived; - -// Callback test function -void OnStartInput(TextInput textInput) -{ - gHasStartSignalBeenReceived = true; -} - -// Callback test function -void OnEndInput(TextInput textInput) -{ - gHasEndSignalBeenReceived = true; -} - -} - -// Positive test case for a method -int UtcDaliTextInputConstruction(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing New constructor"); - - TextInput textInput = TextInput::New(); - DALI_TEST_CHECK(textInput); - - //Additional check to ensure object is created by checking if it's registered - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); - DALI_TEST_CHECK( registry ); - - gObjectCreatedCallBackCalled = false; - registry.ObjectCreatedSignal().Connect(&TestCallback); - { - TextInput textInput = TextInput::New(); - } - DALI_TEST_CHECK( gObjectCreatedCallBackCalled ); - END_TEST; -} - - -static bool downCastToTextInput(Dali::Actor actor) -{ - TextInput handle = TextInput::DownCast(actor); - if (handle) - { - tet_infoline("Downcasted to TextInput"); - return true; - } - else - { - tet_infoline("Did not downcast to TextInput"); - return false; - } -} - -// Positive test case for a method -int UtcDaliTextInputDownCast(void) -{ - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - - tet_infoline("Testing Downcasting with a TextInput"); - DALI_TEST_EQUALS(true,downCastToTextInput(textInput), TEST_LOCATION); // downcast a TextInput - - Dali::TextActor badHandle = Dali::TextActor::New("test"); - - tet_infoline("Testing Downcasting with the wrong actor"); - DALI_TEST_EQUALS(false, downCastToTextInput(badHandle), TEST_LOCATION); // downcast a TextActor to TextInput - END_TEST; -} - -// Positive test case for a method -int UtcDaliTextInputGetText(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing GetText"); - - const std::string teststring = "test"; - - TextInput textInput = TextInput::New(); // create empty TextInput - - DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); // Get text which should be empty - - textInput.SetInitialText(teststring); - - DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be test string - - END_TEST; -} - -int UtcDaliTextInputGetMarkupText(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing retrieval of Markup text after style set"); - - const std::string markup = "Text with italic style" ; - const std::string teststring = "Text with italic style"; - - TextInput textInput = TextInput::New(); - - tet_infoline("Set initial text"); - - textInput.SetInitialText( teststring ); - - tet_infoline("Check initial text"); - DALI_TEST_EQUALS( teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be empty - - TextStyle style; - style.SetItalics( true ); - - tet_infoline("Apply style to TextInput"); - textInput.ApplyStyleToAll( style ); - - tet_infoline("Retreive Markup Text"); - const std::string retreivedMarkupString = textInput.GetMarkupText(); - - tet_infoline("Test Retreived text and Markup text match"); - DALI_TEST_EQUALS( retreivedMarkupString , retreivedMarkupString, TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputSetMaxCharacterLength(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Setting of max characters"); - - const int maxChars = 4; - const char* testChar = "v"; - - TextInput textInput = TextInput::New(); // create empty TextInput - Stage::GetCurrent().Add(textInput); - application.SendNotification(); - application.Render(); - - textInput.SetMaxCharacterLength(maxChars); - - Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down ); - - std::string testString = ""; - - tet_infoline("Starting editmode"); - textInput.SetEditable( true ); - - tet_infoline("Sending Key Events"); - // Send max number of characters - for (int i=0; i < maxChars; i++) - { - application.ProcessEvent(event); - testString.append(testChar); - } - - tet_printf( "Get text result : %s\n", textInput.GetText().c_str()); - - DALI_TEST_EQUALS(testString, textInput.GetText(), TEST_LOCATION); - - tet_infoline("Sending Key Event which exceeds max characters"); - - application.ProcessEvent(event); // try to append additional character - - DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION); - - tet_infoline("Increase max characters limit"); - - textInput.SetMaxCharacterLength(maxChars+1); // increment max characters by 1 - - tet_infoline("Send character again which should now fit"); - application.ProcessEvent(event); // append additional character - testString.append(testChar); - - DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION); - END_TEST; -} - - -int UtcDaliTextInputSetAndGetNumberOfLines(void) -{ - ToolkitTestApplication application; - - tet_infoline("Ensuring API for setting and getting max number of lines is correct"); - - TextInput textInput = TextInput::New(); // create empty TextInput - - unsigned int numberOfLines = 1; - - textInput.SetNumberOfLinesLimit( numberOfLines ); - - DALI_TEST_EQUALS(numberOfLines ,textInput.GetNumberOfLinesLimit(), TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputGetNumberOfCharacters(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Getting number of characters"); - - const std::string initialString = "initial text"; - const std::string newInitialString = "initial text new"; - - TextInput textInput = TextInput::New(); // create empty TextInput - - textInput.SetInitialText( initialString ); - - tet_infoline("Testing TextInput contains correct number of characters "); - - DALI_TEST_EQUALS( initialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION); - - tet_infoline("Testing TextInput contains correct number of characters second phase "); - - textInput.SetInitialText( newInitialString ); - - DALI_TEST_EQUALS( newInitialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputSetAndGetPlaceholderText(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Setting of PlaceholderText"); - - const std::string initialString = "initial text"; - const std::string placeholderString = "placeholder"; - - TextInput textInput = TextInput::New(); // create empty TextInput - - tet_infoline("Testing TextInput is empty at creation "); - - DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); - - tet_infoline("Set placeholder text"); - - textInput.SetPlaceholderText( placeholderString ); - - tet_infoline("Testing TextInput contains placeholder text"); - - DALI_TEST_EQUALS( placeholderString , textInput.GetPlaceholderText(), TEST_LOCATION); - - tet_infoline("Set initial text which should replace placeholder text"); - - textInput.SetInitialText( initialString ); - - tet_infoline("Testing TextInput contains initial text when placeholder text set"); - - DALI_TEST_EQUALS( initialString,textInput.GetText(), TEST_LOCATION); - END_TEST; -} - -// Positive test case for a method -int UtcDaliTextInputSetInitialText(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Setting of Initial Text"); - - const std::string teststring = "test"; - - TextInput textInput = TextInput::New(); // create empty TextInput - - tet_infoline("Testing TextInput is empty at creation "); - - DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); - - tet_infoline("Set text to TextInput"); - - textInput.SetInitialText(teststring); - - tet_infoline("Test TextInput contains set text"); - - DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputSetEditableAndIsEditable(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing SetEditable And IsEditable"); - - const std::string initialString = "initial text"; - - TextInput textInput = TextInput::New(); // create empty TextInput - textInput.SetInitialText( initialString ); - - Stage::GetCurrent().Add(textInput); - application.SendNotification(); - application.Render(); - - bool editableStateFalse ( false ); - bool editableStateTrue ( true ); - - textInput.SetEditable ( editableStateFalse ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( editableStateFalse, textInput.IsEditable() , TEST_LOCATION); - - textInput.SetEditable ( editableStateTrue ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( editableStateTrue, textInput.IsEditable() , TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputSetEditOnTouch(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing SetEditOnTouch And IsEditOnTouch"); - - TextInput textInput = TextInput::New(); - - bool editableOnTouchOn ( true ); - bool editableOnTouchOff( false ); - - tet_infoline("Testing SetEditOnTouch disabled"); - textInput.SetEditOnTouch ( editableOnTouchOff ); - DALI_TEST_EQUALS( editableOnTouchOff, textInput.IsEditOnTouch() , TEST_LOCATION); - - tet_infoline("Testing SetEditOnTouch enabled"); - textInput.SetEditOnTouch ( editableOnTouchOn ); - DALI_TEST_EQUALS( editableOnTouchOn, textInput.IsEditOnTouch() , TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputSetTextSelectable(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing SetTextSelectable and IsTextSelectable"); - - const std::string initialString = "initial text"; - - TextInput textInput = TextInput::New(); - textInput.SetInitialText( initialString ); - - tet_infoline("Testing SetTextSelectable"); - textInput.SetTextSelectable(); - DALI_TEST_EQUALS( true, textInput.IsTextSelectable() , TEST_LOCATION); - textInput.SetTextSelectable( false ); - DALI_TEST_EQUALS( false, textInput.IsTextSelectable() , TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputTextSelection(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Text Selection"); - - const std::string initialString = "initial text"; - - TextInput textInput = TextInput::New(); - textInput.SetInitialText( initialString ); - - Stage::GetCurrent().Add(textInput); - application.SendNotification(); - application.Render(); - - textInput.SetEditable( true ); - - tet_infoline("Testing IsTextSelected negative"); - DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION); - - textInput.SelectText(1,7); - DALI_TEST_EQUALS( true, textInput.IsTextSelected(), TEST_LOCATION); - - textInput.DeSelectText(); - DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled(void) -{ - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - - bool grabHandleState = false; - - textInput.EnableGrabHandle( grabHandleState ); - - DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION); - - grabHandleState = true; - textInput.EnableGrabHandle( grabHandleState ); - - DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION); - - END_TEST; -} - -int UtcDaliTextInputSetAndGetBoundingRectangle(void) -{ - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - - Stage::GetCurrent().Add(textInput); - Vector2 stageSize = Stage::GetCurrent().GetSize(); - - const Rect boundingRectangle( 100.0f, 100.0f, stageSize.width, stageSize.height ); - - textInput.SetBoundingRectangle( boundingRectangle ); - - const Rect retreievedBoundingRectangle = textInput.GetBoundingRectangle(); - - DALI_TEST_EQUALS( boundingRectangle.x, retreievedBoundingRectangle.x, TEST_LOCATION); - DALI_TEST_EQUALS( boundingRectangle.y, retreievedBoundingRectangle.y, TEST_LOCATION); - DALI_TEST_EQUALS( boundingRectangle.width, retreievedBoundingRectangle.width, TEST_LOCATION); - DALI_TEST_EQUALS( boundingRectangle.height, retreievedBoundingRectangle.height, TEST_LOCATION); - END_TEST; -} - - -int UtcDaliTextInputSetAndGetTextAlignment01(void) -{ - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - Stage::GetCurrent().Add(textInput); - application.SendNotification(); - application.Render(); - - textInput.SetTextAlignment(static_cast( Alignment::HorizontalCenter) ); - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( static_cast( Alignment::HorizontalCenter) & textInput.GetTextAlignment()) ; - END_TEST; -} - -int UtcDaliTextInputSetAndGetTextAlignment02(void) -{ - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - textInput.SetTextAlignment(static_cast( Alignment::HorizontalCenter) ); - - bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ; - - DALI_TEST_CHECK( result ); - - result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight ); - - DALI_TEST_CHECK( !result ); - END_TEST; -} - -int UtcDaliTextInputSetSortModifier(void) -{ - tet_infoline("Testing SetSortModifier does not cause TextInput failure"); - - ToolkitTestApplication application; - - TextInput textInput = TextInput::New(); - - const float offsetToUse = 1.5f; - - textInput.SetSortModifier( offsetToUse ); - - DALI_TEST_CHECK( textInput ); - END_TEST; -} - -int UtcDaliTextInputSetAndGetSnapshotModeEnabled(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing SetSnapshotModeEnabled and IsSnapshotModeEnabled"); - - TextInput textInput = TextInput::New(); // create empty TextInput - bool snapshotMode( true ); - textInput.SetSnapshotModeEnabled( snapshotMode ); - - DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION); - - snapshotMode = false; - textInput.SetSnapshotModeEnabled( snapshotMode ); - - DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION); - END_TEST; -} - - -int UtcDaliTextInputEndSignalEmit(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Set editable false emits end signal"); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - textInput.InputFinishedSignal().Connect( &OnEndInput ); - - textInput.SetEditable(true) ; - - gHasEndSignalBeenReceived = false; - - textInput.SetEditable(false) ; - - DALI_TEST_EQUALS(true, gHasEndSignalBeenReceived, TEST_LOCATION); - END_TEST; -} - - - -int UtcDaliTextInputStartSignalEmit(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing SetEditable emits start signal"); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - textInput.InputStartedSignal().Connect( &OnStartInput ); - - gHasStartSignalBeenReceived = false; - - textInput.SetEditable(true); // Set editable first time - - DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION); - - gHasStartSignalBeenReceived = false; - - textInput.SetEditable(true); // Set editable second time, signal should not be sent again. - - DALI_TEST_EQUALS(false, gHasStartSignalBeenReceived, TEST_LOCATION); - - textInput.SetEditable(false); - - gHasStartSignalBeenReceived = false; - - textInput.SetEditable(true); // Set editable again - - DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputExceedMaxCharacters(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Max characters is obeyed when inputting key events "); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - textInput.SetMaxCharacterLength(4); - textInput.SetInitialText(""); - textInput.SetEditable(true); - - application.SendNotification(); - application.Render(); - - Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down ); - Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down ); - - application.ProcessEvent(eventA); - application.ProcessEvent(eventB); - application.ProcessEvent(eventA); - application.ProcessEvent(eventB); - - application.ProcessEvent(eventA); - application.ProcessEvent(eventB); - - tet_printf( "Get text result : %s\n", textInput.GetText().c_str()); - - DALI_TEST_EQUALS("abab",textInput.GetText(), TEST_LOCATION); // Get text which should be only 4 characters - END_TEST; -} - - - -int UtcDaliTextInputSetAndGetFadeBoundary(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: "); - - ToolkitTestApplication application; - - TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) ); - - TextInput textInput = TextInput::New(); - textInput.SetInitialText( "Hello world!" ); - - Stage::GetCurrent().Add(textInput); - application.SendNotification(); - application.Render(); - - textInput.SetFadeBoundary( fadeBoundary ); - - TextView::FadeBoundary fadeBoundary2 = textInput.GetFadeBoundary(); - - DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextInputSetAndGetWidthExceedPolicy(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextInputSetAndGetWidthExceedPolicy: "); - - const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit }; - const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int ); - - TextInput textInput = TextInput::New(); - textInput.SetInitialText( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex ) - { - textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliTextInputSetAndGetHeightExceedPolicy(void) -{ - ToolkitTestApplication application; - - tet_infoline("UtcDaliTextInputSetAndGetHeightExceedPolicy: "); - - const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit }; - const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int ); - - TextInput textInput = TextInput::New(); - textInput.SetInitialText( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex ) - { - textInput.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textInput.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliTextInputScroll(void) -{ - tet_infoline("UtcDaliTextInputScroll: "); - ToolkitTestApplication application; - - // Avoids the frame buffer texture to throw an exception. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - - TextInput view = TextInput::New(); - view.SetMultilinePolicy( TextView::SplitByNewLineChar ); - view.SetWidthExceedPolicy( TextView::Original ); - view.SetHeightExceedPolicy( TextView::Original ); - view.SetTextAlignment( static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ) ); - view.SetInitialText( "Hello world! This is a scroll test." ); - view.SetSize( 100.f, 100.f ); - view.SetSnapshotModeEnabled( false ); - - Stage::GetCurrent().Add( view ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default. - - view.SetScrollEnabled( true ); - - DALI_TEST_CHECK( view.IsScrollEnabled() ); - DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode. - - view.SetScrollPosition( Vector2( 400.f, 400.f ) ); - - application.SendNotification(); - application.Render(); - - const Vector2& scrollPosition = view.GetScrollPosition(); - DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextInputSetActiveStyle(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing Setting of Style to newly added text"); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - const std::string styledString = "Test Stringab" ; - const std::string plainString = "Test String"; - textInput.SetInitialText( plainString ); - - application.SendNotification(); - application.Render(); - - textInput.SetEditable(true); - - std::string retreivedMarkupString = textInput.GetMarkupText(); - - tet_infoline("Confirm markup text is a plain string "); - DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION); - - TextStyle style; - style.SetItalics( true ); - - tet_infoline("Apply style to TextInput"); - textInput.SetActiveStyle( style ); - - Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down ); - Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down ); - - application.SendNotification(); - application.Render(); - - application.ProcessEvent(eventA); - application.SendNotification(); - application.Render(); - - application.ProcessEvent(eventB); - application.SendNotification(); - application.Render(); - - retreivedMarkupString = textInput.GetMarkupText(); - - DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputApplyStyleToSelectedText(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing application of style to selected text "); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - const std::string styledString = "Test String to style"; - const std::string plainString = "Test String to style"; - textInput.SetInitialText( plainString ); - - application.SendNotification(); - application.Render(); - - textInput.SetEditable(true); - - std::string retreivedMarkupString = textInput.GetMarkupText(); - - tet_infoline("Confirm markup text is a plain string "); - DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION); - - TextStyle style; - style.SetItalics( true ); - - textInput.SelectText( 5, 11 ); - - tet_infoline("Apply style to selected text"); - textInput.ApplyStyle( style ); - - application.Render(); - - retreivedMarkupString = textInput.GetMarkupText(); - - DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputApplyStyleToAll(void) -{ - ToolkitTestApplication application; - - tet_infoline("Testing application of style to all text "); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - const std::string styledString = "Test String to style"; - const std::string plainString = "Test String to style"; - textInput.SetInitialText( plainString ); - - application.SendNotification(); - application.Render(); - - textInput.SetEditable(true); - - std::string retreivedMarkupString = textInput.GetMarkupText(); - - tet_infoline("Confirm markup text is a plain string "); - DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION); - - TextStyle style; - style.SetItalics( true ); - - tet_infoline("Apply style to all text"); - textInput.ApplyStyleToAll( style ); - - application.Render(); - - retreivedMarkupString = textInput.GetMarkupText(); - - DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION); - END_TEST; -} - -int UtcDaliTextInputGetStyleAtCursor(void) -{ - ToolkitTestApplication application; - - tet_infoline("Test getting style at cursor"); - - TextInput textInput = TextInput::New(); // create empty TextInput - - Stage::GetCurrent().Add(textInput); - - const std::string styledString = "Test Stringab" ; - const std::string plainString = "Test String"; - textInput.SetInitialText( plainString ); - - application.SendNotification(); - application.Render(); - - textInput.SetEditable(true); - - tet_infoline("Confirm style at cursor is default(plain)"); - TextStyle style; - Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down ); - application.ProcessEvent(eventA); - application.SendNotification(); - application.Render(); - - TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor(); - - DALI_TEST_CHECK( style == retreivedStyleAtCursor ); - DALI_TEST_CHECK( !retreivedStyleAtCursor.IsItalicsEnabled() ); - - tet_infoline("Set style before adding new character"); - style.SetItalics( true ); - textInput.SetActiveStyle( style ); - - Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down ); - application.ProcessEvent(eventB); - application.SendNotification(); - application.Render(); - - tet_infoline("Confirm style at cursor is correct style"); - retreivedStyleAtCursor = textInput.GetStyleAtCursor(); - - DALI_TEST_CHECK( retreivedStyleAtCursor.IsItalicsEnabled() ); - - tet_infoline("Confirm style at cursor is not a style that was not set"); - DALI_TEST_CHECK( !retreivedStyleAtCursor.IsUnderlineEnabled() ); - - tet_infoline("Confirm markup text is correct"); - DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION); - - - - END_TEST; -} - -int UtcDaliTextInputSetAndGetMultilinePolicy(void) -{ - ToolkitTestApplication application; - - const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar }; - const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int ); - - TextInput textInput = TextInput::New(); - Stage::GetCurrent().Add(textInput); - textInput.SetInitialText( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex ) - { - textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliTextInputSetAndGetExceedEnabled(void) -{ - ToolkitTestApplication application; - - const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit }; - const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int ); - - TextInput textInput = TextInput::New(); - Stage::GetCurrent().Add(textInput); - textInput.SetInitialText( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex ) - { - textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp deleted file mode 100644 index b3e55e8..0000000 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextView.cpp +++ /dev/null @@ -1,823 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -// Need to override adaptor classes for toolkit test harness, so include -// test harness headers before dali headers. -#include - -#include -#include - -using namespace Dali; -using namespace Toolkit; - -void utc_dali_toolkit_text_view_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void utc_dali_toolkit_text_view_cleanup(void) -{ - test_return_value = TET_PASS; -} - - -namespace -{ - -const char* const PROPERTY_TEXT = "text"; -const char* const PROPERTY_MULTILINE_POLICY = "multiline-policy"; -const char* const PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy"; -const char* const PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy"; -const char* const PROPERTY_LINE_JUSTIFICATION = "line-justification"; -const char* const PROPERTY_FADE_BOUNDARY = "fade-boundary"; -const char* const PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset"; -const char* const PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment"; -const char* const PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment"; - -bool TestEqual( float x, float y ) -{ - return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 ); -} - -static bool gObjectCreatedCallBackCalled; -static unsigned int gNumberObjectCreated; - -static void TestCallback(BaseHandle handle) -{ - gObjectCreatedCallBackCalled = true; - ++gNumberObjectCreated; -} - -static bool gTextScrolled; -static Vector2 gScrollDelta; -static void TestTextScrolled( TextView textView, Vector2 scrollDelta ) -{ - gTextScrolled = true; - gScrollDelta = scrollDelta; -} - -} // namespace - - -int UtcDaliTextViewNew(void) -{ - tet_infoline("UtcDaliTextViewNew: "); - ToolkitTestApplication application; - - // Test default constructor. - TextView view; - - DALI_TEST_CHECK( !view ); - - // Test default initialization. - view = TextView::New(); - - DALI_TEST_CHECK( view ); - - // Test copy constructor and asignment operator. - TextView viewCopy1; - - viewCopy1 = view; - - DALI_TEST_CHECK( viewCopy1 ); - - TextView viewCopy2( view ); - - DALI_TEST_CHECK( viewCopy2 ); - - // Test down cast. - Actor actorView; - - actorView = view; - - TextView downCastView = TextView::DownCast( actorView ); - - DALI_TEST_CHECK( downCastView ); - - // Test constructor with a given text. - - const std::string text( "Hello world!" ); - - const float DESCENDER = 8.0f; - - TextView view1 = TextView::New( text ); - - DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION ); - - MarkupProcessor::StyledTextArray styledText; - MarkupProcessor::GetStyledTextArray( text, styledText, true ); - - TextView view2 = TextView::New( styledText ); - - DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION ); - - // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage. - TextView::CharacterLayoutInfo characterLayoutInfo; - - DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION ); - - TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ), - Vector3( 3.f, 4.f, 5.f ), - true, - true, - false, - DESCENDER ); - - characterLayoutInfo = characterLayoutInfo2; - - DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION ); - - - TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo ); - - DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION ); - DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION ); - - // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage. - - TextView::TextLayoutInfo textLayoutInfo; - DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo ); - textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 ); - textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 ); - textLayoutInfo.mTextSize = Size( 10.f, 10.f ); - textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f ); - - TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo ); - - DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - TextView::TextLayoutInfo textLayoutInfo3; - - textLayoutInfo3 = textLayoutInfo2; - - DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - //Additional check to ensure object is created by checking if it's registered - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); - DALI_TEST_CHECK( registry ); - - gObjectCreatedCallBackCalled = false; - registry.ObjectCreatedSignal().Connect(&TestCallback); - { - TextView view = TextView::New(); - } - DALI_TEST_CHECK( gObjectCreatedCallBackCalled ); - END_TEST; -} - -int UtcDaliTextViewSetAndGetText(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetText: "); - ToolkitTestApplication application; - - TextView view = TextView::New(); - view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering. - - std::string str( "Text with differing aCeNdEr and dEcEnDeR" ); - - view.SetText( str ); - DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION ); - - MarkupProcessor::StyledTextArray styledText; - MarkupProcessor::GetStyledTextArray( str, styledText, true ); - - view.SetText( styledText ); - DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION ); - - // Test the number of text actor created. - - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); - DALI_TEST_CHECK( registry ); - - gNumberObjectCreated = 0u; - registry.ObjectCreatedSignal().Connect(&TestCallback); - - // Following string should create three text-actors ([Hel], [lo wo] and [rld]). - std::string text( "Hello world!\n" - "\n" ); - - view.SetMarkupProcessingEnabled( true ); // Enables markup processing. - - Stage::GetCurrent().Add( view ); - view.SetText( text ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewSetStyleToCurrentText(void) -{ - tet_infoline("UtcDaliTextViewSetStyleToCurrentText: "); - ToolkitTestApplication application; - - TextStyle style; - style.SetItalics( true ); - - const std::string text( "앞서 농식품부 주이석 검역검사본부\n" - "동물방역부장을 단장으로 하는\n" - "민관합동조사단은 지난달 30일부터\n" - "12일간의 현지 조사활동을 마치고\n" - "11일 새벽 귀국했습니다." ); - TextView view = TextView::New( text ); - - bool fail = false; - try - { - view.SetStyleToCurrentText( style ); - } - catch( ... ) - { - tet_printf( "Tet case fails\n" ); - fail = true; - tet_result(TET_FAIL); - } - - DALI_TEST_CHECK( !fail ); - END_TEST; -} - -int UtcDaliTextViewSetAndGetLineHeight(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetLineHeight: "); - - ToolkitTestApplication application; - - const float lineHeightOffset( 9.f ); - - TextView textView = TextView::New(); - - textView.SetLineHeightOffset( PointSize( lineHeightOffset ) ); - - DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewSetAndGetFadeBoundary(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: "); - - ToolkitTestApplication application; - - TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) ); - - TextView textView = TextView::New( "Hello world!" ); - - textView.SetFadeBoundary( fadeBoundary ); - - TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary(); - - DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION ); - DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewSetAndGetEllipsizeText(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: "); - - ToolkitTestApplication application; - - TextView textView = TextView::New( "Hello world!" ); - - textView.SetEllipsizeText( std::string( "..." ) ); - - DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION ); - - Toolkit::MarkupProcessor::StyledTextArray styledTextArray; - - GetStyledTextArray( std::string( "..." ), styledTextArray, true ); - - textView.SetEllipsizeText( styledTextArray ); - - DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliTextViewSetAndGetWidthExceedPolicy(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: "); - - ToolkitTestApplication application; - - const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit }; - const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int ); - - TextView textView = TextView::New( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex ) - { - textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} - -int UtcDaliTextViewSetAndGetHeightExceedPolicy(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: "); - - ToolkitTestApplication application; - - const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit }; - const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int ); - - TextView textView = TextView::New( "Hello world!" ); - - for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex ) - { - textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] ); - - DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION ); - } - END_TEST; -} - -/* -// Re-enable this test case when ALL layout options work in TextView, currently this breaks TCT -// output because too many warnings/errors are printed out -//int UtcDaliTextViewTestLayoutOptions01(void) -{ - tet_infoline("UtcDaliTextViewTestLayoutOptions01: "); - - ToolkitTestApplication application; - - const std::string text( "앞서 농식품부 주이석 검역검사본부\n" - "동물방역부장을 단장으로 하는\n" - "민관합동조사단은 지난달 30일부터\n" - "12일간의 현지 조사활동을 마치고\n" - "11일 새벽 귀국했습니다." ); - - const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar }; - const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd }; - const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit }; - const Alignment::Type TEXT_ALIGNMENT[] = { static_cast( Alignment::HorizontalLeft | Alignment::VerticalTop ), - static_cast( Alignment::HorizontalLeft | Alignment::VerticalCenter ), - static_cast( Alignment::HorizontalLeft | Alignment::VerticalBottom ), - static_cast( Alignment::HorizontalCenter | Alignment::VerticalTop ), - static_cast( Alignment::HorizontalCenter | Alignment::VerticalCenter ), - static_cast( Alignment::HorizontalCenter | Alignment::VerticalBottom ), - static_cast( Alignment::HorizontalRight | Alignment::VerticalTop ), - static_cast( Alignment::HorizontalRight | Alignment::VerticalCenter ), - static_cast( Alignment::HorizontalRight | Alignment::VerticalBottom ) }; - const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified }; - - const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int ); - const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int ); - const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int ); - const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int ); - const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int ); - - TextView textView = TextView::New( text ); - textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering. - - Stage::GetCurrent().Add( textView ); - - TextView::TextLayoutInfo textLayoutInfo; - - for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex ) - { - textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] ); - for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex ) - { - textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] ); - for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex ) - { - textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] ); - for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex ) - { - textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] ); - for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex ) - { - textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] ); - - try - { - textView.GetTextLayoutInfo( textLayoutInfo ); - - application.SendNotification(); - application.Render(); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_EQUALS( e.condition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf( "Tet case fails\n" ); - tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] ); - tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] ); - tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] ); - tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] ); - tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] ); - tet_result(TET_FAIL); - } - - DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() ); - } - DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() ); - } - DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() ); - } - DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() ); - } - DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() ); - } - END_TEST; -} -*/ - -int UtcDaliTextViewTestLayoutOptions02(void) -{ - tet_infoline("UtcDaliTextViewTestLayoutOptions02: "); - ToolkitTestApplication application; - - // Check some configurations. - - TextView textView = TextView::New(); - textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering. - textView.SetMarkupProcessingEnabled( true ); // Enables markup processing. - - Stage::GetCurrent().Add( textView ); - - // SplitByWord and ShrinkToFit. - // Centered alignment. - // Centered justification. - // Don't create a text actor per character. - - textView.SetMultilinePolicy( TextView::SplitByWord ); - textView.SetWidthExceedPolicy( TextView::ShrinkToFit ); - textView.SetHeightExceedPolicy( TextView::ShrinkToFit ); - textView.SetTextAlignment( static_cast( Alignment::HorizontalCenter | Alignment::VerticalTop ) ); - textView.SetLineJustification( TextView::Center ); - textView.SetSize( 136.56252f, 100.f ); - - textView.SetText( "Hello world!" ); - - application.SendNotification(); - application.Render(); - - std::vector sizes; - sizes.push_back( Size( 34.14063f, 11.380210f ) ); // - sizes.push_back( Size( 56.90105f, 11.380210f ) ); // - sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210. - // The result should be a line with the text 'Hello world' as shown below. - std::vector positions; // ____________ - positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!| - positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------ - positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); // - - DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors. - - for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index ) - { - const Vector3& size = textView.GetChildAt(index).GetCurrentSize(); - const Vector3& position = textView.GetChildAt(index).GetCurrentPosition(); - - DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - } - - textView.SetPreferredSize( Vector2( 50.0f, 50.0f ) ); - textView.SetTextAlignment( static_cast( Alignment::HorizontalCenter | Alignment::VerticalCenter ) ); - textView.SetResizePolicy( FIXED, ALL_DIMENSIONS ); - textView.SetLineJustification( Toolkit::TextView::Left ); - - application.SendNotification(); - application.Render(); - - sizes.clear(); - sizes.push_back( Size( 24.999999f, 8.333333f ) ); // - sizes.push_back( Size( 24.999999f, 8.333333f ) ); // - sizes.push_back( Size( 16.666666f, 8.333333f ) ); // Longest word is 'world!' (6 characters x 11.380210) which doesn't fit in the 50x50 box. - sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333. - // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one. - positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and - positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25). - positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______ - positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | | - positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello | - // |world!| - // |______| - // - - DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors. - - for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index ) - { - const Vector3& size = textView.GetChildAt(index).GetCurrentSize(); - const Vector3& position = textView.GetChildAt(index).GetCurrentPosition(); - - DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - } - - // TODO: Add more tests when TextView implementation is finished. - END_TEST; -} - -int UtcDaliTextViewInsertRemoveText(void) -{ - tet_infoline("UtcDaliTextViewInsertRemoveText: "); - ToolkitTestApplication application; - - std::string text("Hello "); - - MarkupProcessor::StyledTextArray styledText; - MarkupProcessor::GetStyledTextArray( text, styledText, true ); - - TextView view = TextView::New( "world!" ); - - view.InsertTextAt( 0, styledText ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION ); - - view.RemoveTextFrom( 4, 5 ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION ); - - view.InsertTextAt( 0, "Hello " ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION ); - - - view.InsertTextAt( 0, "Hello " ); - view.InsertTextAt( 0, "Hello " ); - view.InsertTextAt( 0, "Hello " ); - view.InsertTextAt( 0, "Hello " ); - view.RemoveTextFrom( 4, 2 ); - view.RemoveTextFrom( 4, 2 ); - view.RemoveTextFrom( 4, 2 ); - view.RemoveTextFrom( 4, 2 ); - view.RemoveTextFrom( 4, 2 ); - view.SetText( "Hello world!" ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION ); - - view.ReplaceTextFromTo( 5, 1, "" ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION ); - - view.ReplaceTextFromTo( 0, 11, styledText ); - - DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewSnapshotEnable(void) -{ - tet_infoline("UtcDaliTextViewSnapshotEnable: "); - ToolkitTestApplication application; - - // Avoids the frame buffer texture to throw an exception. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - - TextView view = TextView::New(); - view.SetMarkupProcessingEnabled( true ); // Enables markup processing. - view.SetText( "Hello world! This is a snapshot test." ); - - Stage::GetCurrent().Add( view ); - - view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled. - // This line should be removed when text-view is set to use the snapshot mode by default. - - // Snapshot is enabled by default. - DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); - - application.SendNotification(); - application.Render(); - - // TextView should have only two actors: - // the root (Actor) and the image (ImageActor). - - DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION ); - - view.SetSnapshotModeEnabled( false ); - DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() ); - - application.SendNotification(); - application.Render(); - - // TextView should have one text-actor per word. - - DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewScroll(void) -{ - tet_infoline("UtcDaliTextViewScroll: "); - ToolkitTestApplication application; - - // Avoids the frame buffer texture to throw an exception. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - - TextView view = TextView::New( "Hello world! This is a scroll test." ); - view.SetSize( 100.f, 100.f ); - view.SetSnapshotModeEnabled( false ); - - Stage::GetCurrent().Add( view ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default. - - view.SetScrollEnabled( true ); - view.ScrolledSignal().Connect( &TestTextScrolled ); - - DALI_TEST_CHECK( view.IsScrollEnabled() ); - DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode. - - gTextScrolled = false; - gScrollDelta = Vector2::ZERO; - view.SetScrollPosition( Vector2( 400.f, 400.f ) ); - - application.SendNotification(); - application.Render(); - - const Vector2& scrollPosition = view.GetScrollPosition(); - DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - DALI_TEST_CHECK( gTextScrolled ); - DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - DALI_TEST_CHECK( view.IsScrollPositionTrimmed() ); - END_TEST; -} - -int UtcDaliTextViewSetProperty(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetText: "); - ToolkitTestApplication application; - - TextView view = TextView::New( "Hello world!" ); - Stage::GetCurrent().Add( view ); - - //Test multiline policy property - view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar"); - DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByWord"); - DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByChar"); - DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() ); - - //Test width exceed policy property - view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Original"); - view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Original"); - DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() ); - DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Fade"); - view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Fade"); - DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() ); - DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit"); - view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit"); - DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() ); - DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() ); - - //Test line justification property - view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Left"); - DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Center"); - DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Right"); - DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Justified"); - DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() ); - - //Test fade boundary property - const Vector4 testValue( 23.f, 26.f, 2.f, 11.f ); - - view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY), testValue); - DALI_TEST_CHECK( testValue.x == view.GetFadeBoundary().mLeft ); - DALI_TEST_CHECK( testValue.y == view.GetFadeBoundary().mRight ); - DALI_TEST_CHECK( testValue.z == view.GetFadeBoundary().mTop ); - DALI_TEST_CHECK( testValue.w == view.GetFadeBoundary().mBottom ); - - //Test Line height offset property - float testOffsetValue = 14.04f; - view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue); - DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() ); - - //Test alignment property - view.SetProperty(view.GetPropertyIndex(PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft"); - view.SetProperty(view.GetPropertyIndex(PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop"); - DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() ); - END_TEST; -} - -int UtcDaliTextViewSetSortModifier(void) -{ - tet_infoline("UtcDaliTextViewSetAndGetText: "); - ToolkitTestApplication application; - - TextView view = TextView::New( "Hello world!" ); - Stage::GetCurrent().Add( view ); - - view.SetSortModifier( 10.f ); - view.SetSnapshotModeEnabled( false ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliTextViewUnderlineText(void) -{ - tet_infoline("UtcDaliTextViewUnderlineText: "); - ToolkitTestApplication application; - - TextView textView = TextView::New(); - textView.SetSnapshotModeEnabled( false ); - textView.SetMarkupProcessingEnabled( true ); - textView.SetText( "gggggggggggggg" ); - - textView.SetSize( 150.f, 100.f ); - - Stage::GetCurrent().Add( textView ); - - application.SendNotification(); - application.Render(); - - std::vector positions; - positions.push_back( 6.448784f ); - positions.push_back( 9.862847f ); - positions.push_back( 13.276909f ); - positions.push_back( 16.690973f ); - positions.push_back( 13.276909f ); - positions.push_back( 9.862847f ); - positions.push_back( 6.448784f ); - - for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index ) - { - TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle(); - - DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - } - END_TEST; -} -- 2.7.4