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