X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-Text-Cursor.cpp;h=920a826af8636dd766e359400b471510247a5be3;hb=0c862d5823332bc2161c64f901395f2390c82fd2;hp=1e2b72d0d292873cd4dd0ae4487800b44b4e6142;hpb=632c0f0659030bea7e4854c815c88a1eeabcf843;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp old mode 100644 new mode 100755 index 1e2b72d..920a826 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -16,8 +16,8 @@ */ #include - #include +#include #include #include @@ -46,6 +46,8 @@ using namespace Text; namespace { + const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); + const unsigned int DEFAULT_FONT_SIZE = 1152u; struct GetClosestLineData { @@ -92,13 +94,21 @@ struct FindSelectionIndicesData CharacterIndex* noTextHitIndex; ///< The expected character index when there is no hit. }; +struct PrimaryCursorHeightData +{ + std::string description; ///< Description of the test. + std::string text; ///< Input text. + unsigned int numberOfTests; ///< The number of tests. + CharacterIndex* logicalIndex; ///< The logical cursor index for each test. + float* heights; ///< The expected primary cursor height for each test. +}; + bool GetClosestLineTest( const GetClosestLineData& data ) { std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -110,9 +120,16 @@ bool GetClosestLineTest( const GetClosestLineData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, - metrics ); + textModel, + metrics, + false, + LineWrap::WORD, + false, + Toolkit::DevelText::EllipsisPosition::END, + 0.f ); + + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; for( unsigned int index = 0; index < data.numberOfTests; ++index ) { @@ -141,8 +158,7 @@ bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -154,9 +170,16 @@ bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, - metrics ); + textModel, + metrics, + false, + LineWrap::WORD, + false, + Toolkit::DevelText::EllipsisPosition::END, + 0.f ); + + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; for( unsigned int index = 0; index < data.numberOfTests; ++index ) { @@ -189,8 +212,7 @@ bool GetCursorPositionTest( const GetCursorPositionData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -202,28 +224,41 @@ bool GetCursorPositionTest( const GetCursorPositionData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, - metrics ); + textModel, + metrics, + false, + LineWrap::WORD, + false, + Toolkit::DevelText::EllipsisPosition::END, + 0.f ); + + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + + GetCursorPositionParameters parameters; + parameters.visualModel = visualModel; + parameters.logicalModel = logicalModel; + parameters.metrics = metrics; + parameters.isMultiline = true; for( unsigned int index = 0; index < data.numberOfTests; ++index ) { CursorInfo cursorInfo; - GetCursorPosition( visualModel, - logicalModel, - metrics, - data.logicalIndex[index], + parameters.logical = data.logicalIndex[index]; + + GetCursorPosition( parameters, + 0.f,// Since this test case is not testing the primary cursor height, the default font line height can be set to 0.f. cursorInfo ); - if( cursorInfo.primaryPosition.x != data.visualX[index] ) + if( floor(cursorInfo.primaryPosition.x) != data.visualX[index] ) { std::cout << " test " << index << " failed. Different 'x' cursor position : " << cursorInfo.primaryPosition.x << ", expected : " << data.visualX[index] << std::endl; return false; } - if( cursorInfo.primaryPosition.y != data.visualY[index] ) + if( floor(cursorInfo.primaryPosition.y) != data.visualY[index] ) { std::cout << " test " << index << " failed. Different 'y' cursor position : " << cursorInfo.primaryPosition.y << ", expected : " << data.visualY[index] << std::endl; - return false; + return false; } } @@ -235,8 +270,7 @@ bool FindSelectionIndicesTest( const FindSelectionIndicesData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -248,9 +282,16 @@ bool FindSelectionIndicesTest( const FindSelectionIndicesData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, - metrics ); + textModel, + metrics, + false, + LineWrap::WORD, + false, + Toolkit::DevelText::EllipsisPosition::END, + 0.f ); + + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; for( unsigned int index = 0; index < data.numberOfTests; ++index ) { @@ -290,12 +331,102 @@ bool FindSelectionIndicesTest( const FindSelectionIndicesData& data ) return true; } +bool PrimaryCursorHeightTest( const PrimaryCursorHeightData& data ) +{ + std::cout << " testing : " << data.description << std::endl; + + // 1) Create the model. + ModelPtr textModel; + MetricsPtr metrics; + Size textArea(400.f, 600.f); + Size layoutSize; + + Vector fontDescriptionRuns; + + const std::string fontFamily( "DejaVuSans" ); + + // Set a known font description + FontDescriptionRun fontDescriptionRun1; + fontDescriptionRun1.characterRun.characterIndex = 0u; + fontDescriptionRun1.characterRun.numberOfCharacters = 13u; + fontDescriptionRun1.familyLength = fontFamily.size(); + fontDescriptionRun1.familyName = new char[fontDescriptionRun1.familyLength]; + memcpy( fontDescriptionRun1.familyName, fontFamily.c_str(), fontDescriptionRun1.familyLength ); + fontDescriptionRun1.familyDefined = true; + fontDescriptionRun1.weightDefined = false; + fontDescriptionRun1.widthDefined = false; + fontDescriptionRun1.slantDefined = false; + fontDescriptionRun1.sizeDefined = true; + fontDescriptionRun1.size = 768u;//Font size = 12.0f (768/64 = 12) + + fontDescriptionRuns.PushBack( fontDescriptionRun1 ); + + LayoutOptions options; + CreateTextModel( data.text, + textArea, + fontDescriptionRuns, + options, + layoutSize, + textModel, + metrics, + false, + LineWrap::WORD, + false, + Toolkit::DevelText::EllipsisPosition::END, + 50.f ); + + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + + GetCursorPositionParameters parameters; + parameters.visualModel = visualModel; + parameters.logicalModel = logicalModel; + parameters.metrics = metrics; + parameters.isMultiline = true; + + for( unsigned int index = 0; index < data.numberOfTests; ++index ) + { + CursorInfo cursorInfo; + parameters.logical = data.logicalIndex[index]; + + // Load some fonts. + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.SetDpi( 93u, 93u ); + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName( pathNamePtr ); + free( pathNamePtr ); + + FontId fontID = fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSans.ttf" ); + + Text::FontMetrics fontMetrics; + MetricsPtr mMetrics = Metrics::New(fontClient); + mMetrics->GetFontMetrics(fontID, fontMetrics); + float defaultFontLineHeight = (fontMetrics.ascender - fontMetrics.descender); + + GetCursorPosition( parameters, + defaultFontLineHeight, + cursorInfo ); + + if( floor(cursorInfo.primaryCursorHeight) != data.heights[index] ) + { + std::cout << " test " << index << " failed. Different primaryCursorHeight : " << cursorInfo.primaryCursorHeight << ", expected : " << data.heights[index] << std::endl; + return false; + } + } + + return true; +} + } // namespace ////////////////////////////////////////////////////////// // // UtcDaliGetClosestLine // UtcDaliGetClosestCursorIndex +// UtcDaliGetCursorPosition +// UtcDaliFindSelectionIndices +// UtcDaliPrimaryCursorHeight // ////////////////////////////////////////////////////////// @@ -375,13 +506,13 @@ int UtcDaliGetClosestCursorIndex(void) float visualX02[] = { -100.f, 1000.f, 60.f, 79.f, 83.f, 148.f, 99.f }; float visualY02[] = { -100.f, 1000.f, 12.f, 12.f, 12.f, 12.f, 12.f }; CharacterHitTest::Mode mode02[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP }; - CharacterIndex logicalIndex02[] = { 0, 21u, 7u, 10u, 11u, 13u, 20u }; + CharacterIndex logicalIndex02[] = { 0, 21u, 7u, 10u, 10u, 14u, 12u }; bool isCharacterHit02[] = { false, false, true, true, true, true, true }; float visualX03[] = { 19.f, 104.f, -2.f, 127.f }; float visualY03[] = { 12.f, 12.f, 12.f, 12.f }; CharacterHitTest::Mode mode03[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP }; - CharacterIndex logicalIndex03[] = { 3u, 12u, 0, 18u }; + CharacterIndex logicalIndex03[] = { 3u, 13u, 0, 18u }; bool isCharacterHit03[] = { true, true, false, false }; // 0 5 _ 6 11 12 @@ -401,9 +532,9 @@ int UtcDaliGetClosestCursorIndex(void) CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP }; CharacterIndex logicalIndex04[] = { 0, 5u, 6u, 11u, 11u, 12u, 16u, 17u, 21u, 21u, - 22u, 25u, 31u, 32u, 34u, 40u, 40u, + 22u, 25u, 30u, 32u, 35u, 34u, 40u, 41u }; - bool isCharacterHit04[] = { false, true, true, false, false, + bool isCharacterHit04[] = { false, true, true, true, false, false, true, true, true, false, false, true, true, true, true, true, false }; @@ -438,12 +569,12 @@ int UtcDaliGetClosestCursorIndex(void) CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP }; - CharacterIndex logicalIndex05[] = { 0, 10u, 20u, 30u, 40u, 45u, - 46u, 50u, 60u, 70u, 80u, 92u, - 93u, 100u, 110u, 120u, 130u, 138u, - 139u, 150u, 160u, 170u, 180u, 185u, - 186u, 190u, 200u, 210u, 220u, 232u, - 233u, 240u, 250u, 260u, 265u }; + CharacterIndex logicalIndex05[] = { 0, 10u, 19u, 28u, 39u, 44u, + 45u, 48u, 59u, 66u, 78u, 87u, + 89u, 96u, 106u, 115u, 124u, 133u, + 134u, 145u, 154u, 162u, 171u, 179u, + 180u, 184u, 191u, 203u, 212u, + 221u, 222u, 233u, 241u, 251u, 265u }; bool isCharacterHit05[] = { false, true, true, true, true, false, false, true, true, true, true, false, false, true, true, true, true, false, @@ -482,12 +613,12 @@ int UtcDaliGetClosestCursorIndex(void) CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP }; - CharacterIndex logicalIndex06[] = { 0, 10u, 20u, 30u, 40u, 45u, - 46u, 50u, 60u, 70u, 80u, 92u, - 93u, 100u, 110u, 120u, 130u, 138u, - 139u, 150u, 160u, 170u, 180u, 185u, - 186u, 190u, 200u, 210u, 220u, 231u, - 232u, 240u, 250u, 260u, 265u }; + CharacterIndex logicalIndex06[] = { 0, 11u, 19u, 28u, 39u, 44u, + 45u, 48u, 57u, 65u, 78u, 87u, + 89u, 96u, 107u, 114u, 124u, 133u, + 134u, 144u, 154u, 162u, 171u, 178u, + 179u, 185u, 192u, 203u, 212u, 221u, + 222u, 232u, 240u, 251u, 265u }; bool isCharacterHit06[] = { false, true, true, true, true, false, false, true, true, true, true, false, false, true, true, true, true, false, @@ -676,14 +807,14 @@ int UtcDaliFindSelectionIndices(void) CharacterIndex endIndex03[] = { 11u }; CharacterIndex noHitText03[] = { 0u }; - float visualX04[] = { 132.f }; + float visualX04[] = { 131.f }; float visualY04[] = { 12.f }; bool found04[] = { true }; CharacterIndex startIndex04[] = { 12u }; CharacterIndex endIndex04[] = { 16u }; CharacterIndex noHitText04[] = { 0u }; - float visualX05[] = { 1.f }; + float visualX05[] = { 0.f }; float visualY05[] = { 12.f }; bool found05[] = { true }; CharacterIndex startIndex05[] = { 0 }; @@ -780,3 +911,35 @@ int UtcDaliFindSelectionIndices(void) tet_result(TET_PASS); END_TEST; } + +int UtcDaliPrimaryCursorHeight(void) +{ + tet_infoline(" UtcDaliPrimaryCursorHeight"); + + float heights[] = { 19.f }; + CharacterIndex logicalIndex[] = { 1u }; + + struct PrimaryCursorHeightData data[] = + { + { + "Testing primary cursor height when line spacing is used.", + "Hello World", + 1u, + logicalIndex, + heights, + } + }; + const unsigned int numberOfTests = 1u; + + for( unsigned int index = 0; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !PrimaryCursorHeightTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +}