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