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 someText( std::string( "Some text" ) );
46 DALI_TEST_CHECK( !someText.IsEmpty() );
48 Text someEmptyText( std::string( "" ) );
50 DALI_TEST_CHECK( someEmptyText.IsEmpty() );
52 Text someText2( Text( std::string( "Some text" ) ) );
54 DALI_TEST_CHECK( !someText2.IsEmpty() );
56 Text someEmptyText2( text );
58 DALI_TEST_CHECK( someEmptyText2.IsEmpty() );
60 Character c = someText[0];
64 DALI_TEST_CHECK( !cText.IsEmpty() );
68 int UtcDaliTextCopyConstructor(void)
70 TestApplication application;
72 Text someText1( std::string( "Some text1" ) );
73 Text someText2( std::string( "Some text2" ) );
75 Text someText3( someText1 );
76 Text someText4 = someText2;
78 DALI_TEST_CHECK( (someText1.GetText()==someText3.GetText()) && (someText2.GetText()==someText4.GetText()) );
82 int UtcDaliTextAssignmentOperator(void)
84 TestApplication application;
86 // check for assignment when current is NULL
88 Text someText1( std::string( "Some text1" ) );
90 someText2 = someText1;
92 DALI_TEST_CHECK( (someText1.GetText()==someText2.GetText()) );
94 // check for assignment when current object already has text
95 Text someText3( std::string( "Some text3" ) );
96 someText2 = someText3;
97 DALI_TEST_CHECK( (someText3.GetText()==someText2.GetText()) );
101 // check for assignment of empty text
102 someText2 = someText4;
103 DALI_TEST_CHECK( someText2.IsEmpty() );
105 // check for self assignment
106 someText3 = someText3;
107 DALI_TEST_CHECK( ! someText3.IsEmpty() );
113 int UtcDaliTextSetGetText(void)
115 TestApplication application;
117 const std::string someText( "Some text" );
118 const std::string someText2( "Some text2" );
121 text.SetText( someText );
123 DALI_TEST_EQUALS( someText, text.GetText(), TEST_LOCATION );
125 text.SetText( someText2 );
127 DALI_TEST_EQUALS( someText2, text.GetText(), TEST_LOCATION );
129 Character c = text[0];
132 DALI_TEST_EQUALS( std::string( "S" ), text.GetText(), TEST_LOCATION );
135 text2.SetText( text );
137 DALI_TEST_EQUALS( text2.GetText(), text.GetText(), TEST_LOCATION );
142 int UtcDaliTextAccessOperator01(void)
144 TestApplication application;
146 std::string someText;
149 text.SetText( someText );
151 bool assert1 = false;
152 bool assert2 = false;
155 Character c = text[0];
157 catch( DaliException& e )
159 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
160 DALI_TEST_EQUALS( e.mCondition, "NULL != mImpl && \"Text::operator[]: Text is uninitialized\"", TEST_LOCATION );
165 someText = std::string( "some text" );
166 text.SetText( someText );
170 Character c = text[100];
172 catch( DaliException& e )
174 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
175 DALI_TEST_EQUALS( e.mCondition, "position < mString.size() && \"Text::operator[]: Character position is out of bounds\"", TEST_LOCATION );
180 if( assert1 && assert2 )
182 tet_result( TET_PASS );
186 tet_result( TET_FAIL );
191 int UtcDaliTextAccessOperator02(void)
193 TestApplication application;
195 const std::string someText( "Some text");
198 text.SetText( someText );
200 DALI_TEST_CHECK( someText == text.GetText() );
202 Character c = text[0];
205 DALI_TEST_CHECK( std::string("S") == text.GetText() );
209 int UtcDaliTextIsEmpty(void)
211 TestApplication application;
215 DALI_TEST_CHECK( text.IsEmpty() );
217 text.SetText( std::string( "Some text") );
219 DALI_TEST_CHECK( !text.IsEmpty() );
223 int UtcDaliTextGetLength(void)
225 TestApplication application;
227 const std::string someText( "Some text");
229 Text text( someText );
231 DALI_TEST_CHECK( someText.size() == text.GetLength() );
235 int UtcDaliTextAppend(void)
237 TestApplication application;
239 Text text( std::string( "Some text") );
241 text.Append( std::string( "A" ) );
243 DALI_TEST_CHECK( std::string( "Some textA" ) == text.GetText() );
245 Character c = text[0];
248 DALI_TEST_CHECK( std::string( "Some textAS" ) == text.GetText() );
250 Text text2( std::string("B") );
251 text.Append( text2 );
253 DALI_TEST_CHECK( std::string( "Some textASB" ) == text.GetText() );
255 // append to a null text
258 emptyText.Append( text2 );
259 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
261 // append a null text
264 emptyText.Append( emptyText2 );
265 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
270 int UtcDaliTextRemove01(void)
272 TestApplication application;
274 Text text( std::string( "Some text") );
276 bool assert1 = false;
277 bool assert2 = false;
278 bool assert3 = false;
282 text.Remove( 100, 3 );
284 catch( DaliException& e )
286 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
287 DALI_TEST_EQUALS( e.mCondition, "position < mString.size() && \"Text::Remove: Character position is out of bounds\"", TEST_LOCATION );
293 text.Remove( 1, 300 );
295 catch( DaliException& e )
297 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
298 DALI_TEST_EQUALS( e.mCondition, "position + numberOfCharacters <= mString.size() && \"Text::Remove: Character position + numberOfCharacters is out of bounds\"", TEST_LOCATION );
304 text.SetText( std::string( "" ) );
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, "NULL != mImpl && \"Text::Remove: Text is uninitialized\"", TEST_LOCATION );
314 if( assert1 && assert2 && assert3 )
316 tet_result( TET_PASS );
320 tet_result( TET_FAIL );
325 int UtcDaliTextRemove02(void)
327 TestApplication application;
329 Text text01( std::string( "Some text") );
330 Text text02( std::string( "Somext") );
331 Text text03( std::string( "" ) );
332 Text text04( std::string( "Hello world" ) );
333 Text text05( std::string( "world" ) );
335 text01.Remove( 3u, 3u );
337 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
338 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
340 text01.Remove( 0u, 0u );
342 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
343 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
345 text01.Remove( 0u, 6u );
347 DALI_TEST_EQUALS( text01.GetLength(), text03.GetLength(), TEST_LOCATION );
348 DALI_TEST_EQUALS( text01.GetText(), text03.GetText(), TEST_LOCATION );
350 text04.Remove( 0u, 6u );
352 DALI_TEST_EQUALS( text04.GetLength(), text05.GetLength(), TEST_LOCATION );
353 DALI_TEST_EQUALS( text04.GetText(), text05.GetText(), TEST_LOCATION );
358 int UtcDaliTextFind(void)
360 TestApplication application;
363 Character c1 = Text( std::string( "c" ) )[0u];
364 Character c2 = Text( std::string( "o" ) )[0u];
365 Vector<std::size_t> positions;
367 // Find in void text.
370 text.Find( c1, 0u, 0u, positions );
371 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
374 text.Find( Text::WHITE_SPACE, 0u, 0u, positions );
375 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
378 text.Find( Text::NEW_LINE, 0u, 0u, positions );
379 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
384 text.SetText( std::string( "Hello world" ) );
387 text.Find( c1, 0u, 11u, positions );
388 DALI_TEST_EQUALS( positions.Count(), 0u, TEST_LOCATION );
391 text.Find( c2, 0u, 11u, positions );
392 DALI_TEST_EQUALS( positions.Count(), 2u, TEST_LOCATION );
393 DALI_TEST_EQUALS( positions[0u], 4u, TEST_LOCATION );
394 DALI_TEST_EQUALS( positions[1u], 7u, TEST_LOCATION );
397 text.SetText( std::string( " Hello world \n" ) );
400 text.Find( Text::WHITE_SPACE, 0u, 17u, positions );
401 DALI_TEST_EQUALS( positions.Count(), 8u, TEST_LOCATION );
402 DALI_TEST_EQUALS( positions[0u], 0u, TEST_LOCATION );
403 DALI_TEST_EQUALS( positions[1u], 1u, TEST_LOCATION );
404 DALI_TEST_EQUALS( positions[2u], 2u, TEST_LOCATION );
405 DALI_TEST_EQUALS( positions[3u], 8u, TEST_LOCATION );
406 DALI_TEST_EQUALS( positions[4u], 9u, TEST_LOCATION );
407 DALI_TEST_EQUALS( positions[5u], 15u, TEST_LOCATION );
408 DALI_TEST_EQUALS( positions[6u], 16u, TEST_LOCATION );
409 DALI_TEST_EQUALS( positions[7u], 17u, TEST_LOCATION );
411 // Find new line character
412 text.SetText( std::string( "\n\nHello\nworld\n\n" ) );
415 text.Find( Text::NEW_LINE, 0u, 14u, positions );
416 DALI_TEST_EQUALS( positions.Count(), 5u, TEST_LOCATION );
417 DALI_TEST_EQUALS( positions[0u], 0u, TEST_LOCATION );
418 DALI_TEST_EQUALS( positions[1u], 1u, TEST_LOCATION );
419 DALI_TEST_EQUALS( positions[2u], 7u, TEST_LOCATION );
420 DALI_TEST_EQUALS( positions[3u], 13u, TEST_LOCATION );
421 DALI_TEST_EQUALS( positions[4u], 14u, TEST_LOCATION );
426 int UtcDaliTextGetSubText(void)
428 TestApplication application;
433 // Get sub-text from a void text.
435 subText.SetText( "Hello" );
436 text.GetSubText( 0u, 1u, subText );
437 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
441 text.SetText( std::string( "Hello world" ) );
443 // Access out of bounds
444 subText.SetText( "Hello" );
445 text.GetSubText( 30u, 31u, subText );
446 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
447 text.GetSubText( 0u, 31u, subText );
448 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
449 text.GetSubText( 30u, 1u, subText );
450 DALI_TEST_EQUALS( subText.GetText(), std::string( "Hello" ), TEST_LOCATION );
452 // Check it swaps the indices.
453 text.GetSubText( 8u, 2u, subText );
454 DALI_TEST_EQUALS( subText.GetText(), std::string( "row oll" ), TEST_LOCATION );
457 subText.SetText( std::string( "" ) );
458 text.GetSubText( 4u, 6u, subText );
459 DALI_TEST_EQUALS( subText.GetText(), std::string( "o w" ), TEST_LOCATION );
464 int UtcDaliTextIsWhiteSpaceNewLine(void)
466 TestApplication application;
470 // Query a void text.
472 DALI_TEST_CHECK( !text.IsWhiteSpace( 0u ) );
473 DALI_TEST_CHECK( !text.IsNewLine( 0u ) );
476 text.SetText( "Hello world\n" );
478 // Query out of bounds
480 DALI_TEST_CHECK( !text.IsWhiteSpace( 30u ) );
481 DALI_TEST_CHECK( !text.IsNewLine( 30u ) );
485 DALI_TEST_CHECK( !text.IsWhiteSpace( 1u ) );
486 DALI_TEST_CHECK( !text.IsNewLine( 1u ) );
487 DALI_TEST_CHECK( text.IsWhiteSpace( 5u ) );
488 DALI_TEST_CHECK( text.IsNewLine( 11u ) );