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