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