Dali 3D User Interface Engine
utc-Dali-TextLabel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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>
22 
23 using namespace Dali;
24 using namespace Toolkit;
25 
27 {
29 }
30 
32 {
34 }
35 
36 namespace
37 {
38 
39 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
40 const char* const PROPERTY_NAME_TEXT = "text";
41 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
42 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
43 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
44 const char* const PROPERTY_NAME_MULTI_LINE = "multiLine";
45 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
46 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
47 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
48 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
49 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
50 const char* const PROPERTY_NAME_UNDERLINE_ENABLED = "underlineEnabled";
51 const char* const PROPERTY_NAME_UNDERLINE_COLOR = "underlineColor";
52 const char* const PROPERTY_NAME_UNDERLINE_HEIGHT = "underlineHeight";
53 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
54 
56 
57 } // namespace
58 
60 {
61  ToolkitTestApplication application;
62  tet_infoline(" UtcDaliToolkitTextLabelConstructorP");
63  TextLabel textLabel;
64  DALI_TEST_CHECK( !textLabel );
65  END_TEST;
66 }
67 
69 {
70  ToolkitTestApplication application;
71  tet_infoline(" UtcDaliToolkitTextLabelNewP");
72  TextLabel textLabel = TextLabel::New( "Test Text" );
73  DALI_TEST_CHECK( textLabel );
74  END_TEST;
75 }
76 
78 {
79  ToolkitTestApplication application;
80  tet_infoline(" UtcDaliToolkitTextLabelDownCastP");
81  TextLabel textLabel1 = TextLabel::New();
82  BaseHandle object( textLabel1 );
83 
84  TextLabel textLabel2 = TextLabel::DownCast( object );
85  DALI_TEST_CHECK( textLabel2 );
86 
87  TextLabel textLabel3 = DownCast< TextLabel >( object );
88  DALI_TEST_CHECK( textLabel3 );
89  END_TEST;
90 }
91 
93 {
94  ToolkitTestApplication application;
95  tet_infoline(" UtcDaliToolkitTextLabelDownCastN");
96  BaseHandle uninitializedObject;
97  TextLabel textLabel1 = TextLabel::DownCast( uninitializedObject );
98  DALI_TEST_CHECK( !textLabel1 );
99 
100  TextLabel textLabel2 = DownCast< TextLabel >( uninitializedObject );
101  DALI_TEST_CHECK( !textLabel2 );
102  END_TEST;
103 }
104 
106 {
107  ToolkitTestApplication application;
108  tet_infoline(" UtcDaliToolkitTextLabelCopyConstructorP");
109  TextLabel textLabel = TextLabel::New();
111 
112  TextLabel copy( textLabel );
113  DALI_TEST_CHECK( copy );
115  END_TEST;
116 }
117 
119 {
120  ToolkitTestApplication application;
121  tet_infoline(" UtcDaliToolkitTextLabelAssingmentOperatorP");
122  TextLabel textLabel = TextLabel::New();
124 
125  TextLabel copy = textLabel;
126  DALI_TEST_CHECK( copy );
128  END_TEST;
129 }
130 
131 // Positive test case for a method
133 {
134  ToolkitTestApplication application;
135  tet_infoline(" UtcDaliToolkitTextLabelGetPropertyP");
136  TextLabel label = TextLabel::New("Test Text");
137  DALI_TEST_CHECK( label );
138 
139  // Check Property Indices are correct
155 
156  END_TEST;
157 }
158 
160 {
161  ToolkitTestApplication application;
162  tet_infoline(" UtcDaliToolkitTextLabelSetPropertyP");
163  TextLabel label = TextLabel::New();
164  DALI_TEST_CHECK( label );
165 
166  // Note - we can't check the defaults since the stylesheets are platform-specific
169 
170  // Check that text can be correctly reset
171  label.SetProperty( TextLabel::Property::TEXT, "Setting Text" );
172  DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
173 
174  // Check font properties.
175  label.SetProperty( TextLabel::Property::FONT_FAMILY, "Setting font family" );
176  DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
177  label.SetProperty( TextLabel::Property::FONT_STYLE, "Setting font style" );
178  DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION );
181 
182  // Toggle multi-line
185 
186  // Check that the Alignment properties can be correctly set
191 
192  // Check that text color can be properly set
195  // The underline color is changed as well.
197 
198  // Check that shadow parameters can be correctly set
203 
204  // Check that underline parameters can be correctly set
211 
212  TextLabel label2 = TextLabel::New( "New text" );
213  DALI_TEST_CHECK( label2 );
214  DALI_TEST_EQUALS( label2.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("New text"), TEST_LOCATION );
215 
216  // Check the enable markup property.
220 
221  END_TEST;
222 }
223 
225 {
226  ToolkitTestApplication application;
227  tet_infoline(" UtcDaliToolkitTextLabelAtlasRenderP");
228  TextLabel label = TextLabel::New("Test Text");
229  DALI_TEST_CHECK( label );
230 
231  // Avoid a crash when core load gl resources.
233 
234  Stage::GetCurrent().Add( label );
235 
236  // Turn on all the effects
243 
244  try
245  {
246  // Render some text with the shared atlas backend
248  application.SendNotification();
249  application.Render();
250  }
251  catch( ... )
252  {
254  }
255 
256  END_TEST;
257 }
258 
260 {
261  ToolkitTestApplication application;
262  tet_infoline(" UtcDaliToolkitTextLabelLanguagesP");
263  TextLabel label = TextLabel::New();
264  DALI_TEST_CHECK( label );
265 
266  Stage::GetCurrent().Add( label );
267 
268  const std::string scripts( " привет мир, γειά σου Κόσμε, Hello world, مرحبا بالعالم, שלום עולם, "
269  "բարեւ աշխարհը, მსოფლიოში, 안녕하세요, 你好世界, ひらがな, カタカナ, "
270  "ওহে বিশ্ব, မင်္ဂလာပါကမ္ဘာလောက, हैलो वर्ल्ड, હેલો વર્લ્ડ, ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ ਦੁਨਿਆ, ಹಲೋ ವರ್ಲ್ಡ್, "
271  "ഹലോ വേൾഡ്, ଓଡ଼ିଆ, හෙලෝ වර්ල්ඩ්, ஹலோ உலகம், హలో వరల్డ్, "
272  "ສະບາຍດີໂລກ, สวัสดีโลก, ជំរាបសួរពិភពលោក, "
273  "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84." ); // these characters on the last line are emojis.
274 
275  label.SetProperty( TextLabel::Property::TEXT, scripts );
276  DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), scripts, TEST_LOCATION );
277 
278  application.SendNotification();
279  application.Render();
280 
281  END_TEST;
282 }
Dali Docs Home
Read more about Dali