X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-TextLabel.cpp;h=4fa21f8e5b2f357180fef94c67571f81670b4159;hp=493655dbfd6ddc0b7a645d303b8cd1036a2a41d8;hb=0d07bc303ad28647afa1342319721384cc37d19f;hpb=60adf82ffbedaf4f10b55cb5f5aac1cb7d514b16 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 493655d..4fa21f8 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -24,6 +24,11 @@ #include #include #include +#include +#include +#include +#include +#include using namespace Dali; using namespace Toolkit; @@ -246,7 +251,7 @@ int UtcDaliToolkitTextLabelGetPropertyP(void) DALI_TEST_CHECK( label ); // Check Property Indices are correct - DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextLabel::Property::RENDERING_BACKEND ); + DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == DevelTextLabel::Property::RENDERING_BACKEND ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextLabel::Property::TEXT ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextLabel::Property::FONT_FAMILY ); DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextLabel::Property::FONT_STYLE ); @@ -283,8 +288,8 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) Stage::GetCurrent().Add( label ); // Note - we can't check the defaults since the stylesheets are platform-specific - label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS ); - DALI_TEST_EQUALS( (Text::RenderingType)label.GetProperty( TextLabel::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION ); + label.SetProperty( DevelTextLabel::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS ); + DALI_TEST_EQUALS( (DevelText::RenderingType)label.GetProperty( DevelTextLabel::Property::RENDERING_BACKEND ), DevelText::RENDERING_SHARED_ATLAS, TEST_LOCATION ); // Check that text can be correctly reset label.SetProperty( TextLabel::Property::TEXT, "Setting Text" ); @@ -393,8 +398,18 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) label.SetProperty( TextLabel::Property::TEXT, "MarkupText" ); DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::TEXT ), std::string("MarkupText"), TEST_LOCATION ); - application.SendNotification(); - application.Render(); + // Check for incomplete marks. + label.SetProperty( TextLabel::Property::TEXT, "MarkupText" ); + DALI_TEST_EQUALS( label.GetProperty( TextLabel::Property::TEXT ), std::string("MarkupText"), TEST_LOCATION ); + try + { + application.SendNotification(); + application.Render(); + } + catch( ... ) + { + tet_result(TET_FAIL); + } // Check autoscroll properties const int SCROLL_SPEED = 80; @@ -623,6 +638,11 @@ int UtcDaliToolkitTextLabelSetPropertyP(void) label.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); DALI_TEST_EQUALS( label.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION ); + // Check the line size property + DALI_TEST_EQUALS( label.GetProperty( DevelTextLabel::Property::MIN_LINE_SIZE ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + label.SetProperty( DevelTextLabel::Property::MIN_LINE_SIZE, 50.f ); + DALI_TEST_EQUALS( label.GetProperty( DevelTextLabel::Property::MIN_LINE_SIZE ), 50.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + application.SendNotification(); application.Render(); @@ -658,7 +678,7 @@ int UtcDaliToolkitTextlabelAtlasRenderP(void) try { // Render some text with the shared atlas backend - label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS ); + label.SetProperty( DevelTextLabel::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS ); application.SendNotification(); application.Render(); } @@ -670,7 +690,7 @@ int UtcDaliToolkitTextlabelAtlasRenderP(void) try { // Render some text with the shared atlas backend - label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_VECTOR_BASED ); + label.SetProperty( DevelTextLabel::Property::RENDERING_BACKEND, DevelText::RENDERING_VECTOR_BASED ); application.SendNotification(); application.Render(); } @@ -1011,7 +1031,7 @@ int UtcDaliToolkitTextlabelScrollingInterruptedP(void) // Avoid a crash when core load gl resources. application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); Stage::GetCurrent().Add( label ); - label.SetSize( 360.0f, 20.f ); + label.SetProperty( Actor::Property::SIZE, Vector2( 360.0f, 20.f ) ); // Turn on all the effects label.SetProperty( TextLabel::Property::MULTI_LINE, false ); label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, 50.0f ); @@ -1086,6 +1106,51 @@ int UtcDaliToolkitTextlabelScrollingN(void) END_TEST; } +int UtcDaliToolkitTextlabelScrollingWithEllipsis(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelScrollingWithEllipsis"); + + TextLabel label = TextLabel::New("Some text to scroll"); + DALI_TEST_CHECK( label ); + + Stage::GetCurrent().Add( label ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Turn on all the effects. + label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, 50.0f ); + label.SetProperty( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3 ); + label.SetProperty( TextLabel::Property::AUTO_SCROLL_SPEED, 80.0f ); + + try + { + // Enable the auto scrolling effect. + label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true ); + label.SetProperty( TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::IMMEDIATE ); + + // Disable the ellipsis + label.SetProperty( TextLabel::Property::ELLIPSIS, false ); + + // Render the text. + application.SendNotification(); + application.Render(); + + // Stop auto scrolling + label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, false ); + + // Check the ellipsis property + DALI_TEST_CHECK( !label.GetProperty( TextLabel::Property::ELLIPSIS ) ); + } + catch( ... ) + { + tet_result(TET_FAIL); + } + + END_TEST; +} + int UtcDaliToolkitTextlabelEllipsis(void) { ToolkitTestApplication application; @@ -1100,9 +1165,9 @@ int UtcDaliToolkitTextlabelEllipsis(void) Stage::GetCurrent().Add( label ); // Turn on all the effects - label.SetAnchorPoint( AnchorPoint::CENTER ); - label.SetParentOrigin( ParentOrigin::CENTER ); - label.SetSize( 360.0f, 10.f ); + label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + label.SetProperty( Actor::Property::SIZE, Vector2( 360.0f, 10.f ) ); try { @@ -1117,7 +1182,7 @@ int UtcDaliToolkitTextlabelEllipsis(void) label.SetProperty( TextLabel::Property::TEXT, "Hello world " ); label.SetProperty( DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT, false ); - label.SetSize( 400.0f, 10.f ); + label.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 10.f ) ); try { @@ -1133,7 +1198,7 @@ int UtcDaliToolkitTextlabelEllipsis(void) label.SetProperty( TextLabel::Property::TEXT, "Hello world" ); label.SetProperty( DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); - label.SetSize( 400.0f, 10.f ); + label.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 10.f ) ); try { @@ -1157,7 +1222,7 @@ int UtcDaliToolkitTextlabelTextWrapMode(void) int lineCount =0 ; TextLabel label = TextLabel::New(); - label.SetSize( 300.0f, 300.f ); + label.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.f ) ); label.SetProperty( TextLabel::Property::TEXT, "Hello world Hello world" ); label.SetProperty( TextLabel::Property::MULTI_LINE, true ); @@ -1232,7 +1297,6 @@ int UtcDaliToolkitTextLabelColorComponents(void) label.SetProperty( TextLabel::Property::TEXT_COLOR_ALPHA, 0.6f ); DALI_TEST_EQUALS( label.GetProperty< float >( TextLabel::Property::TEXT_COLOR_ALPHA ), 0.6f, TEST_LOCATION ); DALI_TEST_EQUALS( label.GetProperty< Vector4 >( TextLabel::Property::TEXT_COLOR ), Vector4( 0.0f, 0.0f, 1.0f, 0.6f ), TEST_LOCATION ); - DALI_TEST_EQUALS( label.GetProperty< Vector4 >( TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR ), Vector4( 0.0f, 0.0f, 1.0f, 0.6f ), TEST_LOCATION ); // Test a transparent text - Rendering should be skipped. label.SetProperty( TextLabel::Property::TEXT, "Hello world Hello world" ); @@ -1275,7 +1339,7 @@ int UtcDaliToolkitTextlabelTextStyle01(void) tet_infoline(" UtcDaliToolkitTextlabelTextStyle Setting Outline after Shadow"); TextLabel label = TextLabel::New(); - label.SetSize( 300.0f, 300.f ); + label.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.f ) ); label.SetProperty( TextLabel::Property::TEXT, "Hello world Hello world" ); label.SetProperty( TextLabel::Property::POINT_SIZE, 12 ); Stage::GetCurrent().Add( label ); @@ -1419,3 +1483,151 @@ int UtcDaliToolkitTextlabelVerticalLineAlignment(void) END_TEST; } + +int UtcDaliToolkitTextLabelBitmapFont(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextLabelBitmapFont"); + + DevelText::BitmapFontDescription fontDescription; + fontDescription.name = "Digits"; + fontDescription.underlinePosition = 0.f; + fontDescription.underlineThickness = 0.f; + + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0030.png", ":", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0031.png", "0", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0032.png", "1", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0033.png", "2", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0034.png", "3", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0035.png", "4", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0036.png", "5", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0037.png", "6", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0038.png", "7", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0039.png", "8", 34.f, 0.f } ); + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u003a.png", "9", 34.f, 0.f } ); + + TextAbstraction::BitmapFont bitmapFont; + DevelText::CreateBitmapFont( fontDescription, bitmapFont ); + + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetFontId( bitmapFont ); + + TextLabel label = TextLabel::New(); + + label.SetProperty( TextLabel::Property::TEXT, "0123456789:" ); + label.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" ); + + // The text has been laid out with the bitmap font if the natural size is the sum of all the width (322) and 34 height. + DALI_TEST_EQUALS( label.GetNaturalSize(), Vector3(322.f, 34.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + Stage::GetCurrent().Add( label ); + + application.SendNotification(); + application.Render(); + + // The text has been rendered if the height of the text-label is the height of the line. + DALI_TEST_EQUALS( label.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height, 34.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + END_TEST; +} + +int ConvertPointToPixel( float point ) +{ + unsigned int horizontalDpi = 0u; + unsigned int verticalDpi = 0u; + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetDpi( horizontalDpi, verticalDpi ); + + return ( point * 72.f ) / static_cast< float >( horizontalDpi ); +} + +int UtcDaliToolkitTextlabelTextFit(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelTextFit"); + TextLabel label = TextLabel::New(); + Vector2 size( 460.0f, 100.0f ); + label.SetProperty( Actor::Property::SIZE, size ); + label.SetProperty( TextLabel::Property::TEXT, "Hello world" ); + + // check point size + Property::Map textFitMapSet; + textFitMapSet["enable"] = true; + textFitMapSet["minSize"] = 10.f; + textFitMapSet["maxSize"] = 100.f; + textFitMapSet["stepSize"] = -1.f; + textFitMapSet["fontSizeType"] = "pointSize"; + + label.SetProperty( Toolkit::DevelTextLabel::Property::TEXT_FIT, textFitMapSet ); + label.SetProperty( TextLabel::Property::POINT_SIZE, 120.f); + + Stage::GetCurrent().Add( label ); + + application.SendNotification(); + application.Render(); + + const Vector3 EXPECTED_NATURAL_SIZE( 452.0f, 94.0f, 0.0f ); + DALI_TEST_EQUALS( EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION ); + + // check pixel size + textFitMapSet.Clear(); + textFitMapSet["enable"] = true; + textFitMapSet["minSize"] = ConvertPointToPixel( 10.f ); + textFitMapSet["maxSize"] = ConvertPointToPixel( 100.f ); + textFitMapSet["stepSize"] = ConvertPointToPixel ( 1.f ); + textFitMapSet["fontSizeType"] = "pixelSize"; + + label.SetProperty( Toolkit::DevelTextLabel::Property::TEXT_FIT, textFitMapSet ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliToolkitTextlabelMaxTextureSet(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelMaxTextureSet"); + + DevelText::BitmapFontDescription fontDescription; + fontDescription.name = "Digits"; + fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0030.png", ":", 200.f, 0.f } ); + + TextAbstraction::BitmapFont bitmapFont; + DevelText::CreateBitmapFont( fontDescription, bitmapFont ); + + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetFontId( bitmapFont ); + + TextLabel label = TextLabel::New(); + label.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" ); + label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); + label.SetProperty( TextLabel::Property::TEXT, ":This is a long sample text made to allow max texture size to be exceeded." ); + label.SetProperty( TextLabel::Property::POINT_SIZE, 200.f ); + label.SetProperty( TextLabel::Property::MULTI_LINE, true ); + + Property::Map underlineMapSet; + underlineMapSet.Clear(); + underlineMapSet.Insert( "enable", true ); + underlineMapSet.Insert( "color", Color::RED ); + underlineMapSet.Insert( "height", 1 ); + label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet ); + label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLUE ); + + Stage::GetCurrent().Add( label ); + + application.SendNotification(); + application.Render(); + + const int maxTextureSize = Dali::GetMaxTextureSize(); + // Whether the rendered text is greater than maxTextureSize + DALI_TEST_CHECK( label.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height > maxTextureSize ); + + // Check if the number of renderers is greater than 1. + DALI_TEST_CHECK( label.GetRendererCount() > 1u ); + + END_TEST; +}