Merge "Add a TextEditor property to limit input to maximum characters" into devel...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextEditor.cpp
old mode 100755 (executable)
new mode 100644 (file)
index f03a330..f4a05e7
@@ -101,6 +101,7 @@ const char* const PROPERTY_NAME_PLACEHOLDER                          = "placehol
 const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION               = "enableShiftSelection";
 const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE                   = "enableGrabHandle";
 const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION      = "matchSystemLanguageDirection";
+const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
 
 
 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
@@ -127,6 +128,7 @@ const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
 
 static bool gTextChangedCallBackCalled;
 static bool gInputStyleChangedCallbackCalled;
+static bool gMaxCharactersCallBackCalled;
 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
 
 struct CallbackFunctor
@@ -158,6 +160,13 @@ static void TestInputStyleChangedCallback( TextEditor control, TextEditor::Input
   gInputStyleMask = mask;
 }
 
+static void TestMaxLengthReachedCallback( TextEditor control )
+{
+  tet_infoline(" TestMaxLengthReachedCallback");
+
+  gMaxCharactersCallBackCalled = true;
+}
+
 // Generate a KeyEvent to send to Core.
 Integration::KeyEvent GenerateKey( const std::string& keyName,
                                    const std::string& logicalKey,
@@ -360,6 +369,23 @@ int UtcDaliToolkitTextEditorCopyConstructorP(void)
   END_TEST;
 }
 
+int UtcDaliTextEditorMoveConstructor(void)
+{
+  ToolkitTestApplication application;
+
+  TextEditor textEditor = TextEditor::New();
+  textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
+  DALI_TEST_CHECK( textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
+
+  TextEditor moved = std::move( textEditor );
+  DALI_TEST_CHECK( moved );
+  DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_CHECK( moved.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
+  DALI_TEST_CHECK( !textEditor );
+
+  END_TEST;
+}
+
 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
 {
   ToolkitTestApplication application;
@@ -373,6 +399,24 @@ int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
   END_TEST;
 }
 
+int UtcDaliTextEditorMoveAssignment(void)
+{
+  ToolkitTestApplication application;
+
+  TextEditor textEditor = TextEditor::New();
+  textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
+  DALI_TEST_CHECK( textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
+
+  TextEditor moved;
+  moved = std::move( textEditor );
+  DALI_TEST_CHECK( moved );
+  DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_CHECK( moved.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
+  DALI_TEST_CHECK( !textEditor );
+
+  END_TEST;
+}
+
 int UtcDaliTextEditorNewP(void)
 {
   ToolkitTestApplication application;
@@ -446,6 +490,7 @@ int UtcDaliTextEditorGetPropertyP(void)
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextEditor::Property::ENABLE_GRAB_HANDLE );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION );
+  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == DevelTextEditor::Property::MAX_LENGTH );
 
   END_TEST;
 }
@@ -475,7 +520,7 @@ int UtcDaliTextEditorSetPropertyP(void)
   tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   // Note - we can't check the defaults since the stylesheets are platform-specific
 
@@ -876,7 +921,7 @@ int utcDaliTextEditorAtlasRenderP(void)
 
   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   try
   {
@@ -900,7 +945,7 @@ int utcDaliTextEditorTextChangedP(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   // connect to the text changed signal.
   ConnectionTracker* testTracker = new ConnectionTracker();
@@ -963,7 +1008,7 @@ int utcDaliTextEditorInputStyleChanged01(void)
   bool inputStyleChangedSignal = false;
   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   // Render and notify
   application.SendNotification();
@@ -1177,7 +1222,7 @@ int utcDaliTextEditorInputStyleChanged02(void)
   bool inputStyleChangedSignal = false;
   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   // Render and notify
   application.SendNotification();
@@ -1399,7 +1444,7 @@ int utcDaliTextEditorEvent01(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
@@ -1446,7 +1491,7 @@ int utcDaliTextEditorEvent01(void)
   editor2.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
   editor2.SetProperty( Actor::Property::POSITION, Vector2( 100.f, 100.f ));
 
-  Stage::GetCurrent().Add( editor2 );
+  application.GetScene().Add( editor2 );
 
   // Render and notify
   application.SendNotification();
@@ -1484,7 +1529,7 @@ int utcDaliTextEditorEvent02(void)
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
@@ -1618,7 +1663,7 @@ int utcDaliTextEditorEvent03(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -1711,7 +1756,7 @@ int utcDaliTextEditorEvent04(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -1800,7 +1845,7 @@ int utcDaliTextEditorEvent05(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -1882,7 +1927,7 @@ int utcDaliTextEditorEvent06(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -1972,7 +2017,7 @@ int utcDaliTextEditorEvent07(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -2116,7 +2161,7 @@ int utcDaliTextEditorEvent08(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "DALi" );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -2310,7 +2355,7 @@ int utcDaliTextEditorHandles(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
@@ -2429,7 +2474,7 @@ int utcDaliTextEditorUnderPropertyStringP(void)
 
   std::string underlineSettings1( "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::UNDERLINE, underlineSettings1 );
   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), underlineSettings1, TEST_LOCATION );
@@ -2473,7 +2518,7 @@ int utcDaliTextEditorShadowPropertyStringP(void)
 
   std::string shadowSettings( "{\"color\":\"green\",\"offset\":\"2 2\",\"blurRadius\":\"0\"}" );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\",\"blurRadius\":\"0\"}" );
 
@@ -2495,7 +2540,7 @@ int utcDaliTextEditorFontStylePropertyStringP(void)
 
   std::string fontStyleSettings( "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
 
@@ -2521,7 +2566,7 @@ int utcDaliTextEditorGetPropertyLinecountP(void)
   editor.SetProperty( TextEditor::Property::TEXT,
                        "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ");
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
   lineCount =  editor.GetProperty<int>( TextEditor::Property::LINE_COUNT );
@@ -2543,7 +2588,7 @@ int utcDaliTextEditorScrollStateChangedSignalTest(void)
   TextEditor editor = TextEditor::New();
   DALI_TEST_CHECK( editor );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
   editor.SetProperty( Actor::Property::SIZE, Vector2( 50.f, 50.f ) );
@@ -2586,7 +2631,7 @@ int UtcDaliToolkitTextEditorTextWrapMode(void)
   editor.SetProperty( Actor::Property::SIZE, Vector2( 150.0f, 300.f ) );
   editor.SetProperty( TextEditor::Property::TEXT, "Hello world Hello world" );
 
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, "WORD" );
   DALI_TEST_EQUALS( editor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::WORD ), TEST_LOCATION );
@@ -2637,7 +2682,7 @@ int UtcDaliTextEditorSetPaddingProperty(void)
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
   editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   application.SendNotification();
   application.Render();
@@ -2670,7 +2715,7 @@ int UtcDaliTextEditorEnableShiftSelectionProperty(void)
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
   editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   application.SendNotification();
   application.Render();
@@ -2698,7 +2743,7 @@ int UtcDaliTextEditorEnableGrabHandleProperty(void)
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
   editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   application.SendNotification();
   application.Render();
@@ -2726,7 +2771,7 @@ int UtcDaliTextEditorMatchSystemLanguageDirectionProperty(void)
   editor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
   editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
   editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
-  Stage::GetCurrent().Add( editor );
+  application.GetScene().Add( editor );
 
   application.SendNotification();
   application.Render();
@@ -2754,3 +2799,36 @@ int UtcDaliTextEditorGetInputMethodContext(void)
 
   END_TEST;
 }
+
+int utcDaliTextEditorMaxCharactersReached(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("utcDaliTextEditorMaxCharactersReached");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK( editor );
+
+  application.GetScene().Add( editor );
+
+  const int maxNumberOfCharacters = 1;
+  editor.SetProperty( DevelTextEditor::Property::MAX_LENGTH, maxNumberOfCharacters );
+  DALI_TEST_EQUALS( editor.GetProperty<int>( DevelTextEditor::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
+
+  editor.SetKeyInputFocus();
+
+  // connect to the text changed signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextEditor::MaxLengthReachedSignal( editor ).Connect(&TestMaxLengthReachedCallback);
+  bool maxLengthReachedSignal = false;
+  editor.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
+
+  gMaxCharactersCallBackCalled = false;
+
+  application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+  application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+  DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
+  DALI_TEST_CHECK( maxLengthReachedSignal );
+
+  END_TEST;
+}