[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextGeometry.cpp
index 76a8b46..13e8dee 100644 (file)
@@ -70,7 +70,7 @@ int UtcDaliTextGeometryGetLineBoundingRectangleLabel(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 16, 420, 16};
+  Rect<> expectedLineGeometry = {0, 16, 418, 16};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -123,7 +123,7 @@ int UtcDaliTextGeometryGetLineBoundingRectangleField(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(field, 0);
 
-  Rect<> expectedLineGeometry = {0, 0, 163, 36};
+  Rect<> expectedLineGeometry = {0, 0, 162, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -179,7 +179,7 @@ int UtcDaliTextGeometryLineSpacingPositiveGetLineBoundingRectangleLabel(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 56, 420, 56};
+  Rect<> expectedLineGeometry = {0, 56, 418, 56};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -207,7 +207,7 @@ int UtcDaliTextGeometryWithVerticalLineAlignmentTopGetLineBoundingRectangleLabel
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 36, 420, 36};
+  Rect<> expectedLineGeometry = {0, 36, 418, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -235,7 +235,7 @@ int UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetLineBoundingRectangleLa
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 36, 420, 36};
+  Rect<> expectedLineGeometry = {0, 36, 418, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -263,7 +263,7 @@ int UtcDaliTextGeometryWithEllipsisMiddleGetLineBoundingRectangleLabel(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 36, 420, 36};
+  Rect<> expectedLineGeometry = {0, 36, 418, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -292,7 +292,7 @@ int UtcDaliTextGeometryWithEllipsisStartGetLineBoundingRectangleLabel(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 36, 420, 36};
+  Rect<> expectedLineGeometry = {0, 36, 418, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -321,7 +321,7 @@ int UtcDaliTextGeometryWithEllipsisEndGetLineBoundingRectangleLabel(void)
 
   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
 
-  Rect<> expectedLineGeometry = {0, 36, 420, 36};
+  Rect<> expectedLineGeometry = {0, 36, 418, 36};
 
   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
 
@@ -353,7 +353,7 @@ int UtcDaliTextGeometryGetCharacterBoundingRectangleLabel(void)
 
   std::cout << " characterGeometry "<< characterGeometry <<std::endl;
 
-  Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+  Rect<> expectedCharacterGeometry = {13.0f, 16.0f, 19.0f, 16.0f};
   std::cout<< " expectedCharacterGeometry " << characterGeometry <<std::endl;
 
   std:: cout << "if" << (characterGeometry == expectedCharacterGeometry) <<std::endl;
@@ -381,7 +381,7 @@ int UtcDaliTextGeometryGetCharacterBoundingRectangleEditor(void)
 
   Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(editor, 1);
 
-  Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+  Rect<> expectedCharacterGeometry = {13.0f, 16.0f, 19.0f, 16.0f};
 
   TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
 
@@ -408,7 +408,7 @@ int UtcDaliTextGeometryGetCharacterBoundingRectangleField(void)
 
   Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(field, 0);
 
-  Rect<> expectedCharacterGeometry = {142.844f, 10.0f, 16.375f, 11.0f};
+  Rect<> expectedCharacterGeometry = {142.0f, 10.0f, 16.0f, 11.0f};
 
   TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
 
@@ -465,7 +465,7 @@ int UtcDaliTextGeometryLineSpacingPositiveGetCharacterBoundingRectangleLabel(voi
 
   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
 
-  Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+  Rect<> expectedCharGeometry = {13.0f, 16.0f, 19.0f, 16.0f};
 
   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
 
@@ -493,7 +493,7 @@ int UtcDaliTextGeometryWithVerticalLineAlignmentTopGetCharacterBoundingRectangle
 
   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
 
-  Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+  Rect<> expectedCharGeometry = {13.0, 16.0f, 19.0f, 16.0f};
 
   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
 
@@ -521,9 +521,166 @@ int UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetCharacterBoundingRectan
 
   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
 
-  Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
+  Rect<> expectedCharGeometry = {13.0, 16.0f, 19.0f, 16.0f};
 
   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
 
   END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionTextLabel(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionTextLabel");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+  label.SetProperty(TextLabel::Property::TEXT, "sara سارة");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(label, 1, 1);
+
+  int expectedCharacterIndex = 0;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionTextEditor(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionTextEditor");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK(editor);
+
+  application.GetScene().Add(editor);
+
+  editor.SetProperty(Actor::Property::SIZE, Vector2(160.0f, 250.f));
+  editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f);
+  editor.SetProperty(TextEditor::Property::TEXT, "Hello everyone.");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(editor, 2, 2);
+
+  int expectedCharacterIndex = 0;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionTextField(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionTextField");
+
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  application.GetScene().Add(field);
+
+  field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+  field.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 350.f));
+  field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
+  field.SetProperty(TextField::Property::TEXT, "مرحبا بالعالم");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(field, 18.6, 6);
+
+  int expectedCharacterIndex = 12;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionTextLabelEmptyText(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionTextLabelEmptyText");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+  label.SetProperty(TextLabel::Property::TEXT, "");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(label, 1, 0);
+
+  int expectedCharacterIndex = -1;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionLastCharacter(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionLastCharacter");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(label, 57, 2);
+
+  int expectedCharacterIndex = 4;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextGeometryGetCharacterIndexAtPositionXExceedsTextWidth(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextGeometryGetCharacterIndexAtPositionXExceedsTextWidth");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello");
+
+  application.SendNotification();
+  application.Render();
+
+  int characterIndex = TextGeometry::GetCharacterIndexAtPosition(label, 150, 1);
+
+  int expectedCharacterIndex = -1;
+
+  DALI_TEST_EQUALS(characterIndex, expectedCharacterIndex, TEST_LOCATION);
+
+  END_TEST;
 }
\ No newline at end of file