Implement vertical scroll animation on text input
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextEditor.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/devel-api/adaptor-framework/clipboard.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
29
30 using namespace Dali;
31 using namespace Toolkit;
32
33 void dali_texteditor_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void dali_texteditor_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45
46 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
47 const char* const PROPERTY_NAME_TEXT                                 = "text";
48 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
49 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
50 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
51 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
52 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
53 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
54 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
55 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
56 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
57 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
58 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
59 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
60 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
61 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
62 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
68 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
69 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
70 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
71 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
72 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
73 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
74 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
75 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
76
77 const char* const PROPERTY_NAME_LINE_SPACING                         = "lineSpacing";
78 const char* const PROPERTY_NAME_INPUT_LINE_SPACING                   = "inputLineSpacing";
79 const char* const PROPERTY_NAME_UNDERLINE                            = "underline";
80 const char* const PROPERTY_NAME_INPUT_UNDERLINE                      = "inputUnderline";
81 const char* const PROPERTY_NAME_SHADOW                               = "shadow";
82 const char* const PROPERTY_NAME_INPUT_SHADOW                         = "inputShadow";
83 const char* const PROPERTY_NAME_EMBOSS                               = "emboss";
84 const char* const PROPERTY_NAME_INPUT_EMBOSS                         = "inputEmboss";
85 const char* const PROPERTY_NAME_OUTLINE                              = "outline";
86 const char* const PROPERTY_NAME_INPUT_OUTLINE                        = "inputOutline";
87
88 const char* const PROPERTY_NAME_SMOOTH_SCROLL                        = "smoothScroll";
89 const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION               = "smoothScrollDuration";
90
91 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
92
93 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
94
95 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
96 const float TO_MILLISECONDS = 1000.f;
97 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
98
99 const float SCROLL_THRESHOLD = 10.f;
100 const float SCROLL_SPEED = 300.f;
101
102 const unsigned int DEFAULT_FONT_SIZE = 1152u;
103 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
104
105 static bool gTextChangedCallBackCalled;
106 static bool gInputStyleChangedCallbackCalled;
107 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
108
109 struct CallbackFunctor
110 {
111   CallbackFunctor(bool* callbackFlag)
112   : mCallbackFlag( callbackFlag )
113   {
114   }
115
116   void operator()()
117   {
118     *mCallbackFlag = true;
119   }
120   bool* mCallbackFlag;
121 };
122
123 static void TestTextChangedCallback( TextEditor control )
124 {
125   tet_infoline(" TestTextChangedCallback");
126
127   gTextChangedCallBackCalled = true;
128 }
129
130 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
131 {
132   tet_infoline(" TestInputStyleChangedCallback");
133
134   gInputStyleChangedCallbackCalled = true;
135   gInputStyleMask = mask;
136 }
137
138 // Generate a TapGestureEvent to send to Core.
139 Integration::TapGestureEvent GenerateTap(
140     Gesture::State state,
141     unsigned int numberOfTaps,
142     unsigned int numberOfTouches,
143     Vector2 point)
144 {
145   Integration::TapGestureEvent tap( state );
146
147   tap.numberOfTaps = numberOfTaps;
148   tap.numberOfTouches = numberOfTouches;
149   tap.point = point;
150
151   return tap;
152 }
153
154 // Generate a KeyEvent to send to Core.
155 Integration::KeyEvent GenerateKey( const std::string& keyName,
156                                    const std::string& keyString,
157                                    int keyCode,
158                                    int keyModifier,
159                                    unsigned long timeStamp,
160                                    const Integration::KeyEvent::State& keyState )
161 {
162   return Integration::KeyEvent( keyName,
163                                 keyString,
164                                 keyCode,
165                                 keyModifier,
166                                 timeStamp,
167                                 keyState );
168 }
169
170 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
171 {
172   if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
173   {
174     for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
175     {
176       const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
177
178       Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
179       if( NULL != valueSet )
180       {
181         if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
182         {
183           tet_printf( "  Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
184           return false;
185         }
186       }
187       else
188       {
189         tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
190         return false;
191       }
192     }
193   }
194
195   return true;
196 }
197
198 } // namespace
199
200 int UtcDaliToolkitTextEditorConstructorP(void)
201 {
202   ToolkitTestApplication application;
203   tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
204   TextEditor textEditor;
205   DALI_TEST_CHECK( !textEditor );
206   END_TEST;
207 }
208
209 int UtcDaliToolkitTextEditorNewP(void)
210 {
211   ToolkitTestApplication application;
212   tet_infoline(" UtcDaliToolkitTextEditorNewP");
213   TextEditor textEditor = TextEditor::New();
214   DALI_TEST_CHECK( textEditor );
215   END_TEST;
216 }
217
218 int UtcDaliToolkitTextEditorDownCastP(void)
219 {
220   ToolkitTestApplication application;
221   tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
222   TextEditor textEditor1 = TextEditor::New();
223   BaseHandle object( textEditor1 );
224
225   TextEditor textEditor2 = TextEditor::DownCast( object );
226   DALI_TEST_CHECK( textEditor2 );
227
228   TextEditor textEditor3 = DownCast< TextEditor >( object );
229   DALI_TEST_CHECK( textEditor3 );
230   END_TEST;
231 }
232
233 int UtcDaliToolkitTextEditorDownCastN(void)
234 {
235   ToolkitTestApplication application;
236   tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
237   BaseHandle uninitializedObject;
238   TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
239   DALI_TEST_CHECK( !textEditor1 );
240
241   TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
242   DALI_TEST_CHECK( !textEditor2 );
243   END_TEST;
244 }
245
246 int UtcDaliToolkitTextEditorCopyConstructorP(void)
247 {
248   ToolkitTestApplication application;
249   tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
250   TextEditor textEditor = TextEditor::New();
251   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
252
253   TextEditor copy( textEditor );
254   DALI_TEST_CHECK( copy );
255   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
256   END_TEST;
257 }
258
259 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
260 {
261   ToolkitTestApplication application;
262   tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
263   TextEditor textEditor = TextEditor::New();
264   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
265
266   TextEditor copy = textEditor;
267   DALI_TEST_CHECK( copy );
268   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
269   END_TEST;
270 }
271
272 int UtcDaliTextEditorNewP(void)
273 {
274   ToolkitTestApplication application;
275   tet_infoline(" UtcDaliToolkitTextEditorNewP");
276   TextEditor textEditor = TextEditor::New();
277   DALI_TEST_CHECK( textEditor );
278   END_TEST;
279 }
280
281 // Positive test case for a method
282 int UtcDaliTextEditorGetPropertyP(void)
283 {
284   ToolkitTestApplication application;
285   tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
286   TextEditor editor = TextEditor::New();
287   DALI_TEST_CHECK( editor );
288
289   // Check Property Indices are correct
290   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
291   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
292   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
293   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
294   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
295   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
296   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
297   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
298   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
299   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
300   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
301   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
302   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
303   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
304   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
305   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
306   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
307   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
308   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
309   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
310   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
311   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
312   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
313   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
314   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
315   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
316   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
317   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
318   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
319   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
320
321   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
322   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
323   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
324   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
325   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
326   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
327   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
328   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
329   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
330   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
331   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
332   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
333
334   END_TEST;
335 }
336
337 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
338 {
339   bool result = false;
340   Property::Map imageMap;
341   imageMap[mapKey] =mapValue;
342
343   editor.SetProperty( property , imageMap );
344   Property::Value propValue = editor.GetProperty( property );
345   Property::Map* resultMap = propValue.GetMap();
346
347   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
348   {
349     result = true;
350   }
351
352   return result;
353 }
354
355 // Positive test case for a method
356 int UtcDaliTextEditorSetPropertyP(void)
357 {
358   ToolkitTestApplication application;
359   tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
360   TextEditor editor = TextEditor::New();
361   DALI_TEST_CHECK( editor );
362   Stage::GetCurrent().Add( editor );
363
364   // Note - we can't check the defaults since the stylesheets are platform-specific
365
366   // Check the render backend property.
367   editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
368   DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
369
370   // Check text property.
371   editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
372   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
373
374   // Check text's color property
375   editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
376   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
377
378   // Check font properties.
379   editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
380   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
381
382   Property::Map fontStyleMapSet;
383   Property::Map fontStyleMapGet;
384   Property::Value* slantValue = NULL;
385
386   fontStyleMapSet.Insert( "weight", "bold" );
387   fontStyleMapSet.Insert( "width", "condensed" );
388   fontStyleMapSet.Insert( "slant", "italic" );
389
390   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
391   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
392   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
393   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
394
395   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
396   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
397
398   // Reset font style.
399   fontStyleMapSet.Clear();
400   fontStyleMapSet.Insert( "weight", "normal" );
401   fontStyleMapSet.Insert( "slant", "oblique" );
402   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
403   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
404   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
405   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
406
407   fontStyleMapSet.Clear();
408   fontStyleMapSet.Insert( "slant", "roman" );
409   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
410   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
411
412   // Replace 'roman' for 'normal'.
413   slantValue = fontStyleMapGet.Find( "slant" );
414   if( NULL != slantValue )
415   {
416     if( "normal" == slantValue->Get<std::string>() )
417     {
418       fontStyleMapGet["slant"] = "roman";
419     }
420   }
421   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
422   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
423
424   fontStyleMapSet.Clear();
425
426   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
427   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
428   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
429   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
430
431   // Check that the Alignment properties can be correctly set
432   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
433   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
434
435   // Check scroll properties.
436   editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
437   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
438   editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
439   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
440
441   // Check cursor properties
442   editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
443   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
444   editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
445   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
446
447   editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
448   DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
449   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
450   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
451   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
452   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
453   editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
454   DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
455
456   // Check handle images
457   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
458   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
459   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
460   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
461   editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
462
463   // Check handle images
464   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
465   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
466   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
467   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
468   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
469   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
470
471   // Check the highlight color
472   editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
473   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
474
475   // Decoration bounding box
476   editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
477   DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
478
479   // Check the enable markup property.
480   DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
481   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
482   DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
483
484   // Check input color property.
485   editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
486   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
487
488   // Check input font properties.
489   editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
490   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
491
492   fontStyleMapSet.Clear();
493   fontStyleMapSet.Insert( "weight", "bold" );
494   fontStyleMapSet.Insert( "width", "condensed" );
495   fontStyleMapSet.Insert( "slant", "italic" );
496
497   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
498   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
499   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
500   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
501
502   editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
503   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
504
505   // Reset input font style.
506   fontStyleMapSet.Clear();
507   fontStyleMapSet.Insert( "weight", "normal" );
508   fontStyleMapSet.Insert( "slant", "oblique" );
509
510   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
511   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
512   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
513   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
514
515   fontStyleMapSet.Clear();
516   fontStyleMapSet.Insert( "slant", "roman" );
517
518   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
519   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
520
521   // Replace 'roman' for 'normal'.
522   slantValue = fontStyleMapGet.Find( "slant" );
523   if( NULL != slantValue )
524   {
525     if( "normal" == slantValue->Get<std::string>() )
526     {
527       fontStyleMapGet["slant"] = "roman";
528     }
529   }
530   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
531   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
532
533   fontStyleMapSet.Clear();
534
535   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
536   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
537   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
538   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
539
540   // Check the line spacing property
541   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
542   editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
543   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
544
545   // Check the input line spacing property
546   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
547   editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
548   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
549
550   // Check the underline property
551
552   Property::Map underlineMapSet;
553   Property::Map underlineMapGet;
554
555   underlineMapSet.Insert( "enable", "true" );
556   underlineMapSet.Insert( "color", "red" );
557   underlineMapSet.Insert( "height", "1" );
558
559   editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
560
561   underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
562   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
563   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
564
565   // Check the input underline property
566   editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
567   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
568
569   // Check the shadow property
570   Property::Map shadowMapSet;
571   Property::Map shadowMapGet;
572
573   shadowMapSet.Insert( "color", "green" );
574   shadowMapSet.Insert( "offset", "2 2" );
575
576   editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
577
578   shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
579   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
580   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
581
582   // Check the input shadow property
583   editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
584   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
585
586   // Check the emboss property
587   editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
588   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
589
590   // Check the input emboss property
591   editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
592   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
593
594   // Check the outline property
595   editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
596   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
597
598   // Check the input outline property
599   editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
600   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
601
602   // Check the smooth scroll property
603   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
604   editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
605   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
606
607   // Check the smooth scroll duration property
608   editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
609   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
610
611   END_TEST;
612 }
613
614 // Positive Atlas Text Renderer test
615 int utcDaliTextEditorAtlasRenderP(void)
616 {
617   ToolkitTestApplication application;
618   tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
619   StyleManager styleManager = StyleManager::Get();
620   styleManager.ApplyDefaultTheme();
621   TextEditor editor = TextEditor::New();
622   DALI_TEST_CHECK( editor );
623
624   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
625
626   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
627
628   Stage::GetCurrent().Add( editor );
629
630   try
631   {
632     // Render some text with the shared atlas backend
633     editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
634     application.SendNotification();
635     application.Render();
636   }
637   catch( ... )
638   {
639     tet_result(TET_FAIL);
640   }
641   END_TEST;
642 }
643
644 // Positive test for the textChanged signal.
645 int utcDaliTextEditorTextChangedP(void)
646 {
647   ToolkitTestApplication application;
648   tet_infoline(" utcDaliTextEditorTextChangedP");
649   TextEditor editor = TextEditor::New();
650   DALI_TEST_CHECK( editor );
651
652   Stage::GetCurrent().Add( editor );
653
654   // connect to the text changed signal.
655   ConnectionTracker* testTracker = new ConnectionTracker();
656   editor.TextChangedSignal().Connect( &TestTextChangedCallback );
657   bool textChangedSignal = false;
658   editor.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
659
660   gTextChangedCallBackCalled = false;
661   editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
662   DALI_TEST_CHECK( gTextChangedCallBackCalled );
663   DALI_TEST_CHECK( textChangedSignal );
664
665   application.SendNotification();
666
667   editor.SetKeyInputFocus();
668
669   gTextChangedCallBackCalled = false;
670   application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
671   DALI_TEST_CHECK( gTextChangedCallBackCalled );
672
673   END_TEST;
674 }
675
676 int utcDaliTextEditorInputStyleChanged01(void)
677 {
678   ToolkitTestApplication application;
679   tet_infoline(" utcDaliTextEditorInputStyleChanged01");
680
681   // The text-editor emits signals when the input style changes. These changes of style are
682   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
683   // can't be emitted during the size negotiation as the callbacks may update the UI.
684   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
685   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
686   application.CreateAdaptor();
687
688   // Load some fonts.
689
690   char* pathNamePtr = get_current_dir_name();
691   const std::string pathName( pathNamePtr );
692   free( pathNamePtr );
693
694   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
695   fontClient.SetDpi( 93u, 93u );
696
697   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
698   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
699
700   TextEditor editor = TextEditor::New();
701   DALI_TEST_CHECK( editor );
702
703
704   editor.SetSize( 300.f, 50.f );
705   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
706   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
707
708   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
709   editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
710
711   // connect to the text changed signal.
712   ConnectionTracker* testTracker = new ConnectionTracker();
713   editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
714   bool inputStyleChangedSignal = false;
715   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
716
717   Stage::GetCurrent().Add( editor );
718
719   // Render and notify
720   application.SendNotification();
721   application.Render();
722
723   // Executes the idle callbacks added by the text control on the change of input style.
724   application.RunIdles();
725
726   gInputStyleChangedCallbackCalled = false;
727   gInputStyleMask = TextEditor::InputStyle::NONE;
728   inputStyleChangedSignal = false;
729
730   // Create a tap event to touch the text editor.
731   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
732   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
733
734   // Render and notify
735   application.SendNotification();
736   application.Render();
737
738   // Executes the idle callbacks added by the text control on the change of input style.
739   application.RunIdles();
740
741   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
742   if( gInputStyleChangedCallbackCalled )
743   {
744     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
745
746     const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
747     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
748
749     const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
750     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
751   }
752   DALI_TEST_CHECK( inputStyleChangedSignal );
753
754   gInputStyleChangedCallbackCalled = false;
755   gInputStyleMask = TextEditor::InputStyle::NONE;
756   inputStyleChangedSignal = false;
757
758   // Create a tap event to touch the text editor.
759   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
760   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
761
762   // Render and notify
763   application.SendNotification();
764   application.Render();
765
766   // Executes the idle callbacks added by the text control on the change of input style.
767   application.RunIdles();
768
769   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
770   DALI_TEST_CHECK( !inputStyleChangedSignal );
771
772   gInputStyleChangedCallbackCalled = false;
773   gInputStyleMask = TextEditor::InputStyle::NONE;
774   inputStyleChangedSignal = false;
775
776   // Create a tap event to touch the text editor.
777   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
778   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
779
780   // Render and notify
781   application.SendNotification();
782   application.Render();
783
784   // Executes the idle callbacks added by the text control on the change of input style.
785   application.RunIdles();
786
787   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
788   if( gInputStyleChangedCallbackCalled )
789   {
790     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
791
792     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
793     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
794   }
795   DALI_TEST_CHECK( inputStyleChangedSignal );
796
797   gInputStyleChangedCallbackCalled = false;
798   gInputStyleMask = TextEditor::InputStyle::NONE;
799   inputStyleChangedSignal = false;
800
801   // Create a tap event to touch the text editor.
802   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
803   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
804
805   // Render and notify
806   application.SendNotification();
807   application.Render();
808
809   // Executes the idle callbacks added by the text control on the change of input style.
810   application.RunIdles();
811
812   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
813   if( gInputStyleChangedCallbackCalled )
814   {
815     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
816
817     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
818     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
819
820     Property::Map fontStyleMapSet;
821     Property::Map fontStyleMapGet;
822
823     fontStyleMapSet.Insert( "weight", "bold" );
824
825     fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
826     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
827     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
828   }
829   DALI_TEST_CHECK( inputStyleChangedSignal );
830
831   gInputStyleChangedCallbackCalled = false;
832   gInputStyleMask = TextEditor::InputStyle::NONE;
833   inputStyleChangedSignal = false;
834
835   // Create a tap event to touch the text editor.
836   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
837   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
838
839   // Render and notify
840   application.SendNotification();
841   application.Render();
842
843   // Executes the idle callbacks added by the text control on the change of input style.
844   application.RunIdles();
845
846   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
847   DALI_TEST_CHECK( !inputStyleChangedSignal );
848
849   gInputStyleChangedCallbackCalled = false;
850   gInputStyleMask = TextEditor::InputStyle::NONE;
851   inputStyleChangedSignal = false;
852
853   // Create a tap event to touch the text editor.
854   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
855   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
856
857   // Render and notify
858   application.SendNotification();
859   application.Render();
860
861   // Executes the idle callbacks added by the text control on the change of input style.
862   application.RunIdles();
863
864   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
865   if( gInputStyleChangedCallbackCalled )
866   {
867     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
868
869     Property::Map fontStyleMapSet;
870     Property::Map fontStyleMapGet;
871
872     fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
873     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
874     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
875   }
876   DALI_TEST_CHECK( inputStyleChangedSignal );
877
878   gInputStyleChangedCallbackCalled = false;
879   gInputStyleMask = TextEditor::InputStyle::NONE;
880   inputStyleChangedSignal = false;
881
882   // Create a tap event to touch the text editor.
883   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
884   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
885
886   // Render and notify
887   application.SendNotification();
888   application.Render();
889
890   // Executes the idle callbacks added by the text control on the change of input style.
891   application.RunIdles();
892
893   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
894   DALI_TEST_CHECK( !inputStyleChangedSignal );
895
896   END_TEST;
897 }
898
899 int utcDaliTextEditorInputStyleChanged02(void)
900 {
901   ToolkitTestApplication application;
902   tet_infoline(" utcDaliTextEditorInputStyleChanged02");
903
904   // The text-editor emits signals when the input style changes. These changes of style are
905   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
906   // can't be emitted during the size negotiation as the callbacks may update the UI.
907   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
908   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
909   application.CreateAdaptor();
910
911   // Load some fonts.
912
913   char* pathNamePtr = get_current_dir_name();
914   const std::string pathName( pathNamePtr );
915   free( pathNamePtr );
916
917   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
918   fontClient.SetDpi( 93u, 93u );
919
920   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
921   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
922
923   TextEditor editor = TextEditor::New();
924   DALI_TEST_CHECK( editor );
925
926
927   editor.SetSize( 300.f, 50.f );
928   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
929   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
930
931   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
932   editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='blue'> l</color><color value='green'>lo</color> <font weight='bold'>world</font> demo</font>" );
933
934   // connect to the text changed signal.
935   ConnectionTracker* testTracker = new ConnectionTracker();
936   editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
937   bool inputStyleChangedSignal = false;
938   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
939
940   Stage::GetCurrent().Add( editor );
941
942   // Render and notify
943   application.SendNotification();
944   application.Render();
945
946   // Executes the idle callbacks added by the text control on the change of input style.
947   application.RunIdles();
948
949   gInputStyleChangedCallbackCalled = false;
950   gInputStyleMask = TextEditor::InputStyle::NONE;
951   inputStyleChangedSignal = false;
952
953   // Create a tap event to touch the text editor.
954   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
955   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
956   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
957   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
958
959   // Render and notify
960   application.SendNotification();
961   application.Render();
962
963   // Executes the idle callbacks added by the text control on the change of input style.
964   application.RunIdles();
965
966   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
967   if( gInputStyleChangedCallbackCalled )
968   {
969     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
970                       static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
971                                                  TextEditor::InputStyle::POINT_SIZE  |
972                                                  TextEditor::InputStyle::COLOR ),
973                       TEST_LOCATION );
974
975     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
976     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
977
978     const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
979     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
980
981     const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
982     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
983   }
984   DALI_TEST_CHECK( inputStyleChangedSignal );
985
986   gInputStyleChangedCallbackCalled = false;
987   gInputStyleMask = TextEditor::InputStyle::NONE;
988   inputStyleChangedSignal = false;
989
990   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
991
992   // Render and notify
993   application.SendNotification();
994   application.Render();
995
996   // Executes the idle callbacks added by the text control on the change of input style.
997   application.RunIdles();
998
999   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1000   if( gInputStyleChangedCallbackCalled )
1001   {
1002     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1003                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1004                       TEST_LOCATION );
1005
1006     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1007     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1008   }
1009   DALI_TEST_CHECK( inputStyleChangedSignal );
1010
1011   gInputStyleChangedCallbackCalled = false;
1012   gInputStyleMask = TextEditor::InputStyle::NONE;
1013   inputStyleChangedSignal = false;
1014
1015   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1016
1017   // Render and notify
1018   application.SendNotification();
1019   application.Render();
1020
1021   // Executes the idle callbacks added by the text control on the change of input style.
1022   application.RunIdles();
1023
1024   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1025   DALI_TEST_CHECK( !inputStyleChangedSignal );
1026
1027   gInputStyleChangedCallbackCalled = false;
1028   gInputStyleMask = TextEditor::InputStyle::NONE;
1029   inputStyleChangedSignal = false;
1030
1031   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1032
1033   // Render and notify
1034   application.SendNotification();
1035   application.Render();
1036
1037   // Executes the idle callbacks added by the text control on the change of input style.
1038   application.RunIdles();
1039
1040   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1041   if( gInputStyleChangedCallbackCalled )
1042   {
1043     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1044                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1045                       TEST_LOCATION );
1046
1047     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1048     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1049   }
1050   DALI_TEST_CHECK( inputStyleChangedSignal );
1051
1052   gInputStyleChangedCallbackCalled = false;
1053   gInputStyleMask = TextEditor::InputStyle::NONE;
1054   inputStyleChangedSignal = false;
1055
1056   editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1057
1058   Property::Map fontStyleMapSet;
1059   fontStyleMapSet.Insert( "weight", "thin" );
1060   fontStyleMapSet.Insert( "width", "condensed" );
1061   fontStyleMapSet.Insert( "slant", "italic" );
1062
1063   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1064   editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1065   editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1066
1067   editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1068   editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1069   editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1070   editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1071
1072   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1073
1074   // Render and notify
1075   application.SendNotification();
1076   application.Render();
1077
1078   // Executes the idle callbacks added by the text control on the change of input style.
1079   application.RunIdles();
1080
1081   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1082   DALI_TEST_CHECK( !inputStyleChangedSignal );
1083
1084   // Create a tap event to touch the text editor.
1085   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1086   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1087
1088   // Render and notify
1089   application.SendNotification();
1090   application.Render();
1091
1092   // Executes the idle callbacks added by the text control on the change of input style.
1093   application.RunIdles();
1094
1095   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1096   if( gInputStyleChangedCallbackCalled )
1097   {
1098     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1099                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1100                                                  TextEditor::InputStyle::POINT_SIZE |
1101                                                  TextEditor::InputStyle::FONT_STYLE |
1102                                                  TextEditor::InputStyle::LINE_SPACING |
1103                                                  TextEditor::InputStyle::UNDERLINE |
1104                                                  TextEditor::InputStyle::SHADOW |
1105                                                  TextEditor::InputStyle::EMBOSS |
1106                                                  TextEditor::InputStyle::OUTLINE ),
1107                       TEST_LOCATION );
1108
1109     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1110     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1111   }
1112   DALI_TEST_CHECK( inputStyleChangedSignal );
1113
1114   gInputStyleChangedCallbackCalled = false;
1115   gInputStyleMask = TextEditor::InputStyle::NONE;
1116   inputStyleChangedSignal = false;
1117
1118   editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1119
1120   fontStyleMapSet.Clear();
1121   fontStyleMapSet.Insert( "weight", "black" );
1122   fontStyleMapSet.Insert( "width", "expanded" );
1123   fontStyleMapSet.Insert( "slant", "oblique" );
1124
1125   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1126
1127   // Create a tap event to touch the text editor.
1128   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1129   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1130
1131   // Render and notify
1132   application.SendNotification();
1133   application.Render();
1134
1135   // Executes the idle callbacks added by the text control on the change of input style.
1136   application.RunIdles();
1137
1138   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1139   if( gInputStyleChangedCallbackCalled )
1140   {
1141     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1142                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1143                                                  TextEditor::InputStyle::POINT_SIZE |
1144                                                  TextEditor::InputStyle::FONT_STYLE ),
1145                       TEST_LOCATION );
1146
1147     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1148     DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1149   }
1150   DALI_TEST_CHECK( inputStyleChangedSignal );
1151
1152   END_TEST;
1153 }
1154
1155 int utcDaliTextEditorEvent01(void)
1156 {
1157   ToolkitTestApplication application;
1158   tet_infoline(" utcDaliTextEditorEvent01");
1159
1160   // Creates a tap event. After creating a tap event the text editor should
1161   // have the focus and add text with key events should be possible.
1162
1163   TextEditor editor = TextEditor::New();
1164   DALI_TEST_CHECK( editor );
1165
1166   Stage::GetCurrent().Add( editor );
1167
1168   editor.SetSize( 300.f, 50.f );
1169   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1170   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1171
1172   // Avoid a crash when core load gl resources.
1173   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1174
1175   // Render and notify
1176   application.SendNotification();
1177   application.Render();
1178
1179   // Add a key event but as the text editor has not the focus it should do nothing.
1180   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1181
1182   // Render and notify
1183   application.SendNotification();
1184   application.Render();
1185
1186   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1187
1188   // Create a tap event to touch the text editor.
1189   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1190   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1191
1192   // Render and notify
1193   application.SendNotification();
1194   application.Render();
1195
1196   // Now the text editor has the focus, so it can handle the key events.
1197   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1198   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1199
1200   // Render and notify
1201   application.SendNotification();
1202   application.Render();
1203
1204   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1205
1206   // Create a second text editor and send key events to it.
1207   TextEditor editor2 = TextEditor::New();
1208
1209   editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1210   editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1211   editor2.SetSize( 100.f, 100.f );
1212   editor2.SetPosition( 100.f, 100.f );
1213
1214   Stage::GetCurrent().Add( editor2 );
1215
1216   // Render and notify
1217   application.SendNotification();
1218   application.Render();
1219
1220   // Create a tap event on the second text editor.
1221   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1222   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1223
1224   // Render and notify
1225   application.SendNotification();
1226   application.Render();
1227
1228   // The second text editor has the focus. It should handle the key events.
1229   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1230   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1231
1232   // Render and notify
1233   application.SendNotification();
1234   application.Render();
1235
1236   // Check the text has been added to the second text editor.
1237   DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1238
1239   END_TEST;
1240 }
1241
1242 int utcDaliTextEditorEvent02(void)
1243 {
1244   ToolkitTestApplication application;
1245   tet_infoline(" utcDaliTextEditorEvent02");
1246
1247   // Checks if the right number of actors are created.
1248
1249   TextEditor editor = TextEditor::New();
1250   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1251   DALI_TEST_CHECK( editor );
1252
1253   Stage::GetCurrent().Add( editor );
1254
1255   editor.SetSize( 300.f, 50.f );
1256   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1257   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1258
1259   // Avoid a crash when core load gl resources.
1260   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1261
1262   // Render and notify
1263   application.SendNotification();
1264   application.Render();
1265
1266   // Check there are the expected number of children (the stencil).
1267   DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1268
1269   Actor stencil = editor.GetChildAt( 0u );
1270
1271   // Create a tap event to touch the text editor.
1272   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1273   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1274
1275   // Render and notify
1276   application.SendNotification();
1277   application.Render();
1278
1279   Actor layer = editor.GetChildAt( 1u );
1280   DALI_TEST_CHECK( layer.IsLayer() );
1281
1282   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1283   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1284
1285   // Now the text editor has the focus, so it can handle the key events.
1286   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1287   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1288
1289   // Render and notify
1290   application.SendNotification();
1291   application.Render();
1292
1293   // Checks the cursor and the renderer have been created.
1294   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1295   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1296
1297   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1298   DALI_TEST_CHECK( cursor );
1299
1300   // The stencil actor has a container with all the actors which contain the text renderers.
1301   Actor container = stencil.GetChildAt( 0u );
1302   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1303   {
1304     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1305     DALI_TEST_CHECK( renderer );
1306   }
1307
1308   // Move the cursor and check the position changes.
1309   Vector3 position1 = cursor.GetCurrentPosition();
1310
1311   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1312   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1313
1314   // Render and notify
1315   application.SendNotification();
1316   application.Render();
1317
1318   Vector3 position2 = cursor.GetCurrentPosition();
1319
1320   DALI_TEST_CHECK( position2.x < position1.x );
1321
1322   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1323   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1324
1325   // Render and notify
1326   application.SendNotification();
1327   application.Render();
1328
1329   Vector3 position3 = cursor.GetCurrentPosition();
1330
1331   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1332
1333   // Send some taps and check the cursor positions.
1334
1335   // Try to tap at the beginning.
1336   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1337   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1338
1339   // Render and notify
1340   application.SendNotification();
1341   application.Render();
1342
1343   // Cursor position should be the same than position1.
1344   Vector3 position4 = cursor.GetCurrentPosition();
1345
1346   DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1347
1348   // Tap away from the start position.
1349   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1350   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1351
1352   // Render and notify
1353   application.SendNotification();
1354   application.Render();
1355
1356   Vector3 position5 = cursor.GetCurrentPosition();
1357
1358   DALI_TEST_CHECK( position5.x > position4.x );
1359
1360   // Remove all the text.
1361   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1362   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1363   editor.SetProperty( TextEditor::Property::TEXT, "" );
1364
1365   // Render and notify
1366   application.SendNotification();
1367   application.Render();
1368
1369   // Cursor position should be the same than position2.
1370   Vector3 position6 = cursor.GetCurrentPosition();
1371
1372   DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1373
1374   // Should not be a renderer.
1375   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1376
1377   END_TEST;
1378 }
1379
1380 int utcDaliTextEditorEvent03(void)
1381 {
1382   ToolkitTestApplication application;
1383   tet_infoline(" utcDaliTextEditorEvent03");
1384
1385   // Checks if the highlight actor is created.
1386
1387   TextEditor editor = TextEditor::New();
1388   DALI_TEST_CHECK( editor );
1389
1390   Stage::GetCurrent().Add( editor );
1391
1392   editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1393   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1394   editor.SetSize( 30.f, 50.f );
1395   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1396   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1397
1398   // Avoid a crash when core load gl resources.
1399   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1400
1401   // Render and notify
1402   application.SendNotification();
1403   application.Render();
1404
1405   // Send some taps and check text controller with clipboard window
1406   Dali::Clipboard clipboard = Clipboard::Get();
1407   clipboard.ShowClipboard();
1408   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1409   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1410   clipboard.HideClipboard();
1411
1412   // Render and notify
1413   application.SendNotification();
1414   application.Render();
1415
1416   // Tap first to get the focus.
1417   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1418   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1419
1420   // Render and notify
1421   application.SendNotification();
1422   application.Render();
1423
1424   // Double tap to select a word.
1425   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1426   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1427
1428   // Render and notify
1429   application.SendNotification();
1430   application.Render();
1431
1432   // The stencil actor should have two actors: the renderer and the highlight actor.
1433   Actor stencil = editor.GetChildAt( 0u );
1434
1435   // The stencil actor has a container with all the actors which contain the text renderers.
1436   Actor container = stencil.GetChildAt( 0u );
1437   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1438   {
1439     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1440     DALI_TEST_CHECK( renderer );
1441   }
1442
1443   Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1444   DALI_TEST_CHECK( highlight );
1445
1446   END_TEST;
1447 }
1448
1449 int utcDaliTextEditorEvent04(void)
1450 {
1451   ToolkitTestApplication application;
1452   tet_infoline(" utcDaliTextEditorEvent04");
1453
1454   // Checks if the highlight actor is created.
1455
1456   TextEditor editor = TextEditor::New();
1457   DALI_TEST_CHECK( editor );
1458
1459   Stage::GetCurrent().Add( editor );
1460
1461   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1462   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1463   editor.SetSize( 100.f, 50.f );
1464   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1465   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1466
1467   // Avoid a crash when core load gl resources.
1468   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1469
1470   // Render and notify
1471   application.SendNotification();
1472   application.Render();
1473
1474   // Tap on the text editor
1475   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1476   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1477
1478   // Render and notify
1479   application.SendNotification();
1480   application.Render();
1481
1482   // Move at the end of the text.
1483   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1484   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1485
1486   // Render and notify
1487   application.SendNotification();
1488   application.Render();
1489
1490   for( unsigned int index = 0u; index < 10u; ++index )
1491   {
1492     application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1493     application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1494
1495     // Render and notify
1496     application.SendNotification();
1497     application.Render();
1498   }
1499
1500   // Add a character
1501   application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1502
1503   // Render and notify
1504   application.SendNotification();
1505   application.Render();
1506
1507   DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1508
1509   // Add some key events
1510   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1511   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1512
1513   // Render and notify
1514   application.SendNotification();
1515   application.Render();
1516
1517   for( unsigned int index = 0u; index < 10u; ++index )
1518   {
1519     application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1520     application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1521
1522     // Render and notify
1523     application.SendNotification();
1524     application.Render();
1525   }
1526
1527   // Add a character
1528   application.ProcessEvent( GenerateKey( " ", " ", 0, 0, 0, Integration::KeyEvent::Down ) );
1529
1530   // Render and notify
1531   application.SendNotification();
1532   application.Render();
1533
1534   DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1535
1536   END_TEST;
1537 }
1538
1539 int utcDaliTextEditorEvent05(void)
1540 {
1541   ToolkitTestApplication application;
1542   tet_infoline(" utcDaliTextEditorEvent05");
1543
1544   // Checks if the highlight actor is created.
1545
1546   TextEditor editor = TextEditor::New();
1547   DALI_TEST_CHECK( editor );
1548
1549   Stage::GetCurrent().Add( editor );
1550
1551   editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1552   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1553   editor.SetSize( 50.f, 50.f );
1554   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1555   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1556   editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1557   editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1558
1559   // Avoid a crash when core load gl resources.
1560   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1561
1562   // Render and notify
1563   application.SendNotification();
1564   application.Render();
1565
1566   // Tap on the text editor
1567   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1568   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1569
1570   // Render and notify
1571   application.SendNotification();
1572   application.Render();
1573
1574   // Move at the end of the text.
1575   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1576   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1577
1578   // Render and notify
1579   application.SendNotification();
1580   application.Render();
1581
1582   for( unsigned int index = 0u; index < 10u; ++index )
1583   {
1584     // Add a character
1585     application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1586
1587     // Render and notify
1588     application.SendNotification();
1589     application.Render();
1590   }
1591   // Modify duration after scroll is enabled
1592   editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1593
1594   // Continuous scroll left to increase coverage
1595   for( unsigned int index = 0u; index < 10u; ++index )
1596   {
1597     application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1598
1599     // Render and notify
1600     application.SendNotification();
1601     application.Render();
1602   }
1603   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1604   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1605
1606   END_TEST;
1607 }