X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-TextField.cpp;h=39cd6054d5618622450437bba92f7e75b56adbe3;hb=3feac03362a8bb2d90a8b3e5defe9d2d704d2d3c;hp=66f1875d055a6776371e11de8580d10f56b5a334;hpb=0ac0783f6dd2fc14ed111373ffa60bda4c94f587;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 66f1875..aa25cf2 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -21,12 +21,14 @@ #include #include -#include #include -#include -#include + +#include +#include #include #include +#include +#include #include "toolkit-clipboard.h" using namespace Dali; @@ -58,8 +60,6 @@ const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizont const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment"; const char* const PROPERTY_NAME_TEXT_COLOR = "textColor"; const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor"; -const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset"; -const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor"; const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor"; const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor"; const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink"; @@ -99,29 +99,30 @@ const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSiz const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis"; - -const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; +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_ENABLE_GRAB_HANDLE_POPUP = "enableGrabHandlePopup"; +const char* const PROPERTY_NAME_BACKGROUND = "textBackground"; +const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; +const char* const PROPERTY_NAME_GRAB_HANDLE_COLOR = "grabHandleColor"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. -const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval const float RENDER_FRAME_INTERVAL = 16.66f; -const float TO_MILLISECONDS = 1000.f; -const float TO_SECONDS = 1.f / TO_MILLISECONDS; - -const float SCROLL_THRESHOLD = 10.f; -const float SCROLL_SPEED = 300.f; - const unsigned int DEFAULT_FONT_SIZE = 1152u; const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); +const int KEY_RETURN_CODE = 36; const int KEY_A_CODE = 38; const int KEY_D_CODE = 40; const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); +static bool gAnchorClickedCallBackCalled; +static bool gAnchorClickedCallBackNotCalled; static bool gTextChangedCallBackCalled; static bool gMaxCharactersCallBackCalled; static bool gInputStyleChangedCallbackCalled; @@ -154,48 +155,6 @@ static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField) textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap ); } -// Generate a PanGestureEvent to send to Core -static Integration::PanGestureEvent GeneratePan( - Gesture::State state, - const Vector2& previousPosition, - const Vector2& currentPosition, - unsigned long timeDelta, - unsigned int numberOfTouches = 1) -{ - Integration::PanGestureEvent pan(state); - - pan.previousPosition = previousPosition; - pan.currentPosition = currentPosition; - pan.timeDelta = timeDelta; - pan.numberOfTouches = numberOfTouches; - - return pan; -} - -/** - * Helper to generate PanGestureEvent - * - * @param[in] application Application instance - * @param[in] state The Gesture State - * @param[in] pos The current position of touch. - */ -static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos) -{ - static Vector2 last; - - if( (state == Gesture::Started) || - (state == Gesture::Possible) ) - { - last.x = pos.x; - last.y = pos.y; - } - - application.ProcessEvent(GeneratePan(state, last, pos, 16)); - - last.x = pos.x; - last.y = pos.y; -} - /* * Simulate time passed by. * @@ -249,6 +208,18 @@ struct CallbackFunctor bool* mCallbackFlag; }; +static void TestAnchorClickedCallback(TextField control, const char* href, unsigned int hrefLength) +{ + tet_infoline(" TestAnchorClickedCallback"); + + gAnchorClickedCallBackNotCalled = false; + + if (!strcmp(href, "https://www.tizen.org") && hrefLength == strlen(href)) + { + gAnchorClickedCallBackCalled = true; + } +} + static void TestTextChangedCallback( TextField control ) { tet_infoline(" TestTextChangedCallback"); @@ -271,51 +242,27 @@ static void TestInputStyleChangedCallback( TextField control, TextField::InputSt gInputStyleMask = mask; } -// Generate a TapGestureEvent to send to Core. -Integration::TapGestureEvent GenerateTap( - Gesture::State state, - unsigned int numberOfTaps, - unsigned int numberOfTouches, - Vector2 point) -{ - Integration::TapGestureEvent tap( state ); - - tap.numberOfTaps = numberOfTaps; - tap.numberOfTouches = numberOfTouches; - tap.point = point; - - return tap; -} - -Integration::LongPressGestureEvent GenerateLongPress( - Gesture::State state, - unsigned int numberOfTouches, - Vector2 point) -{ - Integration::LongPressGestureEvent longPress( state ); - - longPress.numberOfTouches = numberOfTouches; - longPress.point = point; - return longPress; -} - // Generate a KeyEvent to send to Core. Integration::KeyEvent GenerateKey( const std::string& keyName, + const std::string& logicalKey, const std::string& keyString, int keyCode, int keyModifier, unsigned long timeStamp, const Integration::KeyEvent::State& keyState, + const std::string& compose = "", const std::string& deviceName = DEFAULT_DEVICE_NAME, const Device::Class::Type& deviceClass = Device::Class::NONE, const Device::Subclass::Type& deviceSubclass = Device::Subclass::NONE ) { return Integration::KeyEvent( keyName, + logicalKey, keyString, keyCode, keyModifier, timeStamp, keyState, + compose, deviceName, deviceClass, deviceSubclass ); @@ -329,39 +276,65 @@ bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Ma { const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index ); - if( valueGet.first.type == Property::Key::STRING ) + Property::Value* valueSet = NULL; + if ( valueGet.first.type == Property::Key::INDEX ) + { + valueSet = fontStyleMapSet.Find( valueGet.first.indexKey ); + } + else + { + // Get Key is a string so searching Set Map for a string key + valueSet = fontStyleMapSet.Find( valueGet.first.stringKey ); + } + + if( NULL != valueSet ) { - Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey ); - if( NULL != valueSet ) + if( valueSet->GetType() == Dali::Property::STRING && ( valueGet.second.Get() != valueSet->Get() ) ) { - if( valueGet.second.Get() != valueSet->Get() ) - { - tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); - return false; - } + tet_printf( "Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); + return false; } - else + else if( valueSet->GetType() == Dali::Property::BOOLEAN && ( valueGet.second.Get() != valueSet->Get() ) ) { - tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); + tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::INTEGER && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::FLOAT && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%f], expected : [%f]", valueGet.second.Get(), valueSet->Get() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::VECTOR2 && ( valueGet.second.Get() != valueSet->Get() ) ) + { + Vector2 vector2Get = valueGet.second.Get(); + Vector2 vector2Set = valueSet->Get(); + tet_printf( "Value got : [%f, %f], expected : [%f, %f]", vector2Get.x, vector2Get.y, vector2Set.x, vector2Set.y ); + return false; + } + else if( valueSet->GetType() == Dali::Property::VECTOR4 && ( valueGet.second.Get() != valueSet->Get() ) ) + { + Vector4 vector4Get = valueGet.second.Get(); + Vector4 vector4Set = valueSet->Get(); + tet_printf( "Value got : [%f, %f, %f, %f], expected : [%f, %f, %f, %f]", vector4Get.r, vector4Get.g, vector4Get.b, vector4Get.a, vector4Set.r, vector4Set.g, vector4Set.b, vector4Set.a ); return false; } } else { - Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.indexKey ); - if( NULL != valueSet ) + if ( valueGet.first.type == Property::Key::INDEX ) { - if( valueGet.second.Get() != valueSet->Get() ) - { - tet_printf( " Integer Value got : [%d], expected : [%d]", valueGet.second.Get(), valueSet->Get() ); - return false; - } + tet_printf( " The key %d doesn't exist.", valueGet.first.indexKey ); } else { - tet_printf( " The Int key %d doesn't exist.", valueGet.first.indexKey ); - return false; + tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); } + return false; } } } @@ -430,6 +403,23 @@ int UtcDaliToolkitTextFieldCopyConstructorP(void) END_TEST; } +int UtcDaliTextFieldMoveConstructor(void) +{ + ToolkitTestApplication application; + + TextField textField = TextField::New(); + textField.SetProperty( TextEditor::Property::TEXT, "Test" ); + DALI_TEST_CHECK( textField.GetProperty( TextField::Property::TEXT ) == "Test" ); + + TextField moved = std::move( textField ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( moved.GetProperty( TextField::Property::TEXT ) == "Test" ); + DALI_TEST_CHECK( !textField ); + + END_TEST; +} + int UtcDaliToolkitTextFieldAssignmentOperatorP(void) { ToolkitTestApplication application; @@ -443,6 +433,24 @@ int UtcDaliToolkitTextFieldAssignmentOperatorP(void) END_TEST; } +int UtcDaliTextFieldMoveAssignment(void) +{ + ToolkitTestApplication application; + + TextField textField = TextField::New(); + textField.SetProperty( TextEditor::Property::TEXT, "Test" ); + DALI_TEST_CHECK( textField.GetProperty( TextField::Property::TEXT ) == "Test" ); + + TextField moved; + moved = std::move( textField ); + DALI_TEST_CHECK( moved ); + DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION ); + DALI_TEST_CHECK( moved.GetProperty( TextField::Property::TEXT ) == "Test" ); + DALI_TEST_CHECK( !textField ); + + END_TEST; +} + int UtcDaliTextFieldNewP(void) { ToolkitTestApplication application; @@ -461,7 +469,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field ); // Check Property Indices are correct - DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == DevelTextField::Property::RENDERING_BACKEND ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED ); @@ -474,8 +482,6 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR ); - DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET ); - DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK ); @@ -513,6 +519,13 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextField::Property::ENABLE_SELECTION ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextField::Property::FONT_SIZE_SCALE ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextField::Property::ENABLE_GRAB_HANDLE ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP ) == DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_BACKGROUND ) == DevelTextField::Property::BACKGROUND ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_COLOR ) == DevelTextField::Property::GRAB_HANDLE_COLOR ); END_TEST; } @@ -542,13 +555,16 @@ int UtcDaliTextFieldSetPropertyP(void) tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP"); TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); // Note - we can't check the defaults since the stylesheets are platform-specific // Check the render backend property. - field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS ); - DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION ); + field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS ); + DALI_TEST_EQUALS( (DevelText::RenderingType)field.GetProperty( DevelTextField::Property::RENDERING_BACKEND ), DevelText::RENDERING_SHARED_ATLAS, TEST_LOCATION ); + + field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_VECTOR_BASED ); + DALI_TEST_EQUALS( (DevelText::RenderingType)field.GetProperty( DevelTextField::Property::RENDERING_BACKEND ), DevelText::RENDERING_VECTOR_BASED, TEST_LOCATION ); // Check text property. field.SetProperty( TextField::Property::TEXT, "Setting Text" ); @@ -581,6 +597,10 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 2.5f ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 1.0f ); + // Reset font style. fontStyleMapSet.Clear(); fontStyleMapSet.Insert( "weight", "normal" ); @@ -640,12 +660,6 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION ); - // Check shadow properties. - field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION ); - field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION ); - // Check cursor properties field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION ); @@ -694,11 +708,11 @@ int UtcDaliTextFieldSetPropertyP(void) Property::Map propertyMap; InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER; InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD; - InputMethod::ActionButtonTitle::Type actionButton = InputMethod::ActionButtonTitle::GO; + InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO; int inputVariation = 1; propertyMap["PANEL_LAYOUT"] = panelLayout; - propertyMap["AUTO_CAPITALISE"] = autoCapital; - propertyMap["ACTION_BUTTON"] = actionButton; + propertyMap["AUTO_CAPITALIZE"] = autoCapital; + propertyMap["BUTTON_ACTION"] = buttonAction; propertyMap["VARIATION"] = inputVariation; field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap ); @@ -711,12 +725,12 @@ int UtcDaliTextFieldSetPropertyP(void) DALI_TEST_EQUALS( static_cast(panelLayout), layout, TEST_LOCATION ); int capital = 0; - DALI_TEST_CHECK( map[ "AUTO_CAPITALISE" ].Get( capital ) ); + DALI_TEST_CHECK( map[ "AUTO_CAPITALIZE" ].Get( capital ) ); DALI_TEST_EQUALS( static_cast(autoCapital), capital, TEST_LOCATION ); int action = 0; - DALI_TEST_CHECK( map[ "ACTION_BUTTON" ].Get( action ) ); - DALI_TEST_EQUALS( static_cast(actionButton), action, TEST_LOCATION ); + DALI_TEST_CHECK( map[ "BUTTON_ACTION" ].Get( action ) ); + DALI_TEST_EQUALS( static_cast(buttonAction), action, TEST_LOCATION ); int variation = 0; DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) ); @@ -786,9 +800,9 @@ int UtcDaliTextFieldSetPropertyP(void) Property::Map underlineMapSet; Property::Map underlineMapGet; - underlineMapSet.Insert( "enable", "true" ); - underlineMapSet.Insert( "color", "red" ); - underlineMapSet.Insert( "height", "1" ); + underlineMapSet.Insert( "enable", true ); + underlineMapSet.Insert( "color", Color::RED ); + underlineMapSet.Insert( "height", 1 ); // Check the underline property field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet ); @@ -805,8 +819,9 @@ int UtcDaliTextFieldSetPropertyP(void) Property::Map shadowMapSet; Property::Map shadowMapGet; - shadowMapSet.Insert( "color", "green" ); - shadowMapSet.Insert( "offset", "2 2" ); + shadowMapSet.Insert( "color", Color::GREEN ); + shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) ); + shadowMapSet.Insert( "blurRadius", 3.0f ); field.SetProperty( TextField::Property::SHADOW, shadowMapSet ); @@ -842,8 +857,6 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::OUTLINE, outlineMapSet ); - outlineMapSet["color"] = "red"; - outlineMapSet["width"] = "2"; outlineMapGet = field.GetProperty( TextField::Property::OUTLINE ); DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION ); DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION ); @@ -877,12 +890,12 @@ int UtcDaliTextFieldSetPropertyP(void) Property::Map placeholderPixelSizeMapSet; Property::Map placeholderPixelSizeMapGet; Property::Map placeholderFontstyleMap; - placeholderPixelSizeMapSet["placeholderText"] = "Setting Placeholder Text"; - placeholderPixelSizeMapSet["placeholderTextFocused"] = "Setting Placeholder Text Focused"; - placeholderPixelSizeMapSet["placeholderColor"] = Color::BLUE; - placeholderPixelSizeMapSet["placeholderFontFamily"] = "Arial"; - placeholderPixelSizeMapSet["placeholderPixelSize"] = 15.0f; - placeholderPixelSizeMapSet["placeholderEllipsis"] = true; + placeholderPixelSizeMapSet["text"] = "Setting Placeholder Text"; + placeholderPixelSizeMapSet["textFocused"] = "Setting Placeholder Text Focused"; + placeholderPixelSizeMapSet["color"] = Color::BLUE; + placeholderPixelSizeMapSet["fontFamily"] = "Arial"; + placeholderPixelSizeMapSet["pixelSize"] = 15.0f; + placeholderPixelSizeMapSet["ellipsis"] = true; placeholderFontstyleMap.Insert( "weight", "bold" ); placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap; @@ -890,17 +903,27 @@ int UtcDaliTextFieldSetPropertyP(void) placeholderPixelSizeMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION ); + + tet_infoline("Test Placeholder settings set as strings is converted correctly to Property Index key and holds set value"); + Property::Map placeholderConversionMap; + placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"]; + placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ; + placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"]; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"]; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"]; + placeholderConversionMap[ Text::PlaceHolder::Property::PIXEL_SIZE ] = placeholderPixelSizeMapSet["pixelSize"]; + + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderConversionMap ), true, TEST_LOCATION ); // Check the placeholder property with point size Property::Map placeholderMapSet; Property::Map placeholderMapGet; - placeholderMapSet["placeholderText"] = "Setting Placeholder Text"; - placeholderMapSet["placeholderTextFocused"] = "Setting Placeholder Text Focused"; - placeholderMapSet["placeholderColor"] = Color::RED; - placeholderMapSet["placeholderFontFamily"] = "Arial"; - placeholderMapSet["placeholderPointSize"] = 12.0f; - placeholderMapSet["placeholderEllipsis"] = false; + placeholderMapSet["text"] = "Setting Placeholder Text"; + placeholderMapSet["textFocused"] = "Setting Placeholder Text Focused"; + placeholderMapSet["color"] = Color::RED; + placeholderMapSet["fontFamily"] = "Arial"; + placeholderMapSet["pointSize"] = 12.0f; + placeholderMapSet["ellipsis"] = false; // Check the placeholder font style property placeholderFontstyleMap.Clear(); @@ -908,44 +931,78 @@ int UtcDaliTextFieldSetPropertyP(void) placeholderFontstyleMap.Insert( "weight", "bold" ); placeholderFontstyleMap.Insert( "width", "condensed" ); placeholderFontstyleMap.Insert( "slant", "italic" ); - placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + placeholderMapSet["fontStyle"] = placeholderFontstyleMap; field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + placeholderConversionMap.Clear(); + placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"]; + placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ; + placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"]; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"]; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"]; + placeholderConversionMap[ Text::PlaceHolder::Property::POINT_SIZE ] = placeholderPixelSizeMapSet["pointSize"]; + + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION ); // Reset font style. placeholderFontstyleMap.Clear(); placeholderFontstyleMap.Insert( "weight", "normal" ); placeholderFontstyleMap.Insert( "slant", "oblique" ); - placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + placeholderMapSet["fontStyle"] = placeholderFontstyleMap; field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"]; + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION ); placeholderFontstyleMap.Clear(); placeholderFontstyleMap.Insert( "slant", "roman" ); - placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + placeholderMapSet["fontStyle"] = placeholderFontstyleMap; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"]; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); placeholderFontstyleMap.Clear(); - placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + placeholderMapSet["fontStyle"] = placeholderFontstyleMap; + placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"]; field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION ); // Check the ellipsis property DALI_TEST_CHECK( !field.GetProperty( TextField::Property::ELLIPSIS ) ); field.SetProperty( TextField::Property::ELLIPSIS, true ); DALI_TEST_CHECK( field.GetProperty( TextField::Property::ELLIPSIS ) ); + field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); + DALI_TEST_EQUALS( field.GetProperty( Actor::Property::LAYOUT_DIRECTION ), static_cast( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION ); + + // Test the ENABLE_GRAB_HANDLE_POPUP property + DALI_TEST_CHECK( field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) ); + field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP, false ); + DALI_TEST_CHECK( !field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) ); + + // Check the background property + field.SetProperty( DevelTextField::Property::BACKGROUND, Color::RED ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::BACKGROUND ), Color::RED, TEST_LOCATION ); + + //Check handle color + field.SetProperty( DevelTextField::Property::GRAB_HANDLE_COLOR, Color::GREEN ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::GRAB_HANDLE_COLOR ), Color::GREEN, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + END_TEST; } @@ -963,12 +1020,12 @@ int utcDaliTextFieldAtlasRenderP(void) application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); try { // Render some text with the shared atlas backend - field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS ); + field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS ); application.SendNotification(); application.Render(); } @@ -979,190 +1036,575 @@ int utcDaliTextFieldAtlasRenderP(void) END_TEST; } -// Positive test for the textChanged signal. -int utcDaliTextFieldTextChangedP(void) +// Positive test for the anchorClicked signal. +int utcDaliTextFieldAnchorClicked01(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldTextChangedP"); + tet_infoline(" utcDaliTextFieldAnchorClicked01"); TextField field = TextField::New(); - DALI_TEST_CHECK( field ); + DALI_TEST_CHECK(field); - Stage::GetCurrent().Add( field ); + application.GetScene().Add(field); - // connect to the text changed signal. + // connect to the anchor clicked signal. ConnectionTracker* testTracker = new ConnectionTracker(); - field.TextChangedSignal().Connect(&TestTextChangedCallback); - bool textChangedSignal = false; - field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) ); + DevelTextField::AnchorClickedSignal(field).Connect(&TestAnchorClickedCallback); + bool anchorClickedSignal = false; + field.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal)); - gTextChangedCallBackCalled = false; - field.SetProperty( TextField::Property::TEXT, "ABC" ); - DALI_TEST_CHECK( gTextChangedCallBackCalled ); - DALI_TEST_CHECK( textChangedSignal ); + gAnchorClickedCallBackCalled = false; + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(TextField::Property::ENABLE_MARKUP, true); + 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); application.SendNotification(); - + application.Render(); field.SetKeyInputFocus(); - gTextChangedCallBackCalled = false; - application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - DALI_TEST_CHECK( gTextChangedCallBackCalled ); - - END_TEST; -} - -// Negative test for the textChanged signal. -int utcDaliTextFieldTextChangedN(void) -{ - ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldTextChangedN"); - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); + // Create a tap event to touch the text field. + TestGenerateTap(application, 5.0f, 25.0f); + application.SendNotification(); + application.Render(); - Stage::GetCurrent().Add( field ); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + DALI_TEST_CHECK(anchorClickedSignal); - // connect to the text changed signal. - ConnectionTracker* testTracker = new ConnectionTracker(); - field.TextChangedSignal().Connect(&TestTextChangedCallback); - bool textChangedSignal = false; - field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) ); + gAnchorClickedCallBackNotCalled = true; + // Tap the outside of anchor, callback should not be called. + TestGenerateTap(application, 150.f, 100.f); + application.SendNotification(); + application.Render(); - gTextChangedCallBackCalled = false; - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT - DALI_TEST_CHECK( !gTextChangedCallBackCalled ); - DALI_TEST_CHECK( !textChangedSignal ); + DALI_TEST_CHECK(gAnchorClickedCallBackNotCalled); END_TEST; } -// Positive test for Max Characters reached signal. -int utcDaliTextFieldMaxCharactersReachedP(void) +// Positive test for the anchorClicked signal. +int utcDaliTextFieldAnchorClicked02(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldMaxCharactersReachedP"); + tet_infoline(" utcDaliTextFieldAnchorClicked02"); TextField field = TextField::New(); - DALI_TEST_CHECK( field ); - - Stage::GetCurrent().Add( field ); + DALI_TEST_CHECK(field); - const int maxNumberOfCharacters = 1; - field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters ); - - field.SetKeyInputFocus(); + application.GetScene().Add(field); - // connect to the text changed signal. + // connect to the anchor clicked signal. ConnectionTracker* testTracker = new ConnectionTracker(); - field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback); - bool maxLengthReachedSignal = false; - field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) ); + DevelTextField::AnchorClickedSignal(field).Connect(&TestAnchorClickedCallback); + bool anchorClickedSignal = false; + field.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal)); - gMaxCharactersCallBackCalled = false; + gAnchorClickedCallBackCalled = false; + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(TextField::Property::ENABLE_MARKUP, true); + 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); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + field.SetKeyInputFocus(); - DALI_TEST_CHECK( gMaxCharactersCallBackCalled ); - DALI_TEST_CHECK( maxLengthReachedSignal ); + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); - END_TEST; -} + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + application.Render(); -// Negative test for Max Characters reached signal. -int utcDaliTextFieldMaxCharactersReachedN(void) -{ - ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldMaxCharactersReachedN"); - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + DALI_TEST_CHECK(anchorClickedSignal); - Stage::GetCurrent().Add( field ); - const int maxNumberOfCharacters = 3; - field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters ); + // For coverage InsertTextAnchor, RemoveTextAnchor + // first index insert + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0); + application.SendNotification(); + application.Render(); + + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); field.SetKeyInputFocus(); - // connect to the text changed signal. - ConnectionTracker* testTracker = new ConnectionTracker(); - field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback); - bool maxLengthReachedSignal = false; - field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) ); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); - gMaxCharactersCallBackCalled = false; + // last index insert + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 5); + application.SendNotification(); + application.Render(); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); - DALI_TEST_CHECK( !gMaxCharactersCallBackCalled ); - DALI_TEST_CHECK( !maxLengthReachedSignal ); + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + field.SetKeyInputFocus(); - END_TEST; -} + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); -int utcDaliTextFieldInputStyleChanged01(void) -{ - ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldInputStyleChanged01"); + // mid index insert + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 2); + application.SendNotification(); + application.Render(); - // The text-field emits signals when the input style changes. These changes of style are - // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals - // can't be emitted during the size negotiation as the callbacks may update the UI. - // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation. - // This creates an implementation of the adaptor stub and a queue of idle callbacks. - application.CreateAdaptor(); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); - // Load some fonts. + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + field.SetKeyInputFocus(); - char* pathNamePtr = get_current_dir_name(); - const std::string pathName( pathNamePtr ); - free( pathNamePtr ); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); - TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); - fontClient.SetDpi( 93u, 93u ); + // first index remove + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0); + application.SendNotification(); + application.Render(); - fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE ); - fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE ); + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.ProcessEvent(GenerateKey("Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + field.SetKeyInputFocus(); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + // last index remove + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 5); + application.SendNotification(); + application.Render(); - field.SetProperty( TextField::Property::ENABLE_MARKUP, true ); - field.SetProperty( TextField::Property::TEXT, "Hello world demo" ); + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.ProcessEvent(GenerateKey("Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); - // connect to the text changed signal. - ConnectionTracker* testTracker = new ConnectionTracker(); - field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback ); - bool inputStyleChangedSignal = false; - field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) ); + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + application.Render(); - Stage::GetCurrent().Add( field ); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); - // Render and notify + // middle index + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 2); application.SendNotification(); application.Render(); - // Executes the idle callbacks added by the text control on the change of input style. - application.RunIdles(); - - gInputStyleChangedCallbackCalled = false; - gInputStyleMask = TextField::InputStyle::NONE; - inputStyleChangedSignal = false; + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.ProcessEvent(GenerateKey("Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + gAnchorClickedCallBackCalled = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) ); - - // Render and notify + TestGenerateTap(application, 30.0f, 25.0f); application.SendNotification(); application.Render(); - // Executes the idle callbacks added by the text control on the change of input style. - application.RunIdles(); + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + + // 0 ~ 1 index remove + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 0); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 1); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + + // 1 ~ 3 index remove + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 1); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 3); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + + // 3 ~ 4 index remove + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 3); + field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 4); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + gAnchorClickedCallBackCalled = false; + // Create a tap event to touch the text field. + TestGenerateTap(application, 30.0f, 25.0f); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gAnchorClickedCallBackCalled); + + // Remove front of anchor + field.SetProperty(TextField::Property::TEXT, "TIZENTIZEN"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + // Remove whole text + field.SetProperty(TextField::Property::TEXT, "TIZEN"); + DevelTextField::SelectWholeText(field); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + // Remove all with backspace + field.SetProperty(TextField::Property::TEXT, "T"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 1); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + // Remove all with delete + field.SetProperty(TextField::Property::TEXT, "T"); + field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0); + application.SendNotification(); + application.Render(); + + application.ProcessEvent(GenerateKey("Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + END_TEST; +} + +// Positive test for the textChanged signal. +int utcDaliTextFieldTextChangedP(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldTextChangedP"); + 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) ); + + gTextChangedCallBackCalled = false; + field.SetProperty( TextField::Property::TEXT, "ABC" ); + DALI_TEST_CHECK( gTextChangedCallBackCalled ); + DALI_TEST_CHECK( textChangedSignal ); + + application.SendNotification(); + field.SetKeyInputFocus(); + + gTextChangedCallBackCalled = false; + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + DALI_TEST_CHECK( gTextChangedCallBackCalled ); + + // Remove all text + field.SetProperty( TextField::Property::TEXT, "" ); + + // Pressing backspace key: TextChangedCallback should not be called when there is no text in textfield. + gTextChangedCallBackCalled = false; + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + DALI_TEST_CHECK( !gTextChangedCallBackCalled ); + + // Pressing delete key: TextChangedCallback should not be called when there is no text in textfield. + gTextChangedCallBackCalled = false; + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + DALI_TEST_CHECK( !gTextChangedCallBackCalled ); + + 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( 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( 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( 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( TextField::Property::TEXT ), std::string("호두"), TEST_LOCATION ); + + END_TEST; +} + + +// Negative test for the textChanged signal. +int utcDaliTextFieldTextChangedN(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldTextChangedN"); + 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) ); + + 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 ); + + END_TEST; +} + +// Positive test for Max Characters reached signal. +int utcDaliTextFieldMaxCharactersReachedP(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldMaxCharactersReachedP"); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + + application.GetScene().Add( field ); + + const int maxNumberOfCharacters = 1; + field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters ); + + field.SetKeyInputFocus(); + + // connect to the text changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback); + bool maxLengthReachedSignal = false; + field.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; +} + +// Negative test for Max Characters reached signal. +int utcDaliTextFieldMaxCharactersReachedN(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldMaxCharactersReachedN"); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + + application.GetScene().Add( field ); + + const int maxNumberOfCharacters = 3; + field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters ); + + field.SetKeyInputFocus(); + + // connect to the text changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback); + bool maxLengthReachedSignal = false; + field.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 ); + + application.ProcessEvent( GenerateKey( "Return", "", "\r", KEY_RETURN_CODE, 0, 0, Integration::KeyEvent::DOWN, "\r", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + DALI_TEST_CHECK( !gMaxCharactersCallBackCalled ); + DALI_TEST_CHECK( !maxLengthReachedSignal ); + + END_TEST; +} + +int utcDaliTextFieldInputStyleChanged01(void) +{ + // The text-field emits signals when the input style changes. These changes of style are + // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals + // can't be emitted during the size negotiation as the callbacks may update the UI. + // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation. + // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks. + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldInputStyleChanged01"); + + // Load some fonts. + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName( pathNamePtr ); + free( pathNamePtr ); + + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.SetDpi( 93u, 93u ); + + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE ); + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + + + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + field.SetProperty( TextField::Property::ENABLE_MARKUP, true ); + field.SetProperty( TextField::Property::TEXT, "Hello world demo" ); + + // connect to the text changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback ); + bool inputStyleChangedSignal = false; + field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) ); + + application.GetScene().Add( field ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Executes the idle callbacks added by the text control on the change of input style. + application.RunIdles(); + + gInputStyleChangedCallbackCalled = false; + gInputStyleMask = TextField::InputStyle::NONE; + inputStyleChangedSignal = false; + + // Create a tap event to touch the text field. + TestGenerateTap( application, 18.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Executes the idle callbacks added by the text control on the change of input style. + application.RunIdles(); DALI_TEST_CHECK( gInputStyleChangedCallbackCalled ); if( gInputStyleChangedCallbackCalled ) @@ -1182,8 +1624,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) ); + TestGenerateTap( application, 30.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1200,8 +1641,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) ); + TestGenerateTap( application, 43.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1225,8 +1665,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) ); + TestGenerateTap( application, 88.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1258,8 +1697,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) ); + TestGenerateTap( application, 115.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1276,8 +1714,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) ); + TestGenerateTap( application, 164.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1301,8 +1738,7 @@ int utcDaliTextFieldInputStyleChanged01(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) ); + TestGenerateTap( application, 191.0f, 25.0f ); // Render and notify application.SendNotification(); @@ -1319,15 +1755,13 @@ int utcDaliTextFieldInputStyleChanged01(void) int utcDaliTextFieldInputStyleChanged02(void) { - ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldInputStyleChanged02"); - // The text-field emits signals when the input style changes. These changes of style are // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals // can't be emitted during the size negotiation as the callbacks may update the UI. // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation. - // This creates an implementation of the adaptor stub and a queue of idle callbacks. - application.CreateAdaptor(); + // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks. + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldInputStyleChanged02"); // Load some fonts. @@ -1344,10 +1778,9 @@ int utcDaliTextFieldInputStyleChanged02(void) TextField field = TextField::New(); DALI_TEST_CHECK( field ); - - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); field.SetProperty( TextField::Property::ENABLE_MARKUP, true ); field.SetProperty( TextField::Property::TEXT, "He llo world demo" ); @@ -1358,7 +1791,7 @@ int utcDaliTextFieldInputStyleChanged02(void) bool inputStyleChangedSignal = false; field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); // Render and notify application.SendNotification(); @@ -1372,10 +1805,8 @@ int utcDaliTextFieldInputStyleChanged02(void) inputStyleChangedSignal = false; // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) ); + TestGenerateTap( application, 53.0f, 25.0f, 100 ); + TestGenerateTap( application, 53.0f, 25.0f, 200 ); // Render and notify application.SendNotification(); @@ -1408,7 +1839,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + 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(); @@ -1433,7 +1864,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + 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(); @@ -1449,7 +1880,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + 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(); @@ -1500,8 +1931,7 @@ int utcDaliTextFieldInputStyleChanged02(void) DALI_TEST_CHECK( !inputStyleChangedSignal ); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) ); + TestGenerateTap( application, 63.0f, 25.0f, 300 ); // Render and notify application.SendNotification(); @@ -1542,11 +1972,15 @@ int utcDaliTextFieldEvent01(void) TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Render and notify + application.SendNotification(); + application.Render(); // Avoid a crash when core load gl resources. application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); @@ -1556,7 +1990,7 @@ int utcDaliTextFieldEvent01(void) application.Render(); // Add a key event but as the text field has not the focus it should do nothing. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, 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 ) ); // Render and notify application.SendNotification(); @@ -1565,16 +1999,21 @@ int utcDaliTextFieldEvent01(void) DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string(""), TEST_LOCATION ); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + // Pressing delete key should be fine even if there is no text in TextField. + application.ProcessEvent( GenerateKey( "Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); application.Render(); // Now the text field has the focus, so it can handle the key events. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, 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 ) ); + application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); @@ -1585,28 +2024,27 @@ int utcDaliTextFieldEvent01(void) // Create a second text field and send key events to it. TextField field2 = TextField::New(); - field2.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field2.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - field2.SetSize( 100.f, 100.f ); - field2.SetPosition( 100.f, 100.f ); + field2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + field2.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) ); + field2.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f )); - Stage::GetCurrent().Add( field2 ); + application.GetScene().Add( field2 ); // Render and notify application.SendNotification(); application.Render(); // Create a tap event on the second text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) ); + TestGenerateTap( application, 150.0f, 125.0f ); // Render and notify application.SendNotification(); application.Render(); // The second text field has the focus. It should handle the key events. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, 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 ) ); + application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); @@ -1630,11 +2068,11 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_CHECK( field ); LoadMarkerImages(application, field); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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 ); @@ -1650,22 +2088,19 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f, 300 ); // Render and notify application.SendNotification(); application.Render(); Actor layer = field.GetChildAt( 1u ); - DALI_TEST_CHECK( layer.IsLayer() ); - DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor. DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); // Now the text field has the focus, so it can handle the key events. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, 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 ) ); + application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); @@ -1686,158 +2121,513 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_CHECK( renderer ); } - // Move the cursor and check the position changes. - Vector3 position1 = cursor.GetCurrentPosition(); + // Move the cursor and check the position changes. + Vector3 position1 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + 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(); + + Vector3 position2 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + DALI_TEST_CHECK( position2.x < position1.x ); + + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector3 position3 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1. + + + // Move the cursor to the first position. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + 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(); + + Vector3 position4 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + + // Send some taps and check the cursor positions. + + // Try to tap at the beginning. + TestGenerateTap( application, 1.0f, 25.0f, 900 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Cursor position should be the same than position1. + Vector3 position5 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + + DALI_TEST_EQUALS( position4, position5, TEST_LOCATION ); // Should be in the same position2. + + // Tap away from the start position. + TestGenerateTap( application, 16.0f, 25.0f, 1500 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Vector3 position6 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + + DALI_TEST_CHECK( position6.x > position5.x ); + + // Remove all the text. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + field.SetProperty( TextField::Property::TEXT, "" ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Cursor position should be the same than position2. + Vector3 position7 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + + DALI_TEST_EQUALS( position4, position7, TEST_LOCATION );// Should be in the same position2. + + // Should not be a renderer. + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); + + // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil ) + field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); + field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ); + + application.SendNotification(); + application.Render(); + + // There are renderer and decorator layer + DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION ); + + END_TEST; +} + +int utcDaliTextFieldEvent03(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent03"); + + // Checks if the highlight actor is created. + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + + application.GetScene().Add( field ); + + field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 30.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 ); + LoadMarkerImages(application, field); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap first to get the focus. + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Double tap to select a word. + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // The offscreen root actor should have two actors: the renderer and the highlight actor. + Actor stencil = field.GetChildAt( 0u ); + + // The highlight actor is drawn first, so is the first actor in the list + Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u ); + DALI_TEST_CHECK( highlight ); + + // The offscreen root actor has a container with all the actors which contain the text renderers. + Actor container = stencil.GetChildAt( 1u ); + for( unsigned int index = 0; index < container.GetChildCount(); ++index ) + { + Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); + DALI_TEST_CHECK( renderer ); + } + + END_TEST; +} + +int utcDaliTextFieldEvent04(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent04"); + + // Checks if the highlight actor is created. + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); + // Render and notify + application.SendNotification(); + application.Render(); + + field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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(); + + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); + // Render and notify + application.SendNotification(); + application.Render(); + + + // Tap first to get the focus. + TestGenerateTap( application, 1.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Double tap to select a word. + TestGenerateTap( application, 1.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap grab handle + TestGenerateTap( application, 0.0f, 40.0f ); + END_TEST; +} + +int utcDaliTextFieldEvent05(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent05"); + + // Checks dragging of cursor/grab handle + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); + // Render and notify + application.SendNotification(); + application.Render(); + + field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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(); + + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap first to get the focus. + TestGenerateTap( application, 1.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Double tap to select a word. + TestGenerateTap( application, 1.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Actor stencil = field.GetChildAt( 1u ); + END_TEST; +} + +int utcDaliTextFieldEvent06(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent06"); + + // Checks Longpress when in edit mode + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); + // Render and notify + application.SendNotification(); + application.Render(); + + field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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(); + + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); + // Render and notify + application.SendNotification(); + application.Render(); + + + // Tap first to get the focus. + TestGenerateTap( application, 1.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Long Press + TestGenerateLongPress(application, 1.0f, 25.0f); // Render and notify application.SendNotification(); application.Render(); - Vector3 position2 = cursor.GetCurrentPosition(); + END_TEST; +} - DALI_TEST_CHECK( position2.x < position1.x ); +int utcDaliTextFieldEvent07(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent07"); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Checks Longpress to start edit mode + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); // Render and notify application.SendNotification(); application.Render(); - Vector3 position3 = cursor.GetCurrentPosition(); - - DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1. + field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + Property::Map propertyMap; + propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD; + field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap ); - // Send some taps and check the cursor positions. + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + // Render and notify + application.SendNotification(); + application.Render(); - // Try to tap at the beginning. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + // Long Press + TestGenerateLongPress(application, 1.0f, 25.0f); // Render and notify application.SendNotification(); application.Render(); - // Cursor position should be the same than position1. - Vector3 position4 = cursor.GetCurrentPosition(); + END_TEST; +} - DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2. +int utcDaliTextFieldEvent08(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent08"); - // Tap away from the start position. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) ); + Dali::Clipboard clipboard = Clipboard::Get(); + clipboard.SetItem("testTextFieldEvent"); + + // Checks Longpress when only place holder text + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); // Render and notify application.SendNotification(); application.Render(); - Vector3 position5 = cursor.GetCurrentPosition(); + field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" ); + field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - DALI_TEST_CHECK( position5.x > position4.x ); + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + // Render and notify + application.SendNotification(); + application.Render(); - // Remove all the text. - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - field.SetProperty( TextField::Property::TEXT, "" ); + // Long Press + TestGenerateLongPress( application, 1.0f, 25.0f, 20 ); // Render and notify application.SendNotification(); application.Render(); - // Cursor position should be the same than position2. - Vector3 position6 = cursor.GetCurrentPosition(); - - DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2. + Wait(application, 500); - // Should not be a renderer. - DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); + TestEndLongPress( application, 1.0f, 25.0f, 520 ); - // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil ) - field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); - field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ); + // Long Press + TestGenerateLongPress( application, 1.0f, 25.0f, 600 ); - application.SendNotification(); + // Render and notify application.Render(); - // There are renderer and decorator layer - DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION ); + Wait(application, 500); + + Integration::Scene stage = application.GetScene(); + Layer layer = stage.GetRootLayer(); + Actor actor = layer.FindChildByName("optionPaste"); + + if (actor) + { + Vector3 worldPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_POSITION ); + Vector2 halfStageSize = stage.GetSize() / 2.0f; + Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height); + + Dali::Integration::TouchEvent event; + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointDownInside( position ) ); + application.ProcessEvent( event ); + + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointUpInside( position ) ); + application.ProcessEvent( event ); + } + DALI_TEST_EQUALS( field.GetProperty( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION ); END_TEST; } -int utcDaliTextFieldEvent03(void) +int utcDaliTextFieldEvent09(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent03"); - - // Checks if the highlight actor is created. + tet_infoline(" utcDaliTextFieldEvent09"); TextField field = TextField::New(); DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + LoadMarkerImages(application, field); + // Render and notify + application.SendNotification(); + application.Render(); - Stage::GetCurrent().Add( field ); - - field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); + field.SetProperty( TextField::Property::TEXT, "Hello" ); field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 30.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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 ); - LoadMarkerImages(application, field); - // Render and notify + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); application.SendNotification(); application.Render(); - // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) ); - - // Render and notify + Property::Map map; + map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); application.SendNotification(); application.Render(); - // Double tap to select a word. - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) ); - - // Render and notify + map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL; + map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); application.SendNotification(); application.Render(); - // The offscreen root actor should have two actors: the renderer and the highlight actor. - Actor stencil = field.GetChildAt( 0u ); - - // The highlight actor is drawn first, so is the first actor in the list - Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u ); - DALI_TEST_CHECK( highlight ); + map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT; + map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + for( unsigned int index = 0u; index < 5u; ++index ) + { + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + } - // The offscreen root actor has a container with all the actors which contain the text renderers. - Actor container = stencil.GetChildAt( 1u ); - for( unsigned int index = 0; index < container.GetChildCount(); ++index ) + map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT; + map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + for( unsigned int index = 0u; index < 5u; ++index ) { - Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); - DALI_TEST_CHECK( renderer ); + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); } + map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER; + map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + + map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); + application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + + Property::Map mapGet; + mapGet = field.GetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS ); + DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION ); END_TEST; } -int utcDaliTextFieldEvent04(void) + +int utcDaliTextFieldStyleWhilstSelected(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent04"); + tet_infoline(" utcDaliTextFieldStyleWhilstSelected"); - // Checks if the highlight actor is created. + // Change font and styles whilst text is selected whilst word selected TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); LoadMarkerImages(application, field); // Render and notify application.SendNotification(); @@ -1845,9 +2635,9 @@ int utcDaliTextFieldEvent04(void) field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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 ); @@ -1856,127 +2646,182 @@ int utcDaliTextFieldEvent04(void) application.Render(); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + TestGenerateTap( application, 1.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); // Double tap to select a word. - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); + TestGenerateTap( application, 1.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - // Tap grab handle - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) ); + field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION ); + + Property::Map fontStyleMapSet; + Property::Map fontStyleMapGet; + + fontStyleMapSet.Insert( "weight", "bold" ); + fontStyleMapSet.Insert( "slant", "italic" ); + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet ); + + fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ); + DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + + fontStyleMapSet.Clear(); + fontStyleMapSet.Insert( "width", "expanded" ); + fontStyleMapSet.Insert( "slant", "italic" ); + field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet ); + + fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ); + DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + + field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION ); + + fontStyleMapSet.Clear(); + fontStyleMapSet.Insert( "weight", "bold" ); + fontStyleMapSet.Insert( "slant", "italic" ); + + field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet ); + + fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); + DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + + fontStyleMapSet.Clear(); + fontStyleMapSet.Insert( "width", "expanded" ); + + field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet ); + + fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); + DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + + // Press Escape to increase coverage + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( !field.HasKeyInputFocus() ); + END_TEST; } -int utcDaliTextFieldEvent05(void) +int utcDaliTextFieldEscKeyLoseFocus(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent05"); + tet_infoline(" utcDaliTextFieldEscKeyLoseFocus"); - // Checks dragging of cursor/grab handle + // Creates a tap event. After creating a tap event the text field should + // have the focus and add text with key events should be possible. TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); + + application.GetScene().Add( field ); + + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + // Add a key event but as the text field has not the focus it should do nothing. + 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::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - // Avoid a crash when core load gl resources. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Render and notify application.SendNotification(); application.Render(); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string(""), TEST_LOCATION ); + // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f ); + // Render and notify application.SendNotification(); application.Render(); - - // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + // Now the text field has the focus, so it can handle the key events. + 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::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); application.Render(); - // Double tap to select a word. - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION ); + + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); application.Render(); - // drag grab handle right - Vector2 pos(0.0f, 40.0f); - SendPan(application, Gesture::Possible, pos); - SendPan(application, Gesture::Started, pos); - pos.x += 5.0f; - Wait(application, 100); + DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION ); - for(int i = 0;i<20;i++) - { - SendPan(application, Gesture::Continuing, pos); - pos.x += 5.0f; - Wait(application); - } + // No more text should be introduced + 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::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); - SendPan(application, Gesture::Finished, pos); - Wait(application, RENDER_FRAME_INTERVAL); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION ); - Actor stencil = field.GetChildAt( 1u ); END_TEST; } -int utcDaliTextFieldEvent06(void) +int utcDaliTextFieldSomeSpecialKeys(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent06"); + tet_infoline(" utcDaliTextFieldSomeSpecialKeys"); - // Checks Longpress when in edit mode + // Checks some special keys when the text is selected. TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); LoadMarkerImages(application, field); // Render and notify application.SendNotification(); application.Render(); - field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." ); + const std::string longText( "This is a long text for the size of the text-field." ); + + field.SetProperty( TextField::Property::TEXT, longText ); field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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 ); @@ -1985,358 +2830,366 @@ int utcDaliTextFieldEvent06(void) application.Render(); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f ); + // Render and notify application.SendNotification(); application.Render(); - // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + TestGenerateTap( application, 1.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - // Long Press - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) ); + // Double tap to select a word. + TestGenerateTap( application, 1.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - END_TEST; -} - -int utcDaliTextFieldEvent07(void) -{ - ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent07"); - - // Checks Longpress to start edit mode + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::DOWN, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::UP, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); // Render and notify application.SendNotification(); application.Render(); - field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - Property::Map propertyMap; - propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD; - field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap ); + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::DOWN, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::UP, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - // Avoid a crash when core load gl resources. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Render and notify application.SendNotification(); application.Render(); - // Long Press - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) ); + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::DOWN, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::UP, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); application.Render(); + // The text shouldn't be deleted. + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), longText, TEST_LOCATION ); + END_TEST; } -int utcDaliTextFieldEvent08(void) +int utcDaliTextFieldSizeUpdate(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent08"); - - Dali::Clipboard clipboard = Clipboard::Get(); - clipboard.SetItem("testTextFieldEvent"); - - // Checks Longpress when only place holder text + tet_infoline("utcDaliTextFieldSizeUpdate"); + // Checks some special keys when the text is selected. TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); - // Render and notify - application.SendNotification(); - application.Render(); + application.GetScene().Add( field ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + float previousHeight = 0.0f; + float currentHeight = 0.0f; + const float fieldWidth = 1920.0f; - // Avoid a crash when core load gl resources. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - // Render and notify - application.SendNotification(); - application.Render(); - // Long Press - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) ); + // "ㅁ" is bigger then "ኢ" + field.SetProperty( Actor::Property::SIZE, Vector2( fieldWidth ,10.0f ) ); + field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH ); + field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT ); + + field.SetProperty( TextField::Property::TEXT, "ኢ"); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + field.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true); + KeyboardFocusManager::Get().SetCurrentFocusActor( field ); - // Render and notify application.SendNotification(); application.Render(); - Wait(application, 500); + previousHeight = field.GetHeightForWidth( fieldWidth ); + DALI_TEST_EQUALS( previousHeight, field.GetProperty( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION ); - // Long Press - application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) ); + // Add another script characters ( glyph height is defferent ) + application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - // Render and notify application.SendNotification(); application.Render(); - Wait(application, 500); + currentHeight = field.GetHeightForWidth( fieldWidth ); + DALI_TEST_EQUALS( currentHeight, field.GetProperty( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION ); + DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION ); - Stage stage = Stage::GetCurrent(); - Layer layer = stage.GetRootLayer(); - Actor actor = layer.FindChildByName("optionPaste"); + END_TEST; +} - if (actor) - { - Vector3 worldPosition = actor.GetCurrentWorldPosition(); - Vector2 halfStageSize = stage.GetSize() / 2.0f; - Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height); +int utcDaliTextFieldExtremlyLargePointSize(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldExtremlyLargePointSize"); - Dali::Integration::TouchEvent event; - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside( position ) ); - application.ProcessEvent( event ); + TextField field = TextField::New(); - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointUpInside( position ) ); - application.ProcessEvent( event ); + field.SetProperty( TextField::Property::TEXT, "Text" ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( field ); + + try + { + field.SetProperty( TextField::Property::POINT_SIZE, 160.0f ); + application.SendNotification(); + DALI_TEST_CHECK( field ); } - DALI_TEST_EQUALS( field.GetProperty( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION ); + catch (...) + { + tet_result(TET_FAIL); + } + END_TEST; +} + +int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage"); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + application.GetScene().Add( field ); + + Property::Map fontStyleMapGet; + + fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); + + Property::Value* weightValue = NULL; + Property::Value* widthValue = NULL; + Property::Value* slantValue = NULL; + weightValue = fontStyleMapGet.Find( "weight" ); + widthValue = fontStyleMapGet.Find( "width" ); + slantValue = fontStyleMapGet.Find( "slant" ); + DALI_TEST_CHECK( !weightValue ); + DALI_TEST_CHECK( !widthValue ); + DALI_TEST_CHECK( !slantValue ); END_TEST; } -int utcDaliTextFieldEvent09(void) +int UtcDaliTextFieldSettingPlaceholder(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEvent09"); + tet_infoline("UtcDaliTextFieldSettingPlaceholder"); TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); - // Render and notify - application.SendNotification(); - application.Render(); + application.GetScene().Add( field ); - field.SetProperty( TextField::Property::TEXT, "Hello" ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + // Check the placeholder property with pixel size + Property::Map placeholderPixelSizeMapSet; + Property::Map placeholderPixelSizeMapGet; + Property::Map placeholderFontstyleMap; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text"; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused"; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial"; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f; + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true; - // Avoid a crash when core load gl resources. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet ); - // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.SendNotification(); - application.Render(); + placeholderPixelSizeMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION ); - Property::Map map; - map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); + // Check the placeholder property with point size + Property::Map placeholderMapSet; + Property::Map placeholderMapGet; + placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text"; + placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused"; + placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED; + placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial"; + placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f; + placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false; - map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL; - map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); + // Check the placeholder font style property + placeholderFontstyleMap.Clear(); - map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT; - map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - for( unsigned int index = 0u; index < 5u; ++index ) - { - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); - } + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderFontstyleMap.Insert( "width", "condensed" ); + placeholderFontstyleMap.Insert( "slant", "italic" ); + placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); - map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT; - map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - for( unsigned int index = 0u; index < 5u; ++index ) - { - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); - } + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); - map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER; - map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); + // Reset font style. + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "weight", "normal" ); + placeholderFontstyleMap.Insert( "slant", "oblique" ); + placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); - map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100; - field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map ); - application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "slant", "roman" ); + placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + + placeholderFontstyleMap.Clear(); + placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); - Property::Map mapGet; - mapGet = field.GetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS ); - DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION ); END_TEST; } - -int utcDaliTextFieldStyleWhilstSelected(void) +int UtcDaliTextFieldSetPaddingProperty(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldStyleWhilstSelected"); - - // Change font and styles whilst text is selected whilst word selected + tet_infoline("UtcDaliTextFieldSetPaddingProperty\n"); TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); - // Render and notify + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( field ); + application.SendNotification(); application.Render(); - field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Vector3 originalSize = field.GetNaturalSize(); + + field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) ); - // Avoid a crash when core load gl resources. - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - // Render and notify application.SendNotification(); application.Render(); - // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - // Render and notify - application.SendNotification(); - application.Render(); + DALI_TEST_EQUALS( field.GetProperty( Toolkit::Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION ); + + Vector3 paddingAddedSize = field.GetNaturalSize(); + + DALI_TEST_EQUALS( originalSize.width + 10 + 10 , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + DALI_TEST_EQUALS( originalSize.height + 10 + 10 , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + END_TEST; +} +int UtcDaliTextFieldEnableShiftSelectionProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldEnableShiftSelectionProperty"); - // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( field ); - // Render and notify application.SendNotification(); application.Render(); - // Double tap to select a word. - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); + // The default value of ENABLE_SHIFT_SELECTION is 'true'. + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), true, TEST_LOCATION ); + + // Check the enable shift selection property + field.SetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION, false ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), false, TEST_LOCATION ); - // Render and notify application.SendNotification(); application.Render(); - field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION ); - - Property::Map fontStyleMapSet; - Property::Map fontStyleMapGet; + END_TEST; +} - fontStyleMapSet.Insert( "weight", "bold" ); - fontStyleMapSet.Insert( "slant", "italic" ); - field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet ); +int UtcDaliTextFieldEnableGrabHandleProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldEnableGrabHandleProperty"); - fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ); - DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( field ); - fontStyleMapSet.Clear(); - fontStyleMapSet.Insert( "width", "expanded" ); - fontStyleMapSet.Insert( "slant", "italic" ); - field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet ); + application.SendNotification(); + application.Render(); - fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ); - DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + // The default value of ENABLE_GRAB_HANDLE is 'true'. + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION ); - field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Check the enable grab handle property + field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE, false ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION ); - field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED ); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION ); + application.SendNotification(); + application.Render(); - fontStyleMapSet.Clear(); - fontStyleMapSet.Insert( "weight", "bold" ); - fontStyleMapSet.Insert( "slant", "italic" ); + END_TEST; +} - field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet ); +int UtcDaliTextFieldMatchSystemLanguageDirectionProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldMatchSystemLanguageDirectionProperty"); - fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); - DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + application.GetScene().Add( field ); - fontStyleMapSet.Clear(); - fontStyleMapSet.Insert( "width", "expanded" ); + application.SendNotification(); + application.Render(); - field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet ); + // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'. + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION ); - fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); - DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION ); + // Check the match system language direction property + field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION ); - // Press Escape to increase coverage - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); application.SendNotification(); application.Render(); - DALI_TEST_CHECK( !field.HasKeyInputFocus() ); - END_TEST; } -int utcDaliTextFieldEscKeyLoseFocus(void) +int utcDaliTextFieldLayoutDirectionCoverage(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldEscKeyLoseFocus"); + tet_infoline(" utcDaliTextFieldLayoutDirectionCoverage"); // Creates a tap event. After creating a tap event the text field should // have the focus and add text with key events should be possible. - TextField field = TextField::New(); DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + application.GetScene().Add( field ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + field.SetProperty( Actor::Property::SIZE, Vector2( 300.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 ); @@ -2345,236 +3198,329 @@ int utcDaliTextFieldEscKeyLoseFocus(void) application.SendNotification(); application.Render(); - // Add a key event but as the text field has not the focus it should do nothing. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // init direction for coverage + // Set horizontal alignment END + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END"); + + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string(""), TEST_LOCATION ); + // Set MATCH_SYSTEM_LANGUAGE_DIRECTION to true to use the layout direction. + field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); + + // Set horizontal alignment BEGIN + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN"); // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + TestGenerateTap( application, 150.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - // Now the text field has the focus, so it can handle the key events. - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Set horizontal alignment CENTER + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION ); + // Set horizontal alignment END + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END"); - // Generate a Esc key event. The text field should lose the focus. - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Create a tap event to touch the text field. + TestGenerateTap( application, 150.0f, 25.0f ); // Render and notify application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION ); - - // No more text should be introduced - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION ); + DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION ); END_TEST; } -int utcDaliTextFieldSomeSpecialKeys(void) +int UtcDaliTextFieldGetInputMethodContext(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldSomeSpecialKeys"); - - // Checks some special keys when the text is selected. + tet_infoline("UtcDaliTextFieldGetInputMethodContext"); TextField field = TextField::New(); - DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); - LoadMarkerImages(application, field); - // Render and notify - application.SendNotification(); - application.Render(); + DALI_TEST_CHECK( DevelTextField::GetInputMethodContext( field ) ); - const std::string longText( "This is a long text for the size of the text-field." ); + END_TEST; +} - field.SetProperty( TextField::Property::TEXT, longText ); - field.SetProperty( TextField::Property::POINT_SIZE, 10.f ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); +int UtcDaliTextFieldSelectWholeText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldSelectWholeText "); + + 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 ); - // Render and notify + application.SendNotification(); application.Render(); - // Create a tap event to touch the text field. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION ); + + DevelTextField::SelectWholeText( textField ); - // Render and notify application.SendNotification(); application.Render(); - // Tap first to get the focus. - application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); + // Nothing should have been selected. The number of children is still 1 + DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION ); + + textField.SetProperty( TextField::Property::TEXT, "Hello world" ); - // Render and notify application.SendNotification(); application.Render(); - // Double tap to select a word. - application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); - application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) ); + DevelTextField::SelectWholeText( textField ); - // Render and notify application.SendNotification(); application.Render(); - // Generate a Esc key event. The text field should lose the focus. - application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Should be 2 children, the stencil and the layer + DALI_TEST_EQUALS( 2u, textField.GetChildCount(), TEST_LOCATION ); + + // The offscreen root actor should have two actors: the renderer and the highlight actor. + Actor stencil = textField.GetChildAt( 0u ); + + // The highlight actor is drawn first, so is the first actor in the list + Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u ); + DALI_TEST_CHECK( highlight ); + + END_TEST; +} + +int UtcDaliTextFieldSelectNone(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldSelectWholeText "); + + 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 ); - // Render and notify application.SendNotification(); application.Render(); - // Generate a Esc key event. The text field should lose the focus. - application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + textField.SetProperty( TextField::Property::TEXT, "Hello world" ); - // Render and notify application.SendNotification(); application.Render(); - // Generate a Esc key event. The text field should lose the focus. - application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Nothing is selected + std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + DevelTextField::SelectWholeText( textField ); - // Render and notify application.SendNotification(); application.Render(); - // The text shouldn't be deleted. - DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), longText, TEST_LOCATION ); + // whole text is selected + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION ); + + DevelTextField::SelectNone( textField ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); END_TEST; } -int utcDaliTextFieldSizeUpdate(void) +int UtcDaliTextFieldSelectRange(void) { ToolkitTestApplication application; - tet_infoline("utcDaliTextFieldSizeUpdate"); + tet_infoline(" UtcDaliTextFieldSelectRange "); - // Checks some special keys when the text is selected. - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + TextField textField = TextField::New(); - float previousHeight = 0.0f; - float currentHeight = 0.0f; - const float fieldWidth = 1920.0f; + 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 ); - // "ㅁ" is bigger then "ኢ" - field.SetSize( Vector2( fieldWidth ,10.0f ) ); - field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH ); - field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT ); + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - field.SetProperty( TextField::Property::TEXT, "ኢ"); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + application.SendNotification(); + application.Render(); - field.SetKeyboardFocusable(true); - KeyboardFocusManager::Get().SetCurrentFocusActor( field ); + textField.SetProperty( TextField::Property::TEXT, "Hello world" ); application.SendNotification(); application.Render(); - previousHeight = field.GetHeightForWidth( fieldWidth ); - DALI_TEST_EQUALS( previousHeight, field.GetProperty( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION ); + textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_START , 0); + textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_END , 5); - // Add another script characters ( glyph height is defferent ) - application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Hello is selected + std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 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(); + DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 6, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 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(); - currentHeight = field.GetHeightForWidth( fieldWidth ); - DALI_TEST_EQUALS( currentHeight, field.GetProperty( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION ); - DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION ); + 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(), "", TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get(), 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(), "D", TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get(), true, TEST_LOCATION ); END_TEST; } -int utcDaliTextFieldExtremlyLargePointSize(void) +int UtcDaliToolkitTextFieldFontSizeScale(void) { ToolkitTestApplication application; - tet_infoline(" utcDaliTextFieldExtremlyLargePointSize"); + tet_infoline(" UtcDaliToolkitTextFieldFontSizeScale"); - TextField field = TextField::New(); + TextField textField = TextField::New(); + textField.SetProperty( TextField::Property::POINT_SIZE, 30.f ); + textField.SetProperty( TextField::Property::TEXT, "Test" ); + Vector3 nonScaledSize = textField.GetNaturalSize(); - field.SetProperty( TextField::Property::TEXT, "Text" ); - field.SetSize( 300.f, 50.f ); - field.SetParentOrigin( ParentOrigin::TOP_LEFT ); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - Stage::GetCurrent().Add( field ); + TextField textFieldScaled = TextField::New(); + textFieldScaled.SetProperty( TextField::Property::POINT_SIZE, 15.f ); + textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f ); + textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" ); + Vector3 scaledSize = textFieldScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + textField.SetProperty( TextField::Property::PIXEL_SIZE, 30.f ); + textField.SetProperty( TextField::Property::TEXT, "Test" ); + nonScaledSize = textField.GetNaturalSize(); + + textFieldScaled.SetProperty( TextField::Property::PIXEL_SIZE, 15.f ); + textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f ); + textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" ); + scaledSize = textFieldScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); - try - { - field.SetProperty( TextField::Property::POINT_SIZE, 160.0f ); - application.SendNotification(); - DALI_TEST_CHECK( field ); - } - catch (...) - { - tet_result(TET_FAIL); - } END_TEST; } -int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void) +int UtcDaliTextFieldPrimaryCursorPosition(void) { ToolkitTestApplication application; - tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage"); - TextField field = TextField::New(); - DALI_TEST_CHECK( field ); - Stage::GetCurrent().Add( field ); + tet_infoline(" UtcDaliTextFieldPrimaryCursorPosition "); - Property::Map fontStyleMapGet; + TextField textField = TextField::New(); - fontStyleMapGet = field.GetProperty( TextField::Property::FONT_STYLE ); + application.GetScene().Add( textField ); - Property::Value* weightValue = NULL; - Property::Value* widthValue = NULL; - Property::Value* slantValue = NULL; - weightValue = fontStyleMapGet.Find( "weight" ); - widthValue = fontStyleMapGet.Find( "width" ); - slantValue = fontStyleMapGet.Find( "slant" ); - DALI_TEST_CHECK( !weightValue ); - DALI_TEST_CHECK( !widthValue ); - DALI_TEST_CHECK( !slantValue ); + textField.SetProperty( TextField::Property::TEXT, "ABCEF"); + 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 ); + + textField.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3); + application.SendNotification(); + application.Render(); + + 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(), "ABCDEF", TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION ).Get(), 4, TEST_LOCATION ); END_TEST; }