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