X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-TextField.cpp;h=3e369f6bdc846e8af3a786cedf2203c1947986e7;hp=ced942110395fb8d830beea154ff848956214e28;hb=81d8e007ed1aed6e36e4cf44e456d91cf8024004;hpb=88b69217fe05ad98aab6d9d41e030d934093f82c diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index ced9421..3e369f6 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) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include "toolkit-clipboard.h" using namespace Dali; @@ -94,6 +96,13 @@ const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmb const char* const PROPERTY_NAME_OUTLINE = "outline"; const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline"; +const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS = "hiddenInputSettings"; +const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; +const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; +const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; +const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis"; +const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableShiftSelection"; + const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); @@ -111,6 +120,12 @@ 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 gTextChangedCallBackCalled; static bool gMaxCharactersCallBackCalled; static bool gInputStyleChangedCallbackCalled; @@ -118,15 +133,9 @@ static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask; static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height) { - Integration::ResourceRequest* request = platform.GetRequest(); Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD ); Integration::ResourcePointer resource(bitmap); bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height); - - if(request) - { - platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } } static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField) @@ -300,14 +309,20 @@ Integration::KeyEvent GenerateKey( const std::string& keyName, int keyCode, int keyModifier, unsigned long timeStamp, - const Integration::KeyEvent::State& keyState ) + const Integration::KeyEvent::State& keyState, + 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, keyString, keyCode, keyModifier, timeStamp, - keyState ); + keyState, + deviceName, + deviceClass, + deviceSubclass ); } bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet ) @@ -318,18 +333,64 @@ bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Ma { const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index ); - Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey ); + 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 ) { - if( valueGet.second.Get() != valueSet->Get() ) + if( valueSet->GetType() == Dali::Property::STRING && ( valueGet.second.Get() != valueSet->Get() ) ) + { + tet_printf( "Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); + return false; + } + else if( valueSet->GetType() == Dali::Property::BOOLEAN && ( 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::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() ) ) { - tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get().c_str(), valueSet->Get().c_str() ); + 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 { - tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); + if ( valueGet.first.type == Property::Key::INDEX ) + { + tet_printf( " The key %d doesn't exist.", valueGet.first.indexKey ); + } + else + { + tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() ); + } return false; } } @@ -477,6 +538,12 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == TextField::Property::HIDDEN_INPUT_SETTINGS ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextField::Property::PIXEL_SIZE ); + 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_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION ); END_TEST; } @@ -654,6 +721,38 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( 0, 0, 1, 1 ) ); DALI_TEST_EQUALS( field.GetProperty >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect( 0, 0, 1, 1 ), TEST_LOCATION ); + // Check the input method setting + Property::Map propertyMap; + InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER; + InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD; + InputMethod::ActionButtonTitle::Type actionButton = InputMethod::ActionButtonTitle::GO; + int inputVariation = 1; + propertyMap["PANEL_LAYOUT"] = panelLayout; + propertyMap["AUTO_CAPITALISE"] = autoCapital; + propertyMap["ACTION_BUTTON"] = actionButton; + propertyMap["VARIATION"] = inputVariation; + field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap ); + + Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS ); + Property::Map map; + DALI_TEST_CHECK( value.Get( map ) ); + + int layout = 0; + DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) ); + DALI_TEST_EQUALS( static_cast(panelLayout), layout, TEST_LOCATION ); + + int capital = 0; + DALI_TEST_CHECK( map[ "AUTO_CAPITALISE" ].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 ); + + int variation = 0; + DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) ); + DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION ); + // Check input color property. field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION ); @@ -737,8 +836,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 ); @@ -759,13 +859,154 @@ int UtcDaliTextFieldSetPropertyP(void) DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION ); // Check the outline property + + // Test string type first + // This is purely to maintain backward compatibility, but we don't support string as the outline property type. field.SetProperty( TextField::Property::OUTLINE, "Outline properties" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION ); + // Then test the property map type + Property::Map outlineMapSet; + Property::Map outlineMapGet; + + outlineMapSet["color"] = Color::RED; + outlineMapSet["width"] = 2.0f; + + field.SetProperty( TextField::Property::OUTLINE, outlineMapSet ); + + outlineMapGet = field.GetProperty( TextField::Property::OUTLINE ); + DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION ); + // Check the input outline property field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" ); DALI_TEST_EQUALS( field.GetProperty( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION ); + // Check the hidden input settings property + Property::Map hiddenMapSet; + Property::Map hiddenMapGet; + hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL; + hiddenMapSet[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 2; + hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4; + hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23; + field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet ); + + hiddenMapGet = field.GetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS ); + DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION ); + + // Check the pixel size of font + field.SetProperty( TextField::Property::PIXEL_SIZE, 20.f ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + // Check the enable selection property + field.SetProperty( TextField::Property::ENABLE_SELECTION, false ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION ); + + // Check the placeholder property with pixel size + Property::Map placeholderPixelSizeMapSet; + Property::Map placeholderPixelSizeMapGet; + Property::Map placeholderFontstyleMap; + 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; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet ); + + placeholderPixelSizeMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), 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["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(); + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderFontstyleMap.Insert( "width", "condensed" ); + placeholderFontstyleMap.Insert( "slant", "italic" ); + placeholderMapSet["fontStyle"] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), 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["fontStyle"] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), 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["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["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, 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 ); + + application.SendNotification(); + application.Render(); + END_TEST; } @@ -825,7 +1066,7 @@ int utcDaliTextFieldTextChangedP(void) field.SetKeyInputFocus(); gTextChangedCallBackCalled = false; - application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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; @@ -878,8 +1119,8 @@ int utcDaliTextFieldMaxCharactersReachedP(void) gMaxCharactersCallBackCalled = false; - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); DALI_TEST_CHECK( gMaxCharactersCallBackCalled ); DALI_TEST_CHECK( maxLengthReachedSignal ); @@ -910,8 +1151,13 @@ int utcDaliTextFieldMaxCharactersReachedN(void) gMaxCharactersCallBackCalled = false; - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); + + DALI_TEST_CHECK( !gMaxCharactersCallBackCalled ); + DALI_TEST_CHECK( !maxLengthReachedSignal ); + + application.ProcessEvent( GenerateKey( "Return", "\r", KEY_RETURN_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); DALI_TEST_CHECK( !gMaxCharactersCallBackCalled ); DALI_TEST_CHECK( !maxLengthReachedSignal ); @@ -1228,7 +1474,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) ); + 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(); @@ -1253,7 +1499,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) ); + 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(); @@ -1269,7 +1515,7 @@ int utcDaliTextFieldInputStyleChanged02(void) gInputStyleMask = TextField::InputStyle::NONE; inputStyleChangedSignal = false; - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) ); + 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(); @@ -1376,7 +1622,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", 0, 0, 0, Integration::KeyEvent::Down ) ); + application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); // Render and notify application.SendNotification(); @@ -1392,9 +1638,15 @@ int utcDaliTextFieldEvent01(void) 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, 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", 0, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); // Render and notify application.SendNotification(); @@ -1425,8 +1677,8 @@ int utcDaliTextFieldEvent01(void) application.Render(); // The second text field has the focus. It should handle the key events. - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); // Render and notify application.SendNotification(); @@ -1484,8 +1736,8 @@ int utcDaliTextFieldEvent02(void) 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", 0, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); // Render and notify application.SendNotification(); @@ -1509,8 +1761,8 @@ int utcDaliTextFieldEvent02(void) // Move the cursor and check the position changes. Vector3 position1 = cursor.GetCurrentPosition(); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) ); + 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(); @@ -1520,8 +1772,8 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_CHECK( position2.x < position1.x ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) ); + 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 ) ); // Render and notify application.SendNotification(); @@ -1559,8 +1811,8 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_CHECK( position5.x > position4.x ); // Remove all the text. - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) ); - application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) ); + 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 @@ -1575,6 +1827,16 @@ int utcDaliTextFieldEvent02(void) // 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; } @@ -1623,17 +1885,18 @@ int utcDaliTextFieldEvent03(void) // 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( 0u ); + 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 ); } - Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u ); - DALI_TEST_CHECK( highlight ); - END_TEST; } @@ -1840,6 +2103,9 @@ int utcDaliTextFieldEvent07(void) 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 ); // Avoid a crash when core load gl resources. application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); @@ -1898,6 +2164,16 @@ int utcDaliTextFieldEvent08(void) Wait(application, 500); + // Long Press + application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) ); + application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + Wait(application, 500); + Stage stage = Stage::GetCurrent(); Layer layer = stage.GetRootLayer(); Actor actor = layer.FindChildByName("optionPaste"); @@ -1918,9 +2194,96 @@ int utcDaliTextFieldEvent08(void) application.ProcessEvent( event ); } DALI_TEST_EQUALS( field.GetProperty( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION ); + + END_TEST; +} + +int utcDaliTextFieldEvent09(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEvent09"); + + 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, "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 ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // 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(); + + 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(); + + 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(); + + 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(); + } + + 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(); + } + + 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(); + + 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(); + + 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) { ToolkitTestApplication application; @@ -2020,5 +2383,411 @@ int utcDaliTextFieldStyleWhilstSelected(void) 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 utcDaliTextFieldEscKeyLoseFocus(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldEscKeyLoseFocus"); + + // 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 ); + + field.SetSize( 300.f, 50.f ); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + 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 ) ); + + // 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 ) ) ); + + // 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 ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + 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(); + + 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 ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION ); + + END_TEST; +} + +int utcDaliTextFieldSomeSpecialKeys(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldSomeSpecialKeys"); + + // 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(); + + 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 ); + + // 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(); + + // 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 ) ) ); + + // 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 ) ) ); + + // 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 ) ); + + // 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 ) ); + + // 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 ) ); + + // 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 utcDaliTextFieldSizeUpdate(void) +{ + ToolkitTestApplication application; + tet_infoline("utcDaliTextFieldSizeUpdate"); + + // Checks some special keys when the text is selected. + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + Stage::GetCurrent().Add( field ); + + float previousHeight = 0.0f; + float currentHeight = 0.0f; + const float fieldWidth = 1920.0f; + + + // "ㅁ" is bigger then "ኢ" + field.SetSize( Vector2( fieldWidth ,10.0f ) ); + field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH ); + field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT ); + + field.SetProperty( TextField::Property::TEXT, "ኢ"); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + + field.SetKeyboardFocusable(true); + KeyboardFocusManager::Get().SetCurrentFocusActor( field ); + + application.SendNotification(); + application.Render(); + + previousHeight = field.GetHeightForWidth( fieldWidth ); + DALI_TEST_EQUALS( previousHeight, field.GetProperty( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION ); + + // 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 ) ); + + 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 ); + + END_TEST; +} + +int utcDaliTextFieldExtremlyLargePointSize(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldExtremlyLargePointSize"); + + TextField field = TextField::New(); + + 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 ); + + 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) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage"); + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + Stage::GetCurrent().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 UtcDaliTextFieldSettingPlaceholder(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldSettingPlaceholder"); + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + Stage::GetCurrent().Add( field ); + + // 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; + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap; + field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet ); + + placeholderPixelSizeMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION ); + + // 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; + + // Check the placeholder font style property + placeholderFontstyleMap.Clear(); + + 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 ); + + placeholderMapGet = field.GetProperty( TextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + // 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 ); + + 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 ); + + END_TEST; +} + +int UtcDaliTextFieldSetPaddingProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldSetPaddingProperty\n"); + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetSize( 300.f, 50.f ); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage::GetCurrent().Add( field ); + + application.SendNotification(); + application.Render(); + + Vector3 originalSize = field.GetNaturalSize(); + + field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) ); + + 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"); + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetSize( 300.f, 50.f ); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage::GetCurrent().Add( field ); + + application.SendNotification(); + application.Render(); + + // 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 ); + + application.SendNotification(); + application.Render(); + END_TEST; }