2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
25 void utc_dali_text_startup(void)
27 test_return_value = TET_UNDEF;
30 void utc_dali_text_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliTextConstructor(void)
37 TestApplication application;
41 DALI_TEST_CHECK( text.IsEmpty() );
43 Text someText( std::string( "Some text" ) );
45 DALI_TEST_CHECK( !someText.IsEmpty() );
47 Character c = someText[0];
51 DALI_TEST_CHECK( !cText.IsEmpty() );
55 int UtcDaliTextCopyConstructor(void)
57 TestApplication application;
59 Text someText1( std::string( "Some text1" ) );
60 Text someText2( std::string( "Some text2" ) );
62 Text someText3( someText1 );
63 Text someText4 = someText2;
65 DALI_TEST_CHECK( (someText1.GetText()==someText3.GetText()) && (someText2.GetText()==someText4.GetText()) );
69 int UtcDaliTextAssignmentOperator(void)
71 TestApplication application;
73 // check for assignment when current is NULL
75 Text someText1( std::string( "Some text1" ) );
77 someText2 = someText1;
79 DALI_TEST_CHECK( (someText1.GetText()==someText2.GetText()) );
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()) );
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() );
93 // check for self assignment
94 someText3 = someText3;
95 DALI_TEST_CHECK( ! someText3.IsEmpty() );
101 int UtcDaliTextSetGetText(void)
103 TestApplication application;
105 const std::string someText( "Some text");
108 text.SetText( someText );
110 DALI_TEST_CHECK( someText == text.GetText() );
112 Character c = text[0];
115 DALI_TEST_CHECK( std::string("S") == text.GetText() );
118 text2.SetText( text );
120 DALI_TEST_CHECK( text2.GetText() == text.GetText() );
124 int UtcDaliTextAccessOperator01(void)
126 TestApplication application;
128 std::string someText;
131 text.SetText( someText );
133 bool assert1 = false;
134 bool assert2 = false;
137 Character c = text[0];
139 catch( DaliException& e )
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 );
147 someText = std::string( "some text" );
148 text.SetText( someText );
152 Character c = text[100];
154 catch( DaliException& e )
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 );
162 if( assert1 && assert2 )
164 tet_result( TET_PASS );
168 tet_result( TET_FAIL );
173 int UtcDaliTextAccessOperator02(void)
175 TestApplication application;
177 const std::string someText( "Some text");
180 text.SetText( someText );
182 DALI_TEST_CHECK( someText == text.GetText() );
184 Character c = text[0];
187 DALI_TEST_CHECK( std::string("S") == text.GetText() );
191 int UtcDaliTextIsEmpty(void)
193 TestApplication application;
197 DALI_TEST_CHECK( text.IsEmpty() );
199 text.SetText( std::string( "Some text") );
201 DALI_TEST_CHECK( !text.IsEmpty() );
205 int UtcDaliTextGetLength(void)
207 TestApplication application;
209 const std::string someText( "Some text");
211 Text text( someText );
213 DALI_TEST_CHECK( someText.size() == text.GetLength() );
217 int UtcDaliTextAppend(void)
219 TestApplication application;
221 Text text( std::string( "Some text") );
223 text.Append( std::string( "A" ) );
225 DALI_TEST_CHECK( std::string( "Some textA" ) == text.GetText() );
227 Character c = text[0];
230 DALI_TEST_CHECK( std::string( "Some textAS" ) == text.GetText() );
232 Text text2( std::string("B") );
233 text.Append( text2 );
235 DALI_TEST_CHECK( std::string( "Some textASB" ) == text.GetText() );
237 // append to a null text
240 emptyText.Append( text2 );
241 DALI_TEST_CHECK( text2.GetText() == emptyText.GetText() );
246 int UtcDaliTextRemove01(void)
248 TestApplication application;
250 Text text( std::string( "Some text") );
252 bool assert1 = false;
253 bool assert2 = false;
256 text.Remove( 100, 3 );
258 catch( DaliException& e )
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 );
267 text.Remove( 1, 300 );
269 catch( DaliException& e )
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 );
276 if( assert1 && assert2 )
278 tet_result( TET_PASS );
282 tet_result( TET_FAIL );
287 int UtcDaliTextRemove02(void)
289 TestApplication application;
291 Text text01( std::string( "Some text") );
292 Text text02( std::string( "Somext") );
293 Text text03( std::string( "") );
295 text01.Remove( 3, 3 );
297 DALI_TEST_EQUALS( text01.GetLength(), text02.GetLength(), TEST_LOCATION );
298 DALI_TEST_EQUALS( text01.GetText(), text02.GetText(), TEST_LOCATION );
300 text01.Remove( 0, 6 );
302 DALI_TEST_EQUALS( text01.GetLength(), text03.GetLength(), TEST_LOCATION );
303 DALI_TEST_EQUALS( text01.GetText(), text03.GetText(), TEST_LOCATION );