2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_text_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_text_cleanup(void)
33 test_return_value = TET_PASS;
36 int UtcDaliTextConstructor(void)
38 TestApplication application;
42 DALI_TEST_CHECK( text.IsEmpty() );
44 Text someEmptyText1( "" );
46 DALI_TEST_CHECK( someEmptyText1.IsEmpty() );
48 Text someEmptyText2( std::string( "" ) );
50 DALI_TEST_CHECK( someEmptyText2.IsEmpty() );
52 Text someEmptyText3( text );
54 DALI_TEST_CHECK( someEmptyText3.IsEmpty() );
56 Text someText1( "Some text" );
58 DALI_TEST_CHECK( !someText1.IsEmpty() );
60 Text someText2( std::string( "Some text" ) );
62 DALI_TEST_CHECK( !someText2.IsEmpty() );
64 Text someText3( Text( std::string( "Some text" ) ) );
66 DALI_TEST_CHECK( !someText3.IsEmpty() );
68 Character c = someText1[0];
72 DALI_TEST_CHECK( !cText.IsEmpty() );
76 int UtcDaliTextCopyConstructor(void)
78 TestApplication application;
80 Text someText1( std::string( "Some text1" ) );
81 Text someText2( std::string( "Some text2" ) );
83 Text someText3( someText1 );
84 Text someText4 = someText2;
86 DALI_TEST_CHECK( (someText1.GetText()==someText3.GetText()) && (someText2.GetText()==someText4.GetText()) );
90 int UtcDaliTextAssignmentOperator(void)
92 TestApplication application;
94 // check for assignment when current is NULL
96 Text someText1( std::string( "Some text1" ) );
98 someText2 = someText1;
100 DALI_TEST_CHECK( (someText1.GetText()==someText2.GetText()) );
102 // check for assignment when current object already has text
103 Text someText3( std::string( "Some text3" ) );
104 someText2 = someText3;
105 DALI_TEST_CHECK( (someText3.GetText()==someText2.GetText()) );
109 // check for assignment of empty text
110 someText2 = someText4;
111 DALI_TEST_CHECK( someText2.IsEmpty() );
113 // check for self assignment
114 someText3 = someText3;
115 DALI_TEST_CHECK( ! someText3.IsEmpty() );
121 int UtcDaliTextSetGetText(void)
123 TestApplication application;
125 const char* someText = "Some text";
126 const std::string someText2( "Some text2" );
129 text.SetText( someText );
131 DALI_TEST_EQUALS( someText, text.GetText(), TEST_LOCATION );
133 text.SetText( someText2 );
135 DALI_TEST_EQUALS( someText2, text.GetText(), TEST_LOCATION );
137 Character c = text[0];
140 DALI_TEST_EQUALS( std::string( "S" ), text.GetText(), TEST_LOCATION );
143 text2.SetText( text );
145 DALI_TEST_EQUALS( text2.GetText(), text.GetText(), TEST_LOCATION );
150 int UtcDaliTextAccessOperator01(void)
152 TestApplication application;
154 std::string someText;
157 text.SetText( someText );
159 bool assert1 = false;
160 bool assert2 = false;
163 Character c = text[0];
165 catch( DaliException& e )
167 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
168 DALI_TEST_EQUALS( e.mCondition, "NULL != mImpl && \"Text::operator[]: Text is uninitialized\"", TEST_LOCATION );
173 someText = std::string( "some text" );
174 text.SetText( someText );
178 Character c = text[100];
180 catch( DaliException& e )
182 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
183 DALI_TEST_EQUALS( e.mCondition, "position < mString.Count() && \"Text::operator[]: Character position is out of bounds\"", TEST_LOCATION );
188 if( assert1 && assert2 )
190 tet_result( TET_PASS );
194 tet_result( TET_FAIL );
199 int UtcDaliTextAccessOperator02(void)
201 TestApplication application;
203 const std::string someText( "Some text");
206 text.SetText( someText );
208 DALI_TEST_CHECK( someText == text.GetText() );
210 Character c = text[0];
213 DALI_TEST_CHECK( std::string("S") == text.GetText() );
217 int UtcDaliTextIsEmpty(void)
219 TestApplication application;
223 DALI_TEST_CHECK( text.IsEmpty() );
225 text.SetText( std::string( "Some text") );
227 DALI_TEST_CHECK( !text.IsEmpty() );
231 int UtcDaliTextGetLength(void)
233 TestApplication application;
235 const std::string someText( "Some text");
237 Text text( someText );
239 DALI_TEST_CHECK( someText.size() == text.GetLength() );
243 int UtcDaliTextAppend(void)
245 TestApplication application;
247 Text text( std::string( "Some text") );
251 DALI_TEST_CHECK( std::string( "Some textA" ) == text.GetText() );
253 text.Append( std::string( "B" ) );
255 DALI_TEST_CHECK( std::string( "Some textAB" ) == text.GetText() );
257 Character c = text[0];
260 DALI_TEST_CHECK( std::string( "Some textABS" ) == text.GetText() );
262 Text text2( std::string("C") );
263 text.Append( text2 );
265 DALI_TEST_CHECK( std::string( "Some textABSC" ) == text.GetText() );
267 // append to a null text
270 emptyText.Append( text2 );
271 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
273 // append a null text
276 emptyText.Append( emptyText2 );
277 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
282 int UtcDaliTextRemove01(void)
284 TestApplication application;
286 Text text( std::string( "Some text") );
288 bool assert1 = false;
289 bool assert2 = false;
290 bool assert3 = false;
294 text.Remove( 100, 3 );
296 catch( DaliException& e )
298 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
299 DALI_TEST_EQUALS( e.mCondition, "position < mString.Count() && \"Text::Remove: Character position is out of bounds\"", TEST_LOCATION );
305 text.Remove( 1, 300 );
307 catch( DaliException& e )
309 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
310 DALI_TEST_EQUALS( e.mCondition, "position + numberOfCharacters <= mString.Count() && \"Text::Remove: Character position + numberOfCharacters is out of bounds\"", TEST_LOCATION );
316 text.SetText( std::string( "" ) );
317 text.Remove( 1, 300 );
319 catch( DaliException& e )
321 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
322 DALI_TEST_EQUALS( e.mCondition, "NULL != mImpl && \"Text::Remove: Text is uninitialized\"", TEST_LOCATION );
326 if( assert1 && assert2 && assert3 )
328 tet_result( TET_PASS );
332 tet_result( TET_FAIL );
337 int UtcDaliTextRemove02(void)
339 TestApplication application;
341 Text text01( std::string( "Some text") );
342 Text text02( std::string( "Somext") );
343 Text text03( std::string( "" ) );
344 Text text04( std::string( "Hello world" ) );
345 Text text05( std::string( "world" ) );
347 text01.Remove( 3u, 3u );
349 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
350 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
352 text01.Remove( 0u, 0u );
354 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
355 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
357 text01.Remove( 0u, 6u );
359 DALI_TEST_EQUALS( text01.GetLength(), text03.GetLength(), TEST_LOCATION );
360 DALI_TEST_EQUALS( text01.GetText(), text03.GetText(), TEST_LOCATION );
362 text04.Remove( 0u, 6u );
364 DALI_TEST_EQUALS( text04.GetLength(), text05.GetLength(), TEST_LOCATION );
365 DALI_TEST_EQUALS( text04.GetText(), text05.GetText(), TEST_LOCATION );
370 int UtcDaliTextFind(void)
372 TestApplication application;
375 Character c1 = Text( std::string( "c" ) )[0u];
376 Character c2 = Text( std::string( "o" ) )[0u];
377 Vector<std::size_t> positions;
379 // Find in void text.
382 text.Find( c1, 0u, 0u, positions );
383 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
386 text.Find( Text::WHITE_SPACE, 0u, 0u, positions );
387 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
390 text.Find( Text::NEW_LINE, 0u, 0u, positions );
391 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
396 text.SetText( std::string( "Hello world" ) );
399 text.Find( c1, 0u, 11u, positions );
400 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
403 text.Find( c2, 0u, 11u, positions );
404 DALI_TEST_EQUALS( positions.Count(), 2u, TEST_LOCATION );
405 DALI_TEST_EQUALS( positions[0u], 4u, TEST_LOCATION );
406 DALI_TEST_EQUALS( positions[1u], 7u, TEST_LOCATION );
409 text.SetText( std::string( " Hello world \n" ) );
412 text.Find( Text::WHITE_SPACE, 0u, 17u, positions );
413 DALI_TEST_EQUALS( positions.Count(), 8u, TEST_LOCATION );
414 DALI_TEST_EQUALS( positions[0u], 0u, TEST_LOCATION );
415 DALI_TEST_EQUALS( positions[1u], 1u, TEST_LOCATION );
416 DALI_TEST_EQUALS( positions[2u], 2u, TEST_LOCATION );
417 DALI_TEST_EQUALS( positions[3u], 8u, TEST_LOCATION );
418 DALI_TEST_EQUALS( positions[4u], 9u, TEST_LOCATION );
419 DALI_TEST_EQUALS( positions[5u], 15u, TEST_LOCATION );
420 DALI_TEST_EQUALS( positions[6u], 16u, TEST_LOCATION );
421 DALI_TEST_EQUALS( positions[7u], 17u, TEST_LOCATION );
423 // Find new line character
424 text.SetText( std::string( "\n\nHello\nworld\n\n" ) );
427 text.Find( Text::NEW_LINE, 0u, 14u, positions );
428 DALI_TEST_EQUALS( positions.Count(), 5u, TEST_LOCATION );
429 DALI_TEST_EQUALS( positions[0u], 0u, TEST_LOCATION );
430 DALI_TEST_EQUALS( positions[1u], 1u, TEST_LOCATION );
431 DALI_TEST_EQUALS( positions[2u], 7u, TEST_LOCATION );
432 DALI_TEST_EQUALS( positions[3u], 13u, TEST_LOCATION );
433 DALI_TEST_EQUALS( positions[4u], 14u, TEST_LOCATION );
438 int UtcDaliTextGetSubText(void)
440 TestApplication application;
445 // Get sub-text from a void text.
447 subText.SetText( "Hello" );
448 text.GetSubText( 0u, 1u, subText );
449 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
453 text.SetText( std::string( "Hello world" ) );
455 // Access out of bounds
456 subText.SetText( "Hello" );
457 text.GetSubText( 30u, 31u, subText );
458 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
459 text.GetSubText( 0u, 31u, subText );
460 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
461 text.GetSubText( 30u, 1u, subText );
462 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
464 // Check it swaps the indices.
465 text.GetSubText( 8u, 2u, subText );
466 DALI_TEST_EQUALS( subText.GetText(), std::string( "row oll" ), TEST_LOCATION );
469 subText.SetText( std::string( "" ) );
470 text.GetSubText( 4u, 6u, subText );
471 DALI_TEST_EQUALS( subText.GetText(), std::string( "o w" ), TEST_LOCATION );
476 int UtcDaliTextIsWhiteSpaceNewLine(void)
478 TestApplication application;
482 // Query a void text.
484 DALI_TEST_CHECK( !text.IsWhiteSpace( 0u ) );
485 DALI_TEST_CHECK( !text.IsNewLine( 0u ) );
488 text.SetText( "Hello world\n" );
490 // Query out of bounds
492 DALI_TEST_CHECK( !text.IsWhiteSpace( 30u ) );
493 DALI_TEST_CHECK( !text.IsNewLine( 30u ) );
497 DALI_TEST_CHECK( !text.IsWhiteSpace( 1u ) );
498 DALI_TEST_CHECK( !text.IsNewLine( 1u ) );
499 DALI_TEST_CHECK( text.IsWhiteSpace( 5u ) );
500 DALI_TEST_CHECK( text.IsNewLine( 11u ) );