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