X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-TextLabel-internal.cpp;h=31de85066b1b157ca5548f3136d2c1407f4c8564;hb=HEAD;hp=1ac00b5eef34c46a10fd5332c7960cca55ed9898;hpb=e770d32b7703435f37ec18ceadf76df623355c24;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp index 1ac00b5..47237f8 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -18,19 +18,53 @@ #include #include +#include + #include #include #include +#include +#include #include #include -#include -#include using namespace Dali; using namespace Toolkit; using namespace Text; +namespace +{ +static int ASYNC_TEXT_THREAD_TIMEOUT = 5; + +static bool gAsyncTextRenderedCalled; +static float gAsyncTextRenderedWidth; +static float gAsyncTextRenderedHeight; + +struct CallbackFunctor +{ + CallbackFunctor(bool* callbackFlag) + : mCallbackFlag(callbackFlag) + { + } + + void operator()() + { + *mCallbackFlag = true; + } + bool* mCallbackFlag; +}; + +static void TestAsyncTextRendered(TextLabel control, float width, float height) +{ + tet_infoline(" TestAsyncTextRendered"); + gAsyncTextRenderedCalled = true; + gAsyncTextRenderedWidth = width; + gAsyncTextRenderedHeight = height; +} + +} // namespace + int UtcDaliTextLabelMarkupUnderline(void) { ToolkitTestApplication application; @@ -1221,3 +1255,262 @@ int UtcDaliTextLabelMarkupParagraphTagAlignAttribute(void) END_TEST; } + +int UtcDaliTextLabelMarkupCharacterSpacingTag(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLabelMarkupCharacterSpacingTag "); + + const Length EXPECTED_NUMBER_OF_GLYPHS = 21u; + + const float expandedCharSpacing = 10.0f; + const float condensedCharSpacing = -5.0f; + + TextLabel textLabel = TextLabel::New(); + + textLabel.SetProperty(TextLabel::Property::TEXT, "ABC EF\nABC EF\nABC EF\n"); + textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true); + textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + + application.GetScene().Add(textLabel); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel); + Text::ViewInterface& view = textLabelImpl.GetTextController()->GetView(); + + Length numberOfGlyphs = view.GetNumberOfGlyphs(); + + DALI_TEST_EQUALS(numberOfGlyphs, EXPECTED_NUMBER_OF_GLYPHS, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + Vector glyphs; + glyphs.Resize(numberOfGlyphs); + + Vector positions; + positions.Resize(numberOfGlyphs); + + float alignmentOffset = 0u; + numberOfGlyphs = view.GetGlyphs(glyphs.Begin(), + positions.Begin(), + alignmentOffset, + 0u, + numberOfGlyphs); + + const Length numberOfGlyphsOneLine = 7u; + for(Length i = 0; i < numberOfGlyphsOneLine - 1u; i++) + { + float diffLineNoCharSpacing = positions[i + 1].x - positions[i].x; + + float diffLineCondensedCharSpacing = positions[numberOfGlyphsOneLine + i + 1].x - positions[numberOfGlyphsOneLine + i].x; + DALI_TEST_EQUALS(diffLineCondensedCharSpacing, diffLineNoCharSpacing + condensedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + float diffLineExpandedCharSpacing = positions[2u * numberOfGlyphsOneLine + i + 1].x - positions[2u * numberOfGlyphsOneLine + i].x; + DALI_TEST_EQUALS(diffLineExpandedCharSpacing, diffLineNoCharSpacing + expandedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + } + + END_TEST; +} + +int UtcDaliTextLabelMarkupSpanCharacterSpacing(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLabelMarkupSpanCharacterSpacing "); + + const Length EXPECTED_NUMBER_OF_GLYPHS = 21u; + + const float expandedCharSpacing = 10.0f; + const float condensedCharSpacing = -5.0f; + + std::string testText = + "ABC EF\n" + "ABC EF\n" + "ABC EF\n"; + + TextLabel textLabel = TextLabel::New(); + + textLabel.SetProperty(TextLabel::Property::TEXT, testText); + textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true); + textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + + application.GetScene().Add(textLabel); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel); + Text::ViewInterface& view = textLabelImpl.GetTextController()->GetView(); + + Length numberOfGlyphs = view.GetNumberOfGlyphs(); + + DALI_TEST_EQUALS(numberOfGlyphs, EXPECTED_NUMBER_OF_GLYPHS, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + Vector glyphs; + glyphs.Resize(numberOfGlyphs); + + Vector positions; + positions.Resize(numberOfGlyphs); + + float alignmentOffset = 0u; + numberOfGlyphs = view.GetGlyphs(glyphs.Begin(), + positions.Begin(), + alignmentOffset, + 0u, + numberOfGlyphs); + + const Length numberOfGlyphsOneLine = 7u; + for(Length i = 0; i < numberOfGlyphsOneLine - 1u; i++) + { + float diffLineNoCharSpacing = positions[i + 1].x - positions[i].x; + + float diffLineCondensedCharSpacing = positions[numberOfGlyphsOneLine + i + 1].x - positions[numberOfGlyphsOneLine + i].x; + DALI_TEST_EQUALS(diffLineCondensedCharSpacing, diffLineNoCharSpacing + condensedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + + float diffLineExpandedCharSpacing = positions[2u * numberOfGlyphsOneLine + i + 1].x - positions[2u * numberOfGlyphsOneLine + i].x; + DALI_TEST_EQUALS(diffLineExpandedCharSpacing, diffLineNoCharSpacing + expandedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + } + + END_TEST; +} + +int UtcDaliTextLabelLocaleChange01(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLabelLocaleChange01"); + + Adaptor& adaptor = application.GetAdaptor(); + TextLabel textLabel = TextLabel::New(); + application.GetScene().Add(textLabel); + + application.SendNotification(); + application.Render(); + + std::string newLocale = "label_TEST"; + adaptor.LocaleChangedSignal().Emit(newLocale); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(newLocale.data(), GetImpl(textLabel).GetLocale(), TEST_LOCATION); + + END_TEST; +} + +int UtcDaliTextLabelLocaleChange02(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLabelLocaleChange02"); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + TextLabel label = TextLabel::New(); + DALI_TEST_CHECK(label); + + float expectedWidth = 100.0f; + float expectedHeight = 100.0f; + + label.SetProperty(DevelTextLabel::Property::RENDER_MODE, DevelTextLabel::Render::ASYNC_AUTO); + label.SetProperty(TextLabel::Property::TEXT, "Hello world Hello world"); + label.SetProperty(Actor::Property::SIZE, Vector2(expectedWidth, expectedHeight)); + label.SetProperty(TextLabel::Property::POINT_SIZE, 12); + label.SetProperty(TextLabel::Property::MULTI_LINE, true); + application.GetScene().Add(label); + + // Connect to the async text rendered signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextLabel::AsyncTextRenderedSignal(label).Connect(&TestAsyncTextRendered); + + bool asyncTextRendered = false; + label.ConnectSignal(testTracker, "asyncTextRendered", CallbackFunctor(&asyncTextRendered)); + + gAsyncTextRenderedCalled = false; + gAsyncTextRenderedWidth = 0.0f; + gAsyncTextRenderedHeight = 0.0f; + + // Request render automatically. + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, ASYNC_TEXT_THREAD_TIMEOUT), true, TEST_LOCATION); + + DALI_TEST_CHECK(gAsyncTextRenderedCalled); + DALI_TEST_CHECK(asyncTextRendered); + + DALI_TEST_EQUALS(expectedWidth, gAsyncTextRenderedWidth, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(expectedHeight, gAsyncTextRenderedHeight, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(false, label.GetProperty(DevelTextLabel::Property::MANUAL_RENDERED), TEST_LOCATION); + + Adaptor& adaptor = application.GetAdaptor(); + + application.SendNotification(); + application.Render(); + + std::string newLocale = "label_TEST"; + adaptor.LocaleChangedSignal().Emit(newLocale); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(newLocale.data(), GetImpl(label).GetLocale(), TEST_LOCATION); + + // dummy text for test. + TextLabel dummy1 = TextLabel::New(); + DALI_TEST_CHECK(dummy1); + dummy1.SetProperty(DevelTextLabel::Property::RENDER_MODE, DevelTextLabel::Render::ASYNC_MANUAL); + dummy1.SetProperty(Actor::Property::SIZE, Vector2(expectedWidth, expectedHeight)); + dummy1.SetProperty(TextLabel::Property::POINT_SIZE, 20); + dummy1.SetProperty(TextLabel::Property::MULTI_LINE, true); + + TextLabel dummy2 = TextLabel::New(); + DALI_TEST_CHECK(dummy2); + dummy2.SetProperty(DevelTextLabel::Property::RENDER_MODE, DevelTextLabel::Render::ASYNC_MANUAL); + dummy2.SetProperty(Actor::Property::SIZE, Vector2(expectedWidth, expectedHeight)); + dummy2.SetProperty(TextLabel::Property::POINT_SIZE, 20); + dummy2.SetProperty(TextLabel::Property::MULTI_LINE, true); + + asyncTextRendered = false; + gAsyncTextRenderedCalled = false; + gAsyncTextRenderedWidth = 0.0f; + gAsyncTextRenderedHeight = 0.0f; + + expectedWidth = 50.0f; + expectedHeight = 50.0f; + float dummySize = 100.0f; + + std::string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + dummy1.SetProperty(TextLabel::Property::TEXT, text); + dummy2.SetProperty(TextLabel::Property::TEXT, text); + label.SetProperty(TextLabel::Property::TEXT, text); + + // Request size computation, due to dummy's requests, text manager's loader queue is full. + DevelTextLabel::RequestAsyncNaturalSize(dummy1); + DevelTextLabel::RequestAsyncHeightForWidth(dummy1, dummySize); + DevelTextLabel::RequestAsyncNaturalSize(dummy2); + DevelTextLabel::RequestAsyncHeightForWidth(dummy2, dummySize); + + // Request render. + DevelTextLabel::RequestAsyncRenderWithFixedSize(label, expectedWidth, expectedHeight); + + newLocale = "label_TEST_2"; + adaptor.LocaleChangedSignal().Emit(newLocale); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(5, ASYNC_TEXT_THREAD_TIMEOUT), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gAsyncTextRenderedCalled); + DALI_TEST_CHECK(asyncTextRendered); + + DALI_TEST_EQUALS(expectedWidth, gAsyncTextRenderedWidth, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(expectedHeight, gAsyncTextRenderedHeight, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(true, label.GetProperty(DevelTextLabel::Property::MANUAL_RENDERED), TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(newLocale.data(), GetImpl(label).GetLocale(), TEST_LOCATION); + + END_TEST; +} \ No newline at end of file