Merge "If it is a key event that occurred in another window, it skipped" into devel...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.cpp
index 1aecd89..cf57bc0 100644 (file)
@@ -76,7 +76,9 @@ const char* const PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY = "autoScrollLoopDelay";
 const char* const PROPERTY_NAME_FONT_SIZE_SCALE        = "fontSizeScale";
 const char* const PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE = "enableFontSizeScale";
 
-const char* const PROPERTY_NAME_ELLIPSIS_POSITION = "ellipsisPosition";
+const char* const PROPERTY_NAME_ELLIPSIS_POSITION    = "ellipsisPosition";
+const char* const PROPERTY_NAME_ANCHOR_COLOR         = "anchorColor";
+const char* const PROPERTY_NAME_ANCHOR_CLICKED_COLOR = "anchorClickedColor";
 
 const std::string  DEFAULT_FONT_DIR("/resources/fonts");
 const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
@@ -356,6 +358,8 @@ int UtcDaliToolkitTextLabelGetPropertyP(void)
   DALI_TEST_CHECK(label.GetPropertyIndex(PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE) == DevelTextLabel::Property::ENABLE_FONT_SIZE_SCALE);
   DALI_TEST_CHECK(label.GetPropertyIndex(PROPERTY_NAME_ELLIPSIS_POSITION) == DevelTextLabel::Property::ELLIPSIS_POSITION);
   DALI_TEST_CHECK(label.GetPropertyIndex(PROPERTY_NAME_STRIKETHROUGH) == DevelTextLabel::Property::STRIKETHROUGH);
+  DALI_TEST_CHECK(label.GetPropertyIndex(PROPERTY_NAME_ANCHOR_COLOR) == DevelTextLabel::Property::ANCHOR_COLOR);
+  DALI_TEST_CHECK(label.GetPropertyIndex(PROPERTY_NAME_ANCHOR_CLICKED_COLOR) == DevelTextLabel::Property::ANCHOR_CLICKED_COLOR);
 
   END_TEST;
 }
@@ -464,6 +468,13 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   label.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLUE);
   DALI_TEST_EQUALS(label.GetProperty<Vector4>(TextLabel::Property::TEXT_COLOR), Color::BLUE, TEST_LOCATION);
 
+  // Check that anchor color can be properly set
+  label.SetProperty(DevelTextLabel::Property::ANCHOR_COLOR, Color::BLUE);
+  DALI_TEST_EQUALS(label.GetProperty<Vector4>(DevelTextLabel::Property::ANCHOR_COLOR), Color::BLUE, TEST_LOCATION);
+
+  label.SetProperty(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR, Color::RED);
+  DALI_TEST_EQUALS(label.GetProperty<Vector4>(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR), Color::RED, TEST_LOCATION);
+
   Property::Map strikethroughMapSet;
   Property::Map strikethroughMapGet;
 
@@ -2013,7 +2024,7 @@ int UtcDaliToolkitTextlabelTextFit(void)
   application.SendNotification();
   application.Render();
 
-  const Vector3 EXPECTED_NATURAL_SIZE(450.0f, 96.0f, 0.0f);
+  const Vector3 EXPECTED_NATURAL_SIZE(448.0f, 96.0f, 0.0f);
   DALI_TEST_EQUALS(EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION);
 
   DALI_TEST_CHECK(gTextFitChangedCallBackCalled);
@@ -2069,7 +2080,7 @@ int UtcDaliToolkitTextlabelTextFitStressTest(void)
   application.SendNotification();
   application.Render();
 
-  const Vector3 EXPECTED_NATURAL_SIZE(450.0f, 96.0f, 0.0f);
+  const Vector3 EXPECTED_NATURAL_SIZE(448.0f, 96.0f, 0.0f);
   DALI_TEST_EQUALS(EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION);
 
   DALI_TEST_CHECK(gTextFitChangedCallBackCalled);
@@ -2078,6 +2089,72 @@ int UtcDaliToolkitTextlabelTextFitStressTest(void)
   END_TEST;
 }
 
+int UtcDaliToolkitTextlabelTextFitArray(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextlabelTextFitArray");
+  TextLabel label = TextLabel::New();
+  Vector2   size(300.0f, 80.0f);
+  label.SetProperty(Actor::Property::SIZE, size);
+  label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog");
+  label.SetProperty(DevelTextLabel::Property::MIN_LINE_SIZE, 80.f);
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+  application.GetScene().Add(label);
+
+  // make sorted options.
+  std::vector<DevelTextLabel::FitOption> fitOptions;
+  fitOptions.push_back(DevelTextLabel::FitOption(10, 12));
+  fitOptions.push_back(DevelTextLabel::FitOption(8, 10));
+  fitOptions.push_back(DevelTextLabel::FitOption(6, 8));
+  fitOptions.push_back(DevelTextLabel::FitOption(4, 6));
+  fitOptions.push_back(DevelTextLabel::FitOption(20, 22));
+  fitOptions.push_back(DevelTextLabel::FitOption(22, 24));
+  fitOptions.push_back(DevelTextLabel::FitOption(12, 14));
+
+  DevelTextLabel::SetTextFitArray(label, true, fitOptions);
+
+  application.SendNotification();
+  application.Render();
+
+  bool enable = Dali::Toolkit::DevelTextLabel::IsTextFitArrayEnabled(label);
+  DALI_TEST_EQUALS(true, enable, TEST_LOCATION);
+
+  std::vector<Dali::Toolkit::DevelTextLabel::FitOption> getFitOptions = Dali::Toolkit::DevelTextLabel::GetTextFitArray(label);
+  size_t numberOfFitOptions = getFitOptions.size();
+  DALI_TEST_EQUALS(7u, numberOfFitOptions, TEST_LOCATION);
+
+  const Vector3 EXPECTED_NATURAL_SIZE(276.0f, 16.0f, 0.0f);
+  DALI_TEST_EQUALS(EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION);
+
+  std::vector<DevelTextLabel::FitOption> emptyFitOptions;
+  DevelTextLabel::SetTextFitArray(label, false, emptyFitOptions);
+
+  application.SendNotification();
+  application.Render();
+
+  enable = Dali::Toolkit::DevelTextLabel::IsTextFitArrayEnabled(label);
+  DALI_TEST_EQUALS(false, enable, TEST_LOCATION);
+
+  const Vector3 EXPECTED_NATURAL_SIZE_DISABLE(690.0f, 80.0f, 0.0f);
+  DALI_TEST_EQUALS(EXPECTED_NATURAL_SIZE_DISABLE, label.GetNaturalSize(), TEST_LOCATION);
+
+  // make unsorted options.
+  std::vector<DevelTextLabel::FitOption> unorderedFitOptions;
+  unorderedFitOptions.push_back(DevelTextLabel::FitOption(4, 6));
+  unorderedFitOptions.push_back(DevelTextLabel::FitOption(6, 8));
+  unorderedFitOptions.push_back(DevelTextLabel::FitOption(8, 10));
+  unorderedFitOptions.push_back(DevelTextLabel::FitOption(10, 8));
+
+  DevelTextLabel::SetTextFitArray(label, true, unorderedFitOptions);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliToolkitTextlabelMaxTextureSet(void)
 {
   ToolkitTestApplication application;
@@ -2374,6 +2451,56 @@ int UtcDaliToolkitTextlabelFontSizeScale(void)
   END_TEST;
 }
 
+int UtcDaliToolkitTextlabelAnchorColor(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextlabelAnchorColor");
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  // connect to the anchor clicked signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextLabel::AnchorClickedSignal(label).Connect(&TestAnchorClickedCallback);
+  bool anchorClickedSignal = false;
+  label.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal));
+
+  gAnchorClickedCallBackCalled = false;
+  label.SetProperty(TextLabel::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
+  label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
+  label.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
+  label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  // Check that anchor color can be properly set
+  label.SetProperty(DevelTextLabel::Property::ANCHOR_COLOR, Color::BLUE);
+  DALI_TEST_EQUALS(label.GetProperty<Vector4>(DevelTextLabel::Property::ANCHOR_COLOR), Color::BLUE, TEST_LOCATION);
+
+  label.SetProperty(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR, Color::RED);
+  DALI_TEST_EQUALS(label.GetProperty<Vector4>(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR), Color::RED, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  // Create a tap event to touch the text label.
+  TestGenerateTap(application, 5.0f, 25.0f, 100);
+  application.SendNotification();
+  application.Render();
+
+  // Update clicked color
+  label.SetProperty(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR, Color::BLUE);
+  DALI_TEST_EQUALS(label.GetProperty<Vector4>(DevelTextLabel::Property::ANCHOR_CLICKED_COLOR), Color::BLUE, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
+  DALI_TEST_CHECK(anchorClickedSignal);
+
+  END_TEST;
+}
+
 // Positive test for the anchorClicked signal.
 int UtcDaliToolkitTextlabelAnchorClicked(void)
 {
@@ -2419,7 +2546,7 @@ int UtcDaliToolkitTextlabelAnchorClicked(void)
 
   // sets anchor text
   label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
-  label.SetProperty(TextLabel::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
+  label.SetProperty(TextLabel::Property::TEXT, "<a color='red' clicked-color='green' href='https://www.tizen.org'>TIZEN</a>");
   label.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
   label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
   label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
@@ -2587,7 +2714,6 @@ int utcDaliTextLabelGeometryRTL(void)
   label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
   label.SetProperty(TextLabel::Property::TEXT, "line1 \nline2\nline 3\nالاخيرالسطر");
-
   // Avoid a crash when core load gl resources.
   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
 
@@ -2608,16 +2734,16 @@ int utcDaliTextLabelGeometryRTL(void)
   Vector<Vector2> expectedSizes;
   Vector<Vector2> expectedPositions;
 
-  expectedPositions.PushBack(Vector2(24, 0));
-  expectedSizes.PushBack(Vector2(33, 25));
+  expectedPositions.PushBack(Vector2(25, 0));
+  expectedSizes.PushBack(Vector2(34, 25));
 
   expectedPositions.PushBack(Vector2(-1, 25));
-  expectedSizes.PushBack(Vector2(52, 25));
+  expectedSizes.PushBack(Vector2(53, 25));
 
   expectedPositions.PushBack(Vector2(-1, 50));
-  expectedSizes.PushBack(Vector2(59, 25));
+  expectedSizes.PushBack(Vector2(60, 25));
 
-  expectedPositions.PushBack(Vector2(73, 75));
+  expectedPositions.PushBack(Vector2(75, 75));
   expectedSizes.PushBack(Vector2(37, 25));
 
   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
@@ -2663,7 +2789,7 @@ int utcDaliTextLabelGeometryGlyphMiddle(void)
   Vector<Vector2> expectedPositions;
 
   expectedPositions.PushBack(Vector2(6, 0));
-  expectedSizes.PushBack(Vector2(124, 25));
+  expectedSizes.PushBack(Vector2(125, 25));
 
   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);