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 Character c = someText[0];
52 DALI_TEST_CHECK( !cText.IsEmpty() );
56 int UtcDaliTextCopyConstructor(void)
58 TestApplication application;
60 Text someText1( std::string( "Some text1" ) );
61 Text someText2( std::string( "Some text2" ) );
63 Text someText3( someText1 );
64 Text someText4 = someText2;
66 DALI_TEST_CHECK( (someText1.GetText()==someText3.GetText()) && (someText2.GetText()==someText4.GetText()) );
70 int UtcDaliTextAssignmentOperator(void)
72 TestApplication application;
74 // check for assignment when current is NULL
76 Text someText1( std::string( "Some text1" ) );
78 someText2 = someText1;
80 DALI_TEST_CHECK( (someText1.GetText()==someText2.GetText()) );
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()) );
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() );
94 // check for self assignment
95 someText3 = someText3;
96 DALI_TEST_CHECK( ! someText3.IsEmpty() );
102 int UtcDaliTextSetGetText(void)
104 TestApplication application;
106 const std::string someText( "Some text");
109 text.SetText( someText );
111 DALI_TEST_CHECK( someText == text.GetText() );
113 Character c = text[0];
116 DALI_TEST_CHECK( std::string("S") == text.GetText() );
119 text2.SetText( text );
121 DALI_TEST_CHECK( text2.GetText() == text.GetText() );
125 int UtcDaliTextAccessOperator01(void)
127 TestApplication application;
129 std::string someText;
132 text.SetText( someText );
134 bool assert1 = false;
135 bool assert2 = false;
138 Character c = text[0];
140 catch( DaliException& e )
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 );
148 someText = std::string( "some text" );
149 text.SetText( someText );
153 Character c = text[100];
155 catch( DaliException& e )
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 );
163 if( assert1 && assert2 )
165 tet_result( TET_PASS );
169 tet_result( TET_FAIL );
174 int UtcDaliTextAccessOperator02(void)
176 TestApplication application;
178 const std::string someText( "Some text");
181 text.SetText( someText );
183 DALI_TEST_CHECK( someText == text.GetText() );
185 Character c = text[0];
188 DALI_TEST_CHECK( std::string("S") == text.GetText() );
192 int UtcDaliTextIsEmpty(void)
194 TestApplication application;
198 DALI_TEST_CHECK( text.IsEmpty() );
200 text.SetText( std::string( "Some text") );
202 DALI_TEST_CHECK( !text.IsEmpty() );
206 int UtcDaliTextGetLength(void)
208 TestApplication application;
210 const std::string someText( "Some text");
212 Text text( someText );
214 DALI_TEST_CHECK( someText.size() == text.GetLength() );
218 int UtcDaliTextAppend(void)
220 TestApplication application;
222 Text text( std::string( "Some text") );
224 text.Append( std::string( "A" ) );
226 DALI_TEST_CHECK( std::string( "Some textA" ) == text.GetText() );
228 Character c = text[0];
231 DALI_TEST_CHECK( std::string( "Some textAS" ) == text.GetText() );
233 Text text2( std::string("B") );
234 text.Append( text2 );
236 DALI_TEST_CHECK( std::string( "Some textASB" ) == text.GetText() );
238 // append to a null text
241 emptyText.Append( text2 );
242 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
247 int UtcDaliTextRemove01(void)
249 TestApplication application;
251 Text text( std::string( "Some text") );
253 bool assert1 = false;
254 bool assert2 = false;
257 text.Remove( 100, 3 );
259 catch( DaliException& e )
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 );
268 text.Remove( 1, 300 );
270 catch( DaliException& e )
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 );
277 if( assert1 && assert2 )
279 tet_result( TET_PASS );
283 tet_result( TET_FAIL );
288 int UtcDaliTextRemove02(void)
290 TestApplication application;
292 Text text01( std::string( "Some text") );
293 Text text02( std::string( "Somext") );
294 Text text03( std::string( "") );
296 text01.Remove( 3, 3 );
298 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
299 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
301 text01.Remove( 0, 6 );
303 DALI_TEST_EQUALS( text01.GetLength(), text03.GetLength(), TEST_LOCATION );
304 DALI_TEST_EQUALS( text01.GetText(), text03.GetText(), TEST_LOCATION );