X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-LogicalModel.cpp;h=fa28d6118485fa9e915c09cda2346259fbfafc8a;hp=9ec9930ad01cc989b15fc2a3616206d5b9be1926;hb=0b2e209ecfb3cedba510f53a4af58d7d8a2b3876;hpb=269ef791ecea99b85d6241ad8e39769e1db312b3 diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp index 9ec9930..fa28d61 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -39,6 +40,26 @@ using namespace Text; namespace { +struct CreateParagraphData +{ + std::string description; ///< Description of the test. + std::string text; ///< Input text. + CharacterIndex index; ///< The first character index. + Length numberOfCharacters; ///< The number of characters. + unsigned int numberOfParagraphs; ///< The expected number of paragraphs. + unsigned int* indices; ///< The expected paragraph info indices. + unsigned int* numberOfCharactersPerParagraph; ///< The expected number of characters of each paragraph. +}; + +struct FindParagraphData +{ + std::string description; ///< Description of the test. + std::string text; ///< Input text. + CharacterIndex index; ///< The first character index. + Length numberOfCharacters; ///< The number of characters. + unsigned int numberOfParagraphs; ///< The expected number of paragraphs. + unsigned int* paragraphs; ///< The expected paragraph info. +}; struct SetVisualToLogicalMapData { @@ -51,6 +72,109 @@ struct SetVisualToLogicalMapData unsigned int* visualToLogical; ///< The expected visual to logical conversion table. }; +bool CreateParagraphTest( const CreateParagraphData& data ) +{ + // 1) Create the model. + LogicalModelPtr logicalModel = LogicalModel::New(); + VisualModelPtr visualModel = VisualModel::New(); + Size textArea(100.f, 60.f); + Size layoutSize; + + Vector fontDescriptionRuns; + LayoutOptions options; + CreateTextModel( data.text, + textArea, + fontDescriptionRuns, + options, + layoutSize, + logicalModel, + visualModel ); + + // 2) Clear the paragraphs. + Vector& paragraphs = logicalModel->mParagraphInfo; + ClearCharacterRuns( data.index, + data.index + data.numberOfCharacters - 1u, + paragraphs ); + + // 3) Call the LogicalModel::CreateParagraphInfo() method + logicalModel->CreateParagraphInfo( data.index, + data.numberOfCharacters ); + + // 4) Compare the results. + if( data.numberOfParagraphs != paragraphs.Count() ) + { + std::cout << " Different number of paragraphs : " << paragraphs.Count() << ", expected : " << data.numberOfParagraphs << std::endl; + return false; + } + + unsigned int index = 0u; + for( Vector::ConstIterator it = paragraphs.Begin(), + endIt = paragraphs.End(); + it != endIt; + ++it, ++index ) + { + const ParagraphRun& paragraph( *it ); + + if( data.indices[index] != paragraph.characterRun.characterIndex ) + { + std::cout << " Different character index for paragraph : " << index << ", " << paragraph.characterRun.characterIndex << ", expected : " << data.indices[index] << std::endl; + return false; + } + if( data.numberOfCharactersPerParagraph[index] != paragraph.characterRun.numberOfCharacters ) + { + std::cout << " Different number of characters for paragraph : " << index << ", " << paragraph.characterRun.numberOfCharacters << ", expected : " << data.numberOfCharactersPerParagraph[index] << std::endl; + return false; + } + } + + return true; +} + +bool FindParagraphTest( const FindParagraphData& data ) +{ + // 1) Create the model. + LogicalModelPtr logicalModel = LogicalModel::New(); + VisualModelPtr visualModel = VisualModel::New(); + Size textArea(100.f, 60.f); + Size layoutSize; + + Vector fontDescriptionRuns; + LayoutOptions options; + CreateTextModel( data.text, + textArea, + fontDescriptionRuns, + options, + layoutSize, + logicalModel, + visualModel ); + + // 2) Find the paragraphs. + Vector paragraphs; + logicalModel->FindParagraphs( data.index, data.numberOfCharacters, paragraphs ); + + // 3) compare the results. + if( data.numberOfParagraphs != paragraphs.Count() ) + { + return false; + } + + unsigned int index = 0u; + for( Vector::ConstIterator it = paragraphs.Begin(), + endIt = paragraphs.End(); + it != endIt; + ++it, ++index ) + { + const ParagraphRunIndex paragraphIndex = *it; + + if( paragraphIndex != data.paragraphs[index] ) + { + return false; + } + } + + return true; +} + bool SetVisualToLogicalMapTest( const SetVisualToLogicalMapData& data ) { std::cout << " testing : " << data.description << std::endl; @@ -106,10 +230,158 @@ bool SetVisualToLogicalMapTest( const SetVisualToLogicalMapData& data ) } // namespace ////////////////////////////////////////////////////////// +// +// UtcDaliCreateParagraph +// UtcDaliFindParagraph +// UtcDaliSetVisualToLogicalMap +// +////////////////////////////////////////////////////////// -int UtcDaliSetVisualToLogicalMap(void) +int UtcDaliCreateParagraph(void) { ToolkitTestApplication application; + tet_infoline(" UtcDaliCreateParagraph"); + + unsigned int paragraphsIndices01[] = { 0u }; + unsigned int paragraphsNumberOfCharacters01[] = { 0u }; + unsigned int paragraphsIndices02[] = { 0u, 12u, 17u }; + unsigned int paragraphsNumberOfCharacters02[] = { 12u, 5u, 1u }; + unsigned int paragraphsIndices03[] = { 0u, 12u, 17u, 34u }; + unsigned int paragraphsNumberOfCharacters03[] = { 12u, 5u, 17u ,1u }; + + struct CreateParagraphData data[] = + { + { + "Zero characters", + "", + 0u, + 0u, + 0u, + paragraphsIndices01, + paragraphsNumberOfCharacters01, + }, + { + "Some paragraphs", + "Hello world\ndemo\n\n", + 0u, + 18u, + 3u, + paragraphsIndices02, + paragraphsNumberOfCharacters02, + }, + { + "Some paragraphs. Update the initial paragraphs.", + "Hello world\ndemo\nhello world demo\n\n", + 0u, + 17u, + 4u, + paragraphsIndices03, + paragraphsNumberOfCharacters03, + }, + { + "Some paragraphs. Update the mid paragraphs.", + "Hello world\ndemo\nhello world demo\n\n", + 12u, + 5u, + 4u, + paragraphsIndices03, + paragraphsNumberOfCharacters03, + }, + { + "Some paragraphs. Update the final paragraphs.", + "Hello world\ndemo\nhello world demo\n\n", + 17u, + 18u, + 4u, + paragraphsIndices03, + paragraphsNumberOfCharacters03, + }, + }; + const unsigned int numberOfTests = 5u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + // ToolkitTestApplication application; + if( !CreateParagraphTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliFindParagraph(void) +{ + tet_infoline(" UtcDaliFindParagraph"); + + unsigned int paragraphs01[] = {}; + unsigned int paragraphs02[] = { 0u, 1u, 2u }; + unsigned int paragraphs03[] = { 0u }; + unsigned int paragraphs04[] = { 1u }; + unsigned int paragraphs05[] = { 0u, 1u, 2u }; + + struct FindParagraphData data[] = + { + { + "Zero characters", + "", + 0u, + 100u, + 0u, + paragraphs01, + }, + { + "Some paragraphs", + "Hello world\ndemo\n\n", + 0u, + 18u, + 3u, + paragraphs02 + }, + { + "Some paragraphs", + "Hello world\ndemo\n\n", + 0u, + 12u, + 1u, + paragraphs03 + }, + { + "Some paragraphs", + "Hello world\ndemo\n\n", + 12u, + 5u, + 1u, + paragraphs04 + }, + { + "Some paragraphs", + "Hello world\ndemo\n\n", + 3u, + 15u, + 3u, + paragraphs05 + }, + }; + const unsigned int numberOfTests = 5u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !FindParagraphTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliSetVisualToLogicalMap(void) +{ tet_infoline(" UtcDaliSetVisualToLogicalMap"); unsigned int* visualToLogical01 = NULL; @@ -210,6 +482,7 @@ int UtcDaliSetVisualToLogicalMap(void) for( unsigned int index = 0u; index < numberOfTests; ++index ) { + ToolkitTestApplication application; if( !SetVisualToLogicalMapTest( data[index] ) ) { tet_result(TET_FAIL);