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