/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
DALI_TEST_CHECK( textChangedSignal );
application.SendNotification();
-
field.SetKeyInputFocus();
gTextChangedCallBackCalled = false;
END_TEST;
}
+int utcDaliTextFieldTextChangedWithInputMethodContext(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" utcDaliTextFieldTextChangedWithInputMethodContext");
+ TextField field = TextField::New();
+ DALI_TEST_CHECK( field );
+
+
+ application.GetScene().Add( field );
+
+ // connect to the text changed signal.
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ field.TextChangedSignal().Connect(&TestTextChangedCallback);
+ bool textChangedSignal = false;
+ field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
+
+
+ // get InputMethodContext
+ std::string text;
+ InputMethodContext::EventData imfEvent;
+ InputMethodContext inputMethodContext = DevelTextField::GetInputMethodContext( field );
+
+ field.SetKeyInputFocus();
+ field.SetProperty( DevelTextField::Property::ENABLE_EDITING, true );
+
+ // input text
+ gTextChangedCallBackCalled = false;
+ imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "ㅎ", 0, 1 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( gTextChangedCallBackCalled );
+ DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ㅎ"), TEST_LOCATION );
+
+ gTextChangedCallBackCalled = false;
+ imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "호", 0, 1 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( gTextChangedCallBackCalled );
+ DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("호"), TEST_LOCATION );
+
+ gTextChangedCallBackCalled = false;
+ imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "혿", 0, 1 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( gTextChangedCallBackCalled );
+ DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("혿"), TEST_LOCATION );
+
+ gTextChangedCallBackCalled = false;
+ imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "", 0, 1 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
+ imfEvent = InputMethodContext::EventData( InputMethodContext::COMMIT, "호", 0, 1 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
+ imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "두", 1, 2 );
+ inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
+ DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( gTextChangedCallBackCalled );
+ DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("호두"), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
// Negative test for the textChanged signal.
int utcDaliTextFieldTextChangedN(void)
{
gTextChangedCallBackCalled = false;
field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
+ application.SendNotification();
+ application.Render();
DALI_TEST_CHECK( !gTextChangedCallBackCalled );
DALI_TEST_CHECK( !textChangedSignal );
application.Render();
Actor layer = field.GetChildAt( 1u );
- DALI_TEST_CHECK( layer.GetProperty< bool >( Actor::Property::IS_LAYER ) );
-
DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
END_TEST;
}
+
+int UtcDaliTextFieldSelectRange(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextFieldSelectRange ");
+
+ TextField textField = TextField::New();
+
+ application.GetScene().Add( textField );
+
+ textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+ textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ application.SendNotification();
+ application.Render();
+
+ textField.SetProperty( TextField::Property::TEXT, "Hello world" );
+
+ application.SendNotification();
+ application.Render();
+
+ textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_START , 0);
+ textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_END , 5);
+
+ // Hello is selected
+ std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+ DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
+
+ textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_START , 6);
+ textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_END , 11);
+
+ // world is selected
+ selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+ DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 6, TEST_LOCATION );
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 11, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliTextFieldEnableEditing(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextFieldEnableEditing ");
+
+ TextField textField = TextField::New();
+
+ application.GetScene().Add( textField );
+
+ textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+ textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ application.SendNotification();
+ application.Render();
+
+ textField.SetKeyInputFocus();
+ textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, false );
+ 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_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "", TEST_LOCATION );
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get<bool>(), false, TEST_LOCATION );
+
+
+ textField.SetKeyInputFocus();
+ textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, true );
+ 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_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "D", TEST_LOCATION );
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get<bool>(), true, TEST_LOCATION );
+
+ END_TEST;
+}