Add CursorPositionChanged Signal
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
index d89428a..d824c04 100644 (file)
@@ -130,6 +130,8 @@ static bool gMaxCharactersCallBackCalled;
 static bool gInputFilteredAcceptedCallbackCalled;
 static bool gInputFilteredRejectedCallbackCalled;
 static bool gInputStyleChangedCallbackCalled;
+static bool gCursorPositionChangedCallbackCalled;
+static uint32_t oldCursorPos;
 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
 
 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
@@ -224,6 +226,14 @@ static void TestAnchorClickedCallback(TextField control, const char* href, unsig
   }
 }
 
+static void TestCursorPositionChangedCallback( TextField control, unsigned int oldPos )
+{
+  tet_infoline(" TestCursorPositionChangedCallback");
+
+  gCursorPositionChangedCallbackCalled = true;
+  oldCursorPos = oldPos;
+}
+
 static void TestTextChangedCallback( TextField control )
 {
   tet_infoline(" TestTextChangedCallback");
@@ -3221,6 +3231,70 @@ int UtcDaliTextFieldSettingPlaceholder(void)
   END_TEST;
 }
 
+int UtcDaliTextFieldPlaceholderCoverage(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextFieldPlaceholderCoverage");
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  TextField fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderFontFamily() coverage.
+  Property::Map fontFamilyMap;
+  fontFamilyMap[Text::PlaceHolder::Property::FONT_FAMILY] = "Arial";
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontFamilyMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontSize coverage.
+  Property::Map fontSizeMap;
+  fontSizeMap[Text::PlaceHolder::Property::PIXEL_SIZE] = 15.0f;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontSizeMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontWeight coverage.
+  Property::Map fontStyleWeightMap;
+  Property::Map fontStyleWeightPropertyMap;
+  fontStyleWeightPropertyMap.Insert("weight", "bold");
+  fontStyleWeightMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWeightPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWeightMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontWidth coverage.
+  Property::Map fontStyleWidthMap;
+  Property::Map fontStyleWidthPropertyMap;
+  fontStyleWidthPropertyMap.Insert("width", "expanded");
+  fontStyleWidthMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWidthPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWidthMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontSlant coverage.
+  Property::Map fontStyleSlantMap;
+  Property::Map fontStyleSlantPropertyMap;
+  fontStyleSlantPropertyMap.Insert("slant", "italic");
+  fontStyleSlantMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleSlantPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleSlantMap);
+
+  END_TEST;
+}
+
 int UtcDaliTextFieldSetPaddingProperty(void)
 {
   ToolkitTestApplication application;
@@ -3912,4 +3986,106 @@ int UtcDaliToolkitTextFieldEllipsisPositionProperty(void)
   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
 
   END_TEST;
+}
+
+int utcDaliTextFieldCursorPositionChangedSignal(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextFieldCursorPositionChangedSignal");
+
+  TextField field = TextField::New();
+  DALI_TEST_CHECK( field );
+
+  application.GetScene().Add( field );
+
+  // connect to the selection changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextField::CursorPositionChangedSignal(field).Connect(&TestCursorPositionChangedCallback);
+  bool cursorPositionChangedSignal = false;
+  field.ConnectSignal( testTracker, "cursorPositionChanged",   CallbackFunctor(&cursorPositionChangedSignal) );
+
+  field.SetProperty( TextField::Property::TEXT, "Hello world Hello world" );
+  field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
+  field.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) );
+  field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  field.SetKeyInputFocus();
+
+  // Tap on the text field
+  TestGenerateTap( application, 3.0f, 25.0f );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 23, TEST_LOCATION);
+
+  gCursorPositionChangedCallbackCalled = false;
+
+  // Move to left.
+  application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION);
+
+  gCursorPositionChangedCallbackCalled = false;
+
+  // Insert D
+  application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 16, TEST_LOCATION);
+
+  gCursorPositionChangedCallbackCalled = false;
+
+  //delete one character
+  application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION);
+
+  gCursorPositionChangedCallbackCalled = false;
+
+  field.SetProperty( TextField::Property::TEXT, "Hello" );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 16, TEST_LOCATION);
+
+  gCursorPositionChangedCallbackCalled = false;
+
+  field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
+  DALI_TEST_EQUALS(oldCursorPos, 5, TEST_LOCATION);
+
+  END_TEST;
 }
\ No newline at end of file