[dali_1.1.29] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextEditor.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali/devel-api/rendering/renderer.h>
21 #include <dali/integration-api/events/key-event-integ.h>
22 #include <dali/integration-api/events/tap-gesture-event.h>
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-editor.h> ///< @todo to be removed when text-editor is added to the dali-toolkit.h
26 #include <dali-toolkit/devel-api/styling/style-manager.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30
31 void dali_texteditor_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void dali_texteditor_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 namespace
42 {
43
44 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
45 const char* const PROPERTY_NAME_TEXT                                 = "text";
46 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
47 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
48 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
49 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
50 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
51 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
52 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
53 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
54 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
55 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
56 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
57 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
58 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
59 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
60 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
61 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
68 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
69 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
70 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
71 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
72 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
73 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
74
75 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
76
77 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
78
79 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
80 const float TO_MILLISECONDS = 1000.f;
81 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
82
83 const float SCROLL_THRESHOLD = 10.f;
84 const float SCROLL_SPEED = 300.f;
85
86 static bool gTextChangedCallBackCalled;
87
88 static void TestTextChangedCallback( TextEditor control )
89 {
90   tet_infoline(" TestTextChangedCallback");
91
92   gTextChangedCallBackCalled = true;
93 }
94
95 // Generate a TapGestureEvent to send to Core.
96 Integration::TapGestureEvent GenerateTap(
97     Gesture::State state,
98     unsigned int numberOfTaps,
99     unsigned int numberOfTouches,
100     Vector2 point)
101 {
102   Integration::TapGestureEvent tap( state );
103
104   tap.numberOfTaps = numberOfTaps;
105   tap.numberOfTouches = numberOfTouches;
106   tap.point = point;
107
108   return tap;
109 }
110
111 // Generate a KeyEvent to send to Core.
112 Integration::KeyEvent GenerateKey( const std::string& keyName,
113                                    const std::string& keyString,
114                                    int keyCode,
115                                    int keyModifier,
116                                    unsigned long timeStamp,
117                                    const Integration::KeyEvent::State& keyState )
118 {
119   return Integration::KeyEvent( keyName,
120                                 keyString,
121                                 keyCode,
122                                 keyModifier,
123                                 timeStamp,
124                                 keyState );
125 }
126
127 } // namespace
128
129 int UtcDaliToolkitTextEditorConstructorP(void)
130 {
131   ToolkitTestApplication application;
132   tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
133   TextEditor textEditor;
134   DALI_TEST_CHECK( !textEditor );
135   END_TEST;
136 }
137
138 int UtcDaliToolkitTextEditorNewP(void)
139 {
140   ToolkitTestApplication application;
141   tet_infoline(" UtcDaliToolkitTextEditorNewP");
142   TextEditor textEditor = TextEditor::New();
143   DALI_TEST_CHECK( textEditor );
144   END_TEST;
145 }
146
147 int UtcDaliToolkitTextEditorDownCastP(void)
148 {
149   ToolkitTestApplication application;
150   tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
151   TextEditor textEditor1 = TextEditor::New();
152   BaseHandle object( textEditor1 );
153
154   TextEditor textEditor2 = TextEditor::DownCast( object );
155   DALI_TEST_CHECK( textEditor2 );
156
157   TextEditor textEditor3 = DownCast< TextEditor >( object );
158   DALI_TEST_CHECK( textEditor3 );
159   END_TEST;
160 }
161
162 int UtcDaliToolkitTextEditorDownCastN(void)
163 {
164   ToolkitTestApplication application;
165   tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
166   BaseHandle uninitializedObject;
167   TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
168   DALI_TEST_CHECK( !textEditor1 );
169
170   TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
171   DALI_TEST_CHECK( !textEditor2 );
172   END_TEST;
173 }
174
175 int UtcDaliToolkitTextEditorCopyConstructorP(void)
176 {
177   ToolkitTestApplication application;
178   tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
179   TextEditor textEditor = TextEditor::New();
180   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
181
182   TextEditor copy( textEditor );
183   DALI_TEST_CHECK( copy );
184   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textEditor.GetProperty<std::string>( TextLabel::Property::TEXT ) );
185   END_TEST;
186 }
187
188 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
189 {
190   ToolkitTestApplication application;
191   tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
192   TextEditor textEditor = TextEditor::New();
193   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
194
195   TextEditor copy = textEditor;
196   DALI_TEST_CHECK( copy );
197   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
198   END_TEST;
199 }
200
201 int UtcDaliTextEditorNewP(void)
202 {
203   ToolkitTestApplication application;
204   tet_infoline(" UtcDaliToolkitTextEditorNewP");
205   TextEditor textEditor = TextEditor::New();
206   DALI_TEST_CHECK( textEditor );
207   END_TEST;
208 }
209
210 // Positive test case for a method
211 int UtcDaliTextEditorGetPropertyP(void)
212 {
213   ToolkitTestApplication application;
214   tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
215   TextEditor editor = TextEditor::New();
216   DALI_TEST_CHECK( editor );
217
218   // Check Property Indices are correct
219   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
220   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
221   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
222   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
223   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
224   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
225   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
226   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
227   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
228   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
229   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
230   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
231   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
232   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
233   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
234   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
235   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
236   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
237   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
238   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
239   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
240   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
241   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
242   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
243   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
244   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
245   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
246   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
247   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
248   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
249   END_TEST;
250 }
251
252 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
253 {
254   bool result = false;
255   Property::Map imageMap;
256   imageMap[mapKey] =mapValue;
257
258   editor.SetProperty( property , imageMap );
259   Property::Value propValue = editor.GetProperty( property );
260   Property::Map* resultMap = propValue.GetMap();
261
262   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
263   {
264     result = true;
265   }
266
267   return result;
268 }
269
270 // Positive test case for a method
271 int UtcDaliTextEditorSetPropertyP(void)
272 {
273   ToolkitTestApplication application;
274   tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
275   TextEditor editor = TextEditor::New();
276   DALI_TEST_CHECK( editor );
277   Stage::GetCurrent().Add( editor );
278
279   // Note - we can't check the defaults since the stylesheets are platform-specific
280
281   // Check the render backend property.
282   editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
283   DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
284
285   // Check text property.
286   editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
287   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
288
289   // Check text's color property
290   editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
291   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
292
293   // Check font properties.
294   editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
295   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
296   editor.SetProperty( TextEditor::Property::FONT_STYLE, "Setting font style" );
297   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION );
298   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
299   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
300
301   // Check that the Alignment properties can be correctly set
302   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
303   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
304
305   // Check scroll properties.
306   editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
307   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
308   editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
309   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
310
311   // Check cursor properties
312   editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
313   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
314   editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
315   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
316
317   editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
318   DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
319   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
320   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
321   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
322   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
323   editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
324   DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
325
326   // Check handle images
327   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
328   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
329   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
330   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
331   editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
332
333   // Check handle images
334   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
335   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
336   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
337   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
338   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
339   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
340
341   // Check the highlight color
342   editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
343   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
344
345   // Decoration bounding box
346   editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
347   DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
348
349   // Check the enable markup property.
350   DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
351   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
352   DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
353
354   // Check input color property.
355   editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
356   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
357
358   // Check input font properties.
359   editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
360   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
361   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "Setting input font style" );
362   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION );
363   editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
364   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
365
366   END_TEST;
367 }
368
369 // Positive Atlas Text Renderer test
370 int utcDaliTextEditorAtlasRenderP(void)
371 {
372   ToolkitTestApplication application;
373   tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
374   StyleManager styleManager = StyleManager::Get();
375   styleManager.RequestDefaultTheme();
376   TextEditor editor = TextEditor::New();
377   DALI_TEST_CHECK( editor );
378
379   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
380
381   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
382
383   Stage::GetCurrent().Add( editor );
384
385   try
386   {
387     // Render some text with the shared atlas backend
388     editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
389     application.SendNotification();
390     application.Render();
391   }
392   catch( ... )
393   {
394     tet_result(TET_FAIL);
395   }
396   END_TEST;
397 }
398
399 // Positive test for the textChanged signal.
400 int utcDaliTextEditorTextChangedP(void)
401 {
402   ToolkitTestApplication application;
403   tet_infoline(" utcDaliTextEditorTextChangedP");
404   TextEditor editor = TextEditor::New();
405   DALI_TEST_CHECK( editor );
406
407   Stage::GetCurrent().Add( editor );
408
409   editor.TextChangedSignal().Connect(&TestTextChangedCallback);
410
411   gTextChangedCallBackCalled = false;
412   editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
413   DALI_TEST_CHECK( gTextChangedCallBackCalled );
414
415   application.SendNotification();
416
417   editor.SetKeyInputFocus();
418
419   gTextChangedCallBackCalled = false;
420   application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
421   DALI_TEST_CHECK( gTextChangedCallBackCalled );
422
423   END_TEST;
424 }
425
426 int utcDaliTextEditorEvent01(void)
427 {
428   ToolkitTestApplication application;
429   tet_infoline(" utcDaliTextEditorEvent01");
430
431   // Creates a tap event. After creating a tap event the text editor should
432   // have the focus and add text with key events should be possible.
433
434   TextEditor editor = TextEditor::New();
435   DALI_TEST_CHECK( editor );
436
437   Stage::GetCurrent().Add( editor );
438
439   editor.SetSize( 300.f, 50.f );
440   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
441   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
442
443   // Avoid a crash when core load gl resources.
444   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
445
446   // Render and notify
447   application.SendNotification();
448   application.Render();
449
450   // Add a key event but as the text editor has not the focus it should do nothing.
451   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
452
453   // Render and notify
454   application.SendNotification();
455   application.Render();
456
457   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
458
459   // Create a tap event to touch the text editor.
460   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
461   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
462
463   // Render and notify
464   application.SendNotification();
465   application.Render();
466
467   // Now the text editor has the focus, so it can handle the key events.
468   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
469   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
470
471   // Render and notify
472   application.SendNotification();
473   application.Render();
474
475   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
476
477   // Create a second text editor and send key events to it.
478   TextEditor editor2 = TextEditor::New();
479
480   editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
481   editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
482   editor2.SetSize( 100.f, 100.f );
483   editor2.SetPosition( 100.f, 100.f );
484
485   Stage::GetCurrent().Add( editor2 );
486
487   // Render and notify
488   application.SendNotification();
489   application.Render();
490
491   // Create a tap event on the second text editor.
492   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
493   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
494
495   // Render and notify
496   application.SendNotification();
497   application.Render();
498
499   // The second text editor has the focus. It should handle the key events.
500   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
501   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
502
503   // Render and notify
504   application.SendNotification();
505   application.Render();
506
507   // Check the text has been added to the second text editor.
508   DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
509
510   END_TEST;
511 }
512
513 int utcDaliTextEditorEvent02(void)
514 {
515   ToolkitTestApplication application;
516   tet_infoline(" utcDaliTextEditorEvent02");
517
518   // Checks if the right number of actors are created.
519
520   TextEditor editor = TextEditor::New();
521   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
522   DALI_TEST_CHECK( editor );
523
524   Stage::GetCurrent().Add( editor );
525
526   editor.SetSize( 300.f, 50.f );
527   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
528   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
529
530   // Avoid a crash when core load gl resources.
531   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
532
533   // Render and notify
534   application.SendNotification();
535   application.Render();
536
537   // Check there are the expected number of children ( active layer, offscreen root actor, and the offscreen image actor
538   DALI_TEST_EQUALS( editor.GetChildCount(), 3u, TEST_LOCATION );
539
540   Actor layer = editor.GetChildAt( 0u );
541   DALI_TEST_CHECK( layer.IsLayer() );
542
543   Actor offscreenRoot = editor.GetChildAt( 1u );
544   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
545   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
546
547   Actor offscreenImage = editor.GetChildAt( 2u );
548   DALI_TEST_CHECK( offscreenImage );
549
550   // Create a tap event to touch the text editor.
551   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
552   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
553
554   // Render and notify
555   application.SendNotification();
556   application.Render();
557
558   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
559   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
560
561   // Now the text editor has the focus, so it can handle the key events.
562   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
563   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
564
565   // Render and notify
566   application.SendNotification();
567   application.Render();
568
569   // Checks the cursor and the renderer have been created.
570   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
571   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
572
573   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
574   DALI_TEST_CHECK( cursor );
575
576   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
577   DALI_TEST_CHECK( camera );
578
579   Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
580   DALI_TEST_CHECK( renderer );
581
582   // Move the cursor and check the position changes.
583   Vector3 position1 = cursor.GetCurrentPosition();
584
585   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
586   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
587
588   // Render and notify
589   application.SendNotification();
590   application.Render();
591
592   Vector3 position2 = cursor.GetCurrentPosition();
593
594   DALI_TEST_CHECK( position2.x < position1.x );
595
596   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
597   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
598
599   // Render and notify
600   application.SendNotification();
601   application.Render();
602
603   Vector3 position3 = cursor.GetCurrentPosition();
604
605   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
606
607   // Send some taps and check the cursor positions.
608
609   // Try to tap at the beginning.
610   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
611   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
612
613   // Render and notify
614   application.SendNotification();
615   application.Render();
616
617   // Cursor position should be the same than position1.
618   Vector3 position4 = cursor.GetCurrentPosition();
619
620   DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
621
622   // Tap away from the start position.
623   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
624   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
625
626   // Render and notify
627   application.SendNotification();
628   application.Render();
629
630   Vector3 position5 = cursor.GetCurrentPosition();
631
632   DALI_TEST_CHECK( position5.x > position4.x );
633
634   // Remove all the text.
635   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
636   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
637   editor.SetProperty( TextEditor::Property::TEXT, "" );
638
639   // Render and notify
640   application.SendNotification();
641   application.Render();
642
643   // Cursor position should be the same than position2.
644   Vector3 position6 = cursor.GetCurrentPosition();
645
646   DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
647
648   // Should not be a renderer.
649   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
650
651   END_TEST;
652 }
653
654 int utcDaliTextEditorEvent03(void)
655 {
656   ToolkitTestApplication application;
657   tet_infoline(" utcDaliTextEditorEvent03");
658
659   // Checks if the highlight actor is created.
660
661   TextEditor editor = TextEditor::New();
662   DALI_TEST_CHECK( editor );
663
664   Stage::GetCurrent().Add( editor );
665
666   editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
667   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
668   editor.SetSize( 30.f, 50.f );
669   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
670   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
671
672   // Avoid a crash when core load gl resources.
673   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
674
675   // Render and notify
676   application.SendNotification();
677   application.Render();
678
679   // Tap first to get the focus.
680   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
681   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
682
683   // Render and notify
684   application.SendNotification();
685   application.Render();
686
687   // Double tap to select a word.
688   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
689   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
690
691   // Render and notify
692   application.SendNotification();
693   application.Render();
694
695   // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
696   Actor offscreenRoot = editor.GetChildAt( 1u );
697   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
698
699   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
700   DALI_TEST_CHECK( camera );
701
702   Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
703   DALI_TEST_CHECK( renderer );
704
705   Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
706   DALI_TEST_CHECK( highlight );
707
708   END_TEST;
709 }