Merge "(LightActor) Fixed it reporting an incorrect type for one of its properties...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Text.cpp
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
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 void utc_dali_text_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_text_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 int UtcDaliTextConstructor(void)
37 {
38   TestApplication application;
39
40   Text text;
41
42   DALI_TEST_CHECK( text.IsEmpty() );
43
44   Text someText( std::string( "Some text" ) );
45
46   DALI_TEST_CHECK( !someText.IsEmpty() );
47
48   Character c = someText[0];
49
50   Text cText( c );
51
52   DALI_TEST_CHECK( !cText.IsEmpty() );
53   END_TEST;
54 }
55
56 int UtcDaliTextCopyConstructor(void)
57 {
58   TestApplication application;
59
60   Text someText1( std::string( "Some text1" ) );
61   Text someText2( std::string( "Some text2" ) );
62
63   Text someText3( someText1 );
64   Text someText4 = someText2;
65
66   DALI_TEST_CHECK( (someText1.GetText()==someText3.GetText()) && (someText2.GetText()==someText4.GetText()) );
67   END_TEST;
68 }
69
70 int UtcDaliTextAssignmentOperator(void)
71 {
72   TestApplication application;
73
74   // check for assignment when current is NULL
75
76   Text someText1( std::string( "Some text1" ) );
77   Text someText2;
78   someText2 = someText1;
79
80   DALI_TEST_CHECK( (someText1.GetText()==someText2.GetText()) );
81
82   // check for assignment when current object already has text
83   Text someText3( std::string( "Some text3" ) );
84   someText2 = someText3;
85   DALI_TEST_CHECK( (someText3.GetText()==someText2.GetText()) );
86
87   Text someText4;
88
89   printf(" is text empty ? ...... %d \n", someText4.IsEmpty());
90   // check for assignment of empty text
91   someText2 = someText4;
92   DALI_TEST_CHECK( someText2.IsEmpty() );
93
94   // check for self assignment
95   someText3 = someText3;
96   DALI_TEST_CHECK( ! someText3.IsEmpty() );
97
98
99   END_TEST;
100 }
101
102 int UtcDaliTextSetGetText(void)
103 {
104   TestApplication application;
105
106   const std::string someText( "Some text");
107
108   Text text;
109   text.SetText( someText );
110
111   DALI_TEST_CHECK( someText == text.GetText() );
112
113   Character c = text[0];
114   text.SetText( c );
115
116   DALI_TEST_CHECK( std::string("S") == text.GetText() );
117
118   Text text2;
119   text2.SetText( text );
120
121   DALI_TEST_CHECK( text2.GetText() == text.GetText() );
122   END_TEST;
123 }
124
125 int UtcDaliTextAccessOperator01(void)
126 {
127   TestApplication application;
128
129   std::string someText;
130
131   Text text;
132   text.SetText( someText );
133
134   bool assert1 = false;
135   bool assert2 = false;
136   try
137   {
138     Character c = text[0];
139   }
140   catch( DaliException& e )
141   {
142     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
143     DALI_TEST_EQUALS( e.mCondition, "NULL != mImpl && \"Text::operator[]: Text is uninitialized\"", TEST_LOCATION );
144
145     assert1 = true;
146   }
147
148   someText = std::string( "some text" );
149   text.SetText( someText );
150
151   try
152   {
153     Character c = text[100];
154   }
155   catch( DaliException& e )
156   {
157     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
158     DALI_TEST_EQUALS( e.mCondition, "position < mString.size() && \"Text::operator[]: Character position is out of bounds\"", TEST_LOCATION );
159
160     assert2 = true;
161   }
162
163   if( assert1 && assert2 )
164   {
165     tet_result( TET_PASS );
166   }
167   else
168   {
169     tet_result( TET_FAIL );
170   }
171   END_TEST;
172 }
173
174 int UtcDaliTextAccessOperator02(void)
175 {
176   TestApplication application;
177
178   const std::string someText( "Some text");
179
180   Text text;
181   text.SetText( someText );
182
183   DALI_TEST_CHECK( someText == text.GetText() );
184
185   Character c = text[0];
186   text.SetText( c );
187
188   DALI_TEST_CHECK( std::string("S") == text.GetText() );
189   END_TEST;
190 }
191
192 int UtcDaliTextIsEmpty(void)
193 {
194   TestApplication application;
195
196   Text text;
197
198   DALI_TEST_CHECK( text.IsEmpty() );
199
200   text.SetText( std::string( "Some text") );
201
202   DALI_TEST_CHECK( !text.IsEmpty() );
203   END_TEST;
204 }
205
206 int UtcDaliTextGetLength(void)
207 {
208   TestApplication application;
209
210   const std::string someText( "Some text");
211
212   Text text( someText );
213
214   DALI_TEST_CHECK( someText.size() == text.GetLength() );
215   END_TEST;
216 }
217
218 int UtcDaliTextAppend(void)
219 {
220   TestApplication application;
221
222   Text text( std::string( "Some text") );
223
224   text.Append( std::string( "A" ) );
225
226   DALI_TEST_CHECK( std::string( "Some textA" ) == text.GetText() );
227
228   Character c = text[0];
229   text.Append( c );
230
231   DALI_TEST_CHECK( std::string( "Some textAS" ) == text.GetText() );
232
233   Text text2( std::string("B") );
234   text.Append( text2 );
235
236   DALI_TEST_CHECK( std::string( "Some textASB" ) == text.GetText() );
237
238   // append to a null text
239
240   Text emptyText;
241   emptyText.Append( text2 );
242   DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
243
244   END_TEST;
245 }
246
247 int UtcDaliTextRemove01(void)
248 {
249   TestApplication application;
250
251   Text text( std::string( "Some text") );
252
253   bool assert1 = false;
254   bool assert2 = false;
255   try
256   {
257     text.Remove( 100, 3 );
258   }
259   catch( DaliException& e )
260   {
261     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
262     DALI_TEST_EQUALS( e.mCondition, "position < mString.size() && \"Text::Remove: Character position is out of bounds\"", TEST_LOCATION );
263     assert1 = true;
264   }
265
266   try
267   {
268     text.Remove( 1, 300 );
269   }
270   catch( DaliException& e )
271   {
272     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
273     DALI_TEST_EQUALS( e.mCondition, "position + numberOfCharacters <= mString.size() && \"Text::Remove: Character position + numberOfCharacters is out of bounds\"", TEST_LOCATION );
274     assert2 = true;
275   }
276
277   if( assert1 && assert2 )
278   {
279     tet_result( TET_PASS );
280   }
281   else
282   {
283     tet_result( TET_FAIL );
284   }
285   END_TEST;
286 }
287
288 int UtcDaliTextRemove02(void)
289 {
290   TestApplication application;
291
292   Text text01( std::string( "Some text") );
293   Text text02( std::string( "Somext") );
294   Text text03( std::string( "") );
295
296   text01.Remove( 3, 3 );
297
298   DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
299   DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
300
301   text01.Remove( 0, 6 );
302
303   DALI_TEST_EQUALS( text01.GetLength(), text03.GetLength(), TEST_LOCATION );
304   DALI_TEST_EQUALS( text01.GetText(), text03.GetText(), TEST_LOCATION );
305   END_TEST;
306 }