Merge "Add PIXEL_SIZE and ELLIPSIS property in text-controls" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
25
26 using namespace Dali;
27 using namespace Toolkit;
28
29 void dali_textlabel_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void dali_textlabel_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_FONT_FAMILY = "fontFamily";
45 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
46 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
47 const char* const PROPERTY_NAME_MULTI_LINE =  "multiLine";
48 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
49 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
50 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
51 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
52 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
53 const char* const PROPERTY_NAME_UNDERLINE_ENABLED = "underlineEnabled";
54 const char* const PROPERTY_NAME_UNDERLINE_COLOR = "underlineColor";
55 const char* const PROPERTY_NAME_UNDERLINE_HEIGHT = "underlineHeight";
56 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
57 const char* const PROPERTY_NAME_ENABLE_AUTO_SCROLL = "enableAutoScroll";
58 const char* const PROPERTY_NAME_ENABLE_AUTO_SCROLL_SPEED = "autoScrollSpeed";
59 const char* const PROPERTY_NAME_ENABLE_AUTO_SCROLL_LOOPS = "autoScrollLoopCount";
60 const char* const PROPERTY_NAME_ENABLE_AUTO_SCROLL_GAP = "autoScrollGap";
61
62 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
63 const char* const PROPERTY_NAME_UNDERLINE = "underline";
64 const char* const PROPERTY_NAME_SHADOW = "shadow";
65 const char* const PROPERTY_NAME_EMBOSS = "emboss";
66 const char* const PROPERTY_NAME_OUTLINE = "outline";
67
68 const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize";
69 const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis";
70
71 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
72 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
73 const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64
74
75 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
76 {
77   if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
78   {
79     for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
80     {
81       const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
82
83       Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
84       if( NULL != valueSet )
85       {
86         if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
87         {
88           tet_printf( "  Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
89           return false;
90         }
91       }
92       else
93       {
94         tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
95         return false;
96       }
97     }
98   }
99
100   return true;
101 }
102
103 } // namespace
104
105 int UtcDaliToolkitTextLabelConstructorP(void)
106 {
107   ToolkitTestApplication application;
108   tet_infoline(" UtcDaliToolkitTextLabelConstructorP");
109   TextLabel textLabel;
110   DALI_TEST_CHECK( !textLabel );
111   END_TEST;
112 }
113
114 int UtcDaliToolkitTextLabelNewP(void)
115 {
116   ToolkitTestApplication application;
117   tet_infoline(" UtcDaliToolkitTextLabelNewP");
118   TextLabel textLabel = TextLabel::New( "Test Text" );
119   DALI_TEST_CHECK( textLabel );
120   END_TEST;
121 }
122
123 int UtcDaliToolkitTextLabelDownCastP(void)
124 {
125   ToolkitTestApplication application;
126   tet_infoline(" UtcDaliToolkitTextLabelDownCastP");
127   TextLabel textLabel1 = TextLabel::New();
128   BaseHandle object( textLabel1 );
129
130   TextLabel textLabel2 = TextLabel::DownCast( object );
131   DALI_TEST_CHECK( textLabel2 );
132
133   TextLabel textLabel3 = DownCast< TextLabel >( object );
134   DALI_TEST_CHECK( textLabel3 );
135   END_TEST;
136 }
137
138 int UtcDaliToolkitTextLabelDownCastN(void)
139 {
140   ToolkitTestApplication application;
141   tet_infoline(" UtcDaliToolkitTextLabelDownCastN");
142   BaseHandle uninitializedObject;
143   TextLabel textLabel1 = TextLabel::DownCast( uninitializedObject );
144   DALI_TEST_CHECK( !textLabel1 );
145
146   TextLabel textLabel2 = DownCast< TextLabel >( uninitializedObject );
147   DALI_TEST_CHECK( !textLabel2 );
148   END_TEST;
149 }
150
151 int UtcDaliToolkitTextLabelCopyConstructorP(void)
152 {
153   ToolkitTestApplication application;
154   tet_infoline(" UtcDaliToolkitTextLabelCopyConstructorP");
155   TextLabel textLabel = TextLabel::New();
156   textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED );
157
158   TextLabel copy( textLabel );
159   DALI_TEST_CHECK( copy );
160   DALI_TEST_CHECK( copy.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ) == textLabel.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ) );
161   END_TEST;
162 }
163
164 int UtcDaliToolkitTextLabelAssignmentOperatorP(void)
165 {
166   ToolkitTestApplication application;
167   tet_infoline(" UtcDaliToolkitTextLabelAssingmentOperatorP");
168   TextLabel textLabel = TextLabel::New();
169   textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED );
170
171   TextLabel copy = textLabel;
172   DALI_TEST_CHECK( copy );
173   DALI_TEST_CHECK( copy.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ) == textLabel.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ) );
174   END_TEST;
175 }
176
177 // Positive test case for a method
178 int UtcDaliToolkitTextLabelGetPropertyP(void)
179 {
180   ToolkitTestApplication application;
181   tet_infoline(" UtcDaliToolkitTextLabelGetPropertyP");
182   TextLabel label = TextLabel::New("Test Text");
183   DALI_TEST_CHECK( label );
184
185   // Check Property Indices are correct
186   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextLabel::Property::RENDERING_BACKEND );
187   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextLabel::Property::TEXT );
188   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextLabel::Property::FONT_FAMILY );
189   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextLabel::Property::FONT_STYLE );
190   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextLabel::Property::POINT_SIZE );
191   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_MULTI_LINE ) == TextLabel::Property::MULTI_LINE );
192   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextLabel::Property::HORIZONTAL_ALIGNMENT );
193   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextLabel::Property::VERTICAL_ALIGNMENT );
194   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextLabel::Property::TEXT_COLOR );
195   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextLabel::Property::SHADOW_OFFSET );
196   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextLabel::Property::SHADOW_COLOR );
197   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_ENABLED ) == TextLabel::Property::UNDERLINE_ENABLED );
198   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_COLOR ) == TextLabel::Property::UNDERLINE_COLOR );
199   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_HEIGHT) == TextLabel::Property::UNDERLINE_HEIGHT );
200   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP) == TextLabel::Property::ENABLE_MARKUP );
201   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_AUTO_SCROLL ) == TextLabel::Property::ENABLE_AUTO_SCROLL );
202   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_AUTO_SCROLL_SPEED ) == TextLabel::Property::AUTO_SCROLL_SPEED );
203   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_AUTO_SCROLL_LOOPS ) == TextLabel::Property::AUTO_SCROLL_LOOP_COUNT );
204   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ENABLE_AUTO_SCROLL_GAP ) == TextLabel::Property::AUTO_SCROLL_GAP );
205   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextLabel::Property::LINE_SPACING );
206   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextLabel::Property::UNDERLINE );
207   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextLabel::Property::SHADOW );
208   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextLabel::Property::EMBOSS );
209   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextLabel::Property::OUTLINE );
210   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextLabel::Property::PIXEL_SIZE );
211   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == DevelTextLabel::Property::ELLIPSIS );
212
213   END_TEST;
214 }
215
216 int UtcDaliToolkitTextLabelSetPropertyP(void)
217 {
218   ToolkitTestApplication application;
219   tet_infoline(" UtcDaliToolkitTextLabelSetPropertyP");
220   TextLabel label = TextLabel::New();
221   DALI_TEST_CHECK( label );
222
223   // Note - we can't check the defaults since the stylesheets are platform-specific
224   label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
225   DALI_TEST_EQUALS( (Text::RenderingType)label.GetProperty<int>( TextLabel::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
226
227   // Check that text can be correctly reset
228   label.SetProperty( TextLabel::Property::TEXT, "Setting Text" );
229   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
230
231   // Check font properties.
232   label.SetProperty( TextLabel::Property::FONT_FAMILY, "Setting font family" );
233   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
234
235   Property::Map fontStyleMapSet;
236   Property::Map fontStyleMapGet;
237
238   fontStyleMapSet.Insert( "weight", "bold" );
239   fontStyleMapSet.Insert( "width", "condensed" );
240   fontStyleMapSet.Insert( "slant", "italic" );
241   label.SetProperty( TextLabel::Property::FONT_STYLE, fontStyleMapSet );
242
243   fontStyleMapGet = label.GetProperty<Property::Map>( TextLabel::Property::FONT_STYLE );
244   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
245   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
246
247   // Check the old font style format.
248   fontStyleMapSet.Clear();
249   fontStyleMapSet.Insert( "weight", "thin" );
250   fontStyleMapSet.Insert( "width", "expanded" );
251   fontStyleMapSet.Insert( "slant", "oblique" );
252
253   label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"expanded\",\"slant\":\"oblique\"}" );
254   fontStyleMapGet = label.GetProperty<Property::Map>( TextLabel::Property::FONT_STYLE );
255   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
256   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
257
258   label.SetProperty( TextLabel::Property::POINT_SIZE, 10.f );
259   DALI_TEST_EQUALS( label.GetProperty<float>( TextLabel::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
260
261   // Reset font style.
262   fontStyleMapSet.Clear();
263   fontStyleMapSet.Insert( "weight", "normal" );
264   fontStyleMapSet.Insert( "slant", "oblique" );
265
266   label.SetProperty( TextLabel::Property::FONT_STYLE, fontStyleMapSet );
267   fontStyleMapGet = label.GetProperty<Property::Map>( TextLabel::Property::FONT_STYLE );
268   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
269   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
270
271   fontStyleMapSet.Clear();
272   fontStyleMapSet.Insert( "slant", "roman" );
273
274   label.SetProperty( TextLabel::Property::FONT_STYLE, fontStyleMapSet );
275   fontStyleMapGet = label.GetProperty<Property::Map>( TextLabel::Property::FONT_STYLE );
276   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
277
278   // Replace 'roman' for 'normal'.
279   Property::Value* slantValue = fontStyleMapGet.Find( "slant" );
280   if( NULL != slantValue )
281   {
282     if( "normal" == slantValue->Get<std::string>() )
283     {
284       fontStyleMapGet["slant"] = "roman";
285     }
286   }
287   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
288
289   fontStyleMapSet.Clear();
290
291   label.SetProperty( TextLabel::Property::FONT_STYLE, fontStyleMapSet );
292   fontStyleMapGet = label.GetProperty<Property::Map>( TextLabel::Property::FONT_STYLE );
293   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
294   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
295
296   // Toggle multi-line
297   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
298   DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::MULTI_LINE ), true, TEST_LOCATION );
299
300   // Check that the Alignment properties can be correctly set
301   label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
302   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::HORIZONTAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
303   label.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
304   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
305
306   // Check that text color can be properly set
307   label.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
308   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ), Color::BLUE, TEST_LOCATION );
309   // The underline color is changed as well.
310   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::UNDERLINE_COLOR ), Color::BLUE, TEST_LOCATION );
311
312   Property::Map underlineMapSet;
313   Property::Map underlineMapGet;
314
315   underlineMapSet.Insert( "enable", "false" );
316   underlineMapSet.Insert( "color", "blue" );
317   underlineMapSet.Insert( "height", "0" );
318
319   underlineMapGet = label.GetProperty<Property::Map>( TextLabel::Property::UNDERLINE );
320   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
321   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
322
323   // Check that shadow parameters can be correctly set
324   label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 3.0f, 3.0f ) );
325   DALI_TEST_EQUALS( label.GetProperty<Vector2>( TextLabel::Property::SHADOW_OFFSET ), Vector2( 3.0f, 3.0f ), TEST_LOCATION );
326   label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLUE );
327   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::SHADOW_COLOR ), Color::BLUE, TEST_LOCATION );
328
329   // Check that underline parameters can be correctly set
330   label.SetProperty( TextLabel::Property::UNDERLINE_ENABLED, true );
331   DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::UNDERLINE_ENABLED ), true, TEST_LOCATION );
332   label.SetProperty( TextLabel::Property::UNDERLINE_COLOR, Color::RED );
333   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::UNDERLINE_COLOR ), Color::RED, TEST_LOCATION );
334   label.SetProperty( TextLabel::Property::UNDERLINE_HEIGHT, 1.0f );
335   DALI_TEST_EQUALS( label.GetProperty<float>( TextLabel::Property::UNDERLINE_HEIGHT ), 1.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
336
337   TextLabel label2 = TextLabel::New( "New text" );
338   DALI_TEST_CHECK( label2 );
339   DALI_TEST_EQUALS( label2.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("New text"), TEST_LOCATION );
340
341   // Check the enable markup property.
342   DALI_TEST_CHECK( !label.GetProperty<bool>( TextLabel::Property::ENABLE_MARKUP ) );
343   label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
344   DALI_TEST_CHECK( label.GetProperty<bool>( TextLabel::Property::ENABLE_MARKUP ) );
345
346   // Check autoscroll properties
347   const int SCROLL_SPEED = 80;
348   const int SCROLL_LOOPS = 4;
349   const float SCROLL_GAP = 50.0f;
350   label.SetProperty( TextLabel::Property::MULTI_LINE, false ); // Autoscroll only supported in single line
351   DALI_TEST_CHECK( !label.GetProperty<bool>( TextLabel::Property::ENABLE_AUTO_SCROLL ) );
352   label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true );
353   DALI_TEST_CHECK( label.GetProperty<bool>( TextLabel::Property::ENABLE_AUTO_SCROLL ) );
354   label.SetProperty( TextLabel::Property::AUTO_SCROLL_SPEED, SCROLL_SPEED );
355   DALI_TEST_EQUALS( SCROLL_SPEED, label.GetProperty<int>( TextLabel::Property::AUTO_SCROLL_SPEED ), TEST_LOCATION );
356   label.SetProperty( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, SCROLL_LOOPS );
357   DALI_TEST_EQUALS( SCROLL_LOOPS, label.GetProperty<int>( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT ), TEST_LOCATION );
358   label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, SCROLL_GAP );
359   DALI_TEST_EQUALS( SCROLL_GAP, label.GetProperty<float>( TextLabel::Property::AUTO_SCROLL_GAP ), TEST_LOCATION );
360
361   // Check the line spacing property
362   DALI_TEST_EQUALS( label.GetProperty<float>( TextLabel::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
363   label.SetProperty( TextLabel::Property::LINE_SPACING, 10.f );
364   DALI_TEST_EQUALS( label.GetProperty<float>( TextLabel::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
365
366   // Check the underline property
367
368   underlineMapSet.Clear();
369   underlineMapSet.Insert( "enable", "true" );
370   underlineMapSet.Insert( "color", "red" );
371   underlineMapSet.Insert( "height", "1" );
372
373   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet );
374
375   underlineMapGet = label.GetProperty<Property::Map>( TextLabel::Property::UNDERLINE );
376   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
377   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
378
379   underlineMapSet.Clear();
380
381   Property::Map underlineDisabledMapGet;
382   underlineDisabledMapGet.Insert( "enable", "false" );
383   underlineDisabledMapGet.Insert( "color", "red" );
384   underlineDisabledMapGet.Insert( "height", "1" );
385
386   label.SetProperty( TextLabel::Property::UNDERLINE, underlineMapSet );
387   underlineMapGet = label.GetProperty<Property::Map>( TextLabel::Property::UNDERLINE );
388   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineDisabledMapGet.Count(), TEST_LOCATION );
389   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineDisabledMapGet ), true, TEST_LOCATION );
390
391   // Check the shadow property
392
393   Property::Map shadowMapSet;
394   Property::Map shadowMapGet;
395
396   shadowMapSet.Insert( "color", "green" );
397   shadowMapSet.Insert( "offset", "2 2" );
398
399   label.SetProperty( TextLabel::Property::SHADOW, shadowMapSet );
400
401   shadowMapGet = label.GetProperty<Property::Map>( TextLabel::Property::SHADOW );
402   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
403   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
404
405   shadowMapSet.Clear();
406   Property::Map shadowDisabledMapGet;
407   shadowDisabledMapGet.Insert( "color", "green" );
408   shadowDisabledMapGet.Insert( "offset", "0 0" );
409
410   label.SetProperty( TextLabel::Property::SHADOW, shadowMapSet );
411
412   shadowMapGet = label.GetProperty<Property::Map>( TextLabel::Property::SHADOW );
413   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowDisabledMapGet.Count(), TEST_LOCATION );
414   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowDisabledMapGet ), true, TEST_LOCATION );
415
416   // Check the emboss property
417   label.SetProperty( TextLabel::Property::EMBOSS, "Emboss properties" );
418   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
419
420   // Check the outline property
421   label.SetProperty( TextLabel::Property::OUTLINE, "Outline properties" );
422   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
423
424   // Check the pixel size of font
425   label.SetProperty( DevelTextLabel::Property::PIXEL_SIZE, 20.f );
426   DALI_TEST_EQUALS( label.GetProperty<float>( DevelTextLabel::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
427
428   // Check the ellipsis property
429   DALI_TEST_CHECK( !label.GetProperty<bool>( DevelTextLabel::Property::ELLIPSIS ) );
430   label.SetProperty( DevelTextLabel::Property::ELLIPSIS, true );
431   DALI_TEST_CHECK( label.GetProperty<bool>( DevelTextLabel::Property::ELLIPSIS ) );
432
433   END_TEST;
434 }
435
436 int UtcDaliToolkitTextlabelAtlasRenderP(void)
437 {
438   ToolkitTestApplication application;
439   tet_infoline(" UtcDaliToolkitTextLabelAtlasRenderP");
440   TextLabel label = TextLabel::New("Test Text");
441   DALI_TEST_CHECK( label );
442
443   // Avoid a crash when core load gl resources.
444   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
445
446   Stage::GetCurrent().Add( label );
447
448   // Turn on all the effects
449   label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
450   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
451   label.SetProperty( TextLabel::Property::UNDERLINE_ENABLED, true );
452   label.SetProperty( TextLabel::Property::UNDERLINE_COLOR, Color::RED );
453   label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
454   label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLUE );
455
456   try
457   {
458     // Render some text with the shared atlas backend
459     label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
460     application.SendNotification();
461     application.Render();
462   }
463   catch( ... )
464   {
465     tet_result(TET_FAIL);
466   }
467
468   try
469   {
470     // Render some text with the shared atlas backend
471     label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_VECTOR_BASED );
472     application.SendNotification();
473     application.Render();
474   }
475   catch( ... )
476   {
477     tet_result(TET_FAIL);
478   }
479   END_TEST;
480 }
481
482 int UtcDaliToolkitTextLabelLanguagesP(void)
483 {
484   ToolkitTestApplication application;
485   tet_infoline(" UtcDaliToolkitTextLabelLanguagesP");
486   TextLabel label = TextLabel::New();
487   DALI_TEST_CHECK( label );
488
489   Stage::GetCurrent().Add( label );
490
491   const std::string scripts( " привет мир, γειά σου Κόσμε, Hello world, مرحبا بالعالم, שלום עולם, "
492                              "բարեւ աշխարհը, მსოფლიოში, 안녕하세요, 你好世界, ひらがな, カタカナ, "
493                              "ওহে বিশ্ব, မင်္ဂလာပါကမ္ဘာလောက, हैलो वर्ल्ड, હેલો વર્લ્ડ, ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ ਦੁਨਿਆ, ಹಲೋ ವರ್ಲ್ಡ್, "
494                              "ഹലോ വേൾഡ്, ଓଡ଼ିଆ, හෙලෝ වර්ල්ඩ්, ஹலோ உலகம், హలో వరల్డ్, "
495                              "ສະບາຍດີໂລກ, สวัสดีโลก, ជំរាបសួរពិភពលោក, "
496                              "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84." ); // these characters on the last line are emojis.
497
498   label.SetProperty( TextLabel::Property::TEXT, scripts );
499   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), scripts, TEST_LOCATION );
500
501   application.SendNotification();
502   application.Render();
503
504   END_TEST;
505 }
506
507 int UtcDaliToolkitTextLabelEmojisP(void)
508 {
509   ToolkitTestApplication application;
510   tet_infoline(" UtcDaliToolkitTextLabelLanguagesP");
511   TextLabel label = TextLabel::New();
512   DALI_TEST_CHECK( label );
513
514   Stage::GetCurrent().Add( label );
515
516   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
517
518   char* pathNamePtr = get_current_dir_name();
519   const std::string pathName( pathNamePtr );
520   free( pathNamePtr );
521
522   TextAbstraction::FontDescription fontDescription;
523   fontDescription.path = pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf";
524   fontDescription.family = "BreezeColorEmoji";
525   fontDescription.width = TextAbstraction::FontWidth::NONE;
526   fontDescription.weight = TextAbstraction::FontWeight::NORMAL;
527   fontDescription.slant = TextAbstraction::FontSlant::NONE;
528
529   fontClient.GetFontId( fontDescription, EMOJI_FONT_SIZE );
530
531   const std::string emojis = "<font family='BreezeColorEmoji' size='60'>\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84</font>";
532   label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
533   label.SetProperty( TextLabel::Property::TEXT, emojis );
534
535   application.SendNotification();
536   application.Render();
537
538   END_TEST;
539 }
540
541 int UtcDaliToolkitTextlabelScrollingP(void)
542 {
543   ToolkitTestApplication application;
544   tet_infoline(" UtcDaliToolkitTextLabelScrollingP");
545   TextLabel label = TextLabel::New("Some text to scroll");
546   DALI_TEST_CHECK( label );
547   // Avoid a crash when core load gl resources.
548   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
549   Stage::GetCurrent().Add( label );
550   // Turn on all the effects
551   label.SetProperty( TextLabel::Property::MULTI_LINE, false );
552   label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, 50.0f );
553   label.SetProperty( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3 );
554   label.SetProperty( TextLabel::Property::AUTO_SCROLL_SPEED, 80.0f );
555
556   try
557   {
558     // Render some text with the shared atlas backend
559     label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true );
560     application.SendNotification();
561     application.Render();
562   }
563   catch( ... )
564   {
565     tet_result(TET_FAIL);
566   }
567
568   END_TEST;
569 }
570
571 int UtcDaliToolkitTextlabelScrollingInterruptedP(void)
572 {
573   ToolkitTestApplication application;
574   tet_infoline(" UtcDaliToolkitTextlabelScrollingInterruptedP");
575   TextLabel label = TextLabel::New("Some text to scroll");
576   DALI_TEST_CHECK( label );
577   // Avoid a crash when core load gl resources.
578   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
579   Stage::GetCurrent().Add( label );
580   label.SetSize( 360.0f, 20.f );
581   // Turn on all the effects
582   label.SetProperty( TextLabel::Property::MULTI_LINE, false );
583   label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, 50.0f );
584   label.SetProperty( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3 );
585   label.SetProperty( TextLabel::Property::AUTO_SCROLL_SPEED, 80.0f );
586
587   // Render the text.
588   application.SendNotification();
589   application.Render();
590
591   unsigned int actorCount1 = label.GetChildCount();
592   tet_printf("Initial actor count is(%d)\n", actorCount1 );
593
594   try
595   {
596     // Render some text with the shared atlas backend
597     label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true );
598     application.SendNotification();
599     application.Render(2000);
600
601     unsigned int actorCount1 = label.GetChildCount();
602     tet_printf("Actor count after scrolling is(%d)\n", actorCount1 );
603
604     label.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED );
605
606     // Render the text.
607     application.SendNotification();
608     application.Render();
609
610     unsigned int actorCount2 = label.GetChildCount();
611     tet_printf("After changing color the actor count is(%d)\n", actorCount2 );
612
613     DALI_TEST_EQUALS( actorCount1, actorCount2, TEST_LOCATION );
614
615   }
616   catch( ... )
617   {
618     tet_result(TET_FAIL);
619   }
620
621   END_TEST;
622 }
623
624 int UtcDaliToolkitTextlabelScrollingN(void)
625 {
626   ToolkitTestApplication application;
627   tet_infoline(" UtcDaliToolkitTextlabelScrollingN");
628
629   TextLabel label = TextLabel::New("Some text to scroll");
630   DALI_TEST_CHECK( label );
631
632   Stage::GetCurrent().Add( label );
633
634   // Avoid a crash when core load gl resources.
635   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
636
637   // The text scrolling works only on single line text.
638   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
639
640   // Turn on all the effects.
641   label.SetProperty( TextLabel::Property::AUTO_SCROLL_GAP, 50.0f );
642   label.SetProperty( TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3 );
643   label.SetProperty( TextLabel::Property::AUTO_SCROLL_SPEED, 80.0f );
644
645   // Enable the auto scrolling effect.
646   label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true );
647
648   // The auto scrolling shouldn't be enabled.
649   const bool enabled = label.GetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL ).Get<bool>();
650   DALI_TEST_CHECK( !enabled );
651
652   END_TEST;
653 }
654
655 int UtcDaliToolkitTextlabelEllipsis(void)
656 {
657   ToolkitTestApplication application;
658   tet_infoline(" UtcDaliToolkitTextlabelEllipsis");
659
660   TextLabel label = TextLabel::New("Hello world");
661   DALI_TEST_CHECK( label );
662
663   // Avoid a crash when core load gl resources.
664   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
665
666   Stage::GetCurrent().Add( label );
667
668   // Turn on all the effects
669   label.SetAnchorPoint( AnchorPoint::CENTER );
670   label.SetParentOrigin( ParentOrigin::CENTER );
671   label.SetSize( 360.0f, 10.f );
672
673   try
674   {
675     // Render the text.
676     application.SendNotification();
677     application.Render();
678   }
679   catch( ... )
680   {
681     tet_result(TET_FAIL);
682   }
683
684   END_TEST;
685 }