Merge "Destroy removal visuals after idler" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.cpp
index 0ece717..8db73dd 100644 (file)
@@ -1508,6 +1508,44 @@ int UtcDaliToolkitTextlabelScrollingN(void)
   const bool enabled = label.GetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL).Get<bool>();
   DALI_TEST_CHECK(!enabled);
 
+  label.SetProperty(TextLabel::Property::MULTI_LINE, false);
+  label.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 1);
+  label.SetProperty(TextLabel::Property::AUTO_SCROLL_SPEED, 9999.0f);
+  label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, true);
+
+  try
+  {
+    // Render the text.
+    application.SendNotification();
+    application.Render(1000);
+
+    application.GetScene().Remove(label);
+    application.SendNotification();
+    application.Render();
+
+    DALI_TEST_CHECK(!label.GetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL).Get<bool>());
+
+    label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, true);
+    application.GetScene().Add(label);
+
+    application.SendNotification();
+    application.Render();
+
+    DALI_TEST_CHECK(label.GetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL).Get<bool>());
+
+    label.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, (Toolkit::TextLabel::AutoScrollStopMode::Type)2); // invalid type
+    label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, false);
+
+    application.SendNotification();
+    application.Render();
+
+    DALI_TEST_CHECK(label.GetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL).Get<bool>());
+  }
+  catch(...)
+  {
+    tet_result(TET_FAIL);
+  }
+
   END_TEST;
 }
 
@@ -1975,7 +2013,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);
@@ -1999,6 +2037,113 @@ int UtcDaliToolkitTextlabelTextFit(void)
   END_TEST;
 }
 
+int UtcDaliToolkitTextlabelTextFitStressTest(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextlabelTextFitStressTest");
+  TextLabel label = TextLabel::New();
+  Vector2   size(460.0f, 100.0f);
+  label.SetProperty(Actor::Property::SIZE, size);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello world");
+
+  // connect to the text git changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextLabel::TextFitChangedSignal(label).Connect(&TestTextFitChangedCallback);
+  bool textFitChangedSignal = false;
+  label.ConnectSignal(testTracker, "textFitChanged", CallbackFunctor(&textFitChangedSignal));
+  gTextFitChangedCallBackCalled = false;
+
+  // check point size with veryvery big range
+  Property::Map textFitMapSet;
+  textFitMapSet["enable"]       = true;
+  textFitMapSet["minSize"]      = 10.f;
+  textFitMapSet["maxSize"]      = 10000.f;
+  textFitMapSet["stepSize"]     = -1.0f;
+  textFitMapSet["fontSizeType"] = "pointSize";
+
+  label.SetProperty(Toolkit::DevelTextLabel::Property::TEXT_FIT, textFitMapSet);
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 120.f);
+
+  application.GetScene().Add(label);
+
+  application.SendNotification();
+  application.Render();
+
+  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);
+  DALI_TEST_CHECK(textFitChangedSignal);
+
+  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;
@@ -2099,7 +2244,6 @@ int UtcDaliToolkitTextlabelMaxTextureSet(void)
   application.SendNotification();
   application.Render();
 
-
   END_TEST;
 }
 
@@ -2509,7 +2653,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);
 
@@ -2530,16 +2673,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);
@@ -2585,7 +2728,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);
 
@@ -2634,6 +2777,54 @@ int utcDaliTextLabelGeometryOneGlyph(void)
 
   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
 
+  positionsList.Clear();
+  sizeList.Clear();
+
+  startIndex = 2;
+  endIndex   = 0;
+
+  positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex);
+  sizeList      = DevelTextLabel::GetTextSize(label, startIndex, endIndex);
+
+  TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
+
+  END_TEST;
+}
+
+int utcDaliTextLabelGeometryNullPtr(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("utcDaliTextLabelGeometryNullPtr");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 7.f);
+  label.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+  label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
+  label.SetProperty(TextLabel::Property::TEXT, "");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  unsigned int expectedCount = 0;
+  unsigned int startIndex    = 0;
+  unsigned int endIndex      = 0;
+
+  Vector<Vector2> positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex);
+  Vector<Vector2> sizeList      = DevelTextLabel::GetTextSize(label, startIndex, endIndex);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
+  DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -2953,4 +3144,38 @@ int UtcDaliToolkitTextlabelParagraphTag(void)
   application.Render();
 
   END_TEST;
+}
+
+int utcDaliTextLabelGetTextBoundingRectangle(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextLabelGeometryEllipsisMiddle");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 7.f);
+  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);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello this is the Text Bounding Rectangle TC");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int startIndex    = 0;
+  unsigned int endIndex      = 15;
+
+  Rect<> textBoundingRectangle = DevelTextLabel::GetTextBoundingRectangle(label, startIndex, endIndex);
+  Rect<> expectedTextBoundingRectangle = {0, 0, 100, 25};
+
+  TestTextGeometryUtils::CheckRectGeometryResult(textBoundingRectangle, expectedTextBoundingRectangle);
+
+  END_TEST;
 }
\ No newline at end of file