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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
27 // Internal headers are allowed here
28 #include <dali-toolkit/internal/controls/text-view/text-processor.h>
31 using namespace Dali::Toolkit;
32 using namespace Dali::Toolkit::Internal;
36 // Data structures used to create an 'experiment' in TET cases
38 //////////////////////////////////////////////////////////////////
40 struct BeginsRightToLeftCharacterTest
42 std::string description;
47 bool TestBeginsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
49 // Creates a styled text with the markup or plain string.
50 MarkupProcessor::StyledTextArray styledText;
51 MarkupProcessor::GetStyledTextArray( input, styledText );
53 const bool ret = ( result == TextProcessor::BeginsRightToLeftCharacter( styledText ) );
57 tet_printf( "Fail. %s", location );
58 tet_printf( "Input : %s", input.c_str() );
64 //////////////////////////////////////////////////////////////////
66 struct ContainsRightToLeftCharacterTest
68 std::string description;
73 bool TestContainsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
75 // Creates a styled text with the markup or plain string.
76 MarkupProcessor::StyledTextArray styledText;
77 MarkupProcessor::GetStyledTextArray( input, styledText );
79 const bool ret = ( result == TextProcessor::ContainsRightToLeftCharacter( styledText ) );
83 tet_printf( "Fail. %s", location );
84 tet_printf( "Input : %s", input.c_str() );
90 //////////////////////////////////////////////////////////////////
92 struct FindNearestWordTest
94 std::string description;
101 bool TestFindNearestWord( const std::string& description, const std::string& input, const std::size_t offset, const std::size_t startResult, const std::size_t endResult, const char* location )
103 // Creates a styled text with the markup or plain string.
104 MarkupProcessor::StyledTextArray styledText;
105 MarkupProcessor::GetStyledTextArray( input, styledText );
109 TextProcessor::FindNearestWord( styledText, offset, start, end );
111 const bool ret = ( start == startResult ) && ( end == endResult );
115 tet_printf( "Fail. %s", location );
116 tet_printf( "Input : %s, offset %d, start %d, end %d", input.c_str(), offset, start, end );
122 //////////////////////////////////////////////////////////////////
124 struct SplitInLinesTest
126 std::string inputText;
128 std::size_t resultNumberOfLines;
131 bool TestSplitInLines( const SplitInLinesTest& test, const char* location )
133 // Creates a styled text with the markup or plain string.
134 MarkupProcessor::StyledTextArray styledText;
135 MarkupProcessor::GetStyledTextArray( test.inputText, styledText );
137 std::vector<MarkupProcessor::StyledTextArray> lines;
139 TextProcessor::SplitInLines( styledText,
142 if( lines.size() != test.resultNumberOfLines )
144 tet_printf( "Fail. %s", location );
145 tet_printf( "Different number of lines, result %d, expected result %d", lines.size(), test.resultNumberOfLines );
153 //////////////////////////////////////////////////////////////////
155 struct SplitInWordsTest
157 std::string inputText;
159 std::size_t resultNumberOfWords;
162 bool TestSplitInWords( const SplitInWordsTest& test, const char* location )
164 // Creates a styled text with the markup or plain string.
165 MarkupProcessor::StyledTextArray styledText;
166 MarkupProcessor::GetStyledTextArray( test.inputText, styledText );
168 std::vector<MarkupProcessor::StyledTextArray> words;
170 TextProcessor::SplitInWords( styledText,
173 if( words.size() != test.resultNumberOfWords )
175 tet_printf( "Fail. %s", location );
176 tet_printf( "Different number of words, result %d, expected result %d", words.size(), test.resultNumberOfWords );
184 //////////////////////////////////////////////////////////////////
188 static void Startup();
189 static void Cleanup();
192 void (*tet_startup)() = Startup;
193 void (*tet_cleanup)() = Cleanup;
197 POSITIVE_TC_IDX = 0x01,
201 #define MAX_NUMBER_OF_TESTS 10000
203 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
206 // Add test functionality for all APIs in the class (Positive and Negative)
207 TEST_FUNCTION( UtcDaliTextViewSplitInLines, POSITIVE_TC_IDX );
208 TEST_FUNCTION( UtcDaliTextViewSplitInWords, POSITIVE_TC_IDX );
209 TEST_FUNCTION( UtcDaliTextViewBeginsRightToLeftCharacter, POSITIVE_TC_IDX );
210 TEST_FUNCTION( UtcDaliTextViewContainsRightToLeftCharacter, POSITIVE_TC_IDX );
211 TEST_FUNCTION( UtcDaliTextViewFindNearestWord, POSITIVE_TC_IDX );
212 // TEST_FUNCTION( , POSITIVE_TC_IDX );
213 // TEST_FUNCTION( , NEGATIVE_TC_IDX );
215 // Called only once before first test is run.
216 static void Startup()
220 // Called only once after last test is run
221 static void Cleanup()
225 static void UtcDaliTextViewSplitInLines()
227 ToolkitTestApplication application;
229 tet_infoline("UtcDaliTextViewSplitInLines : ");
231 struct SplitInLinesTest splitInLinesTest[] =
234 std::string( "Hello world\nhello world." ),
238 std::string( "Hello world\nhello world.\n\n" ),
242 const std::size_t numberOfTests( 2 );
244 for( std::size_t index = 0; index < numberOfTests; ++index )
246 const SplitInLinesTest& test = splitInLinesTest[index];
248 if( !TestSplitInLines( test, TEST_LOCATION ) )
250 tet_result( TET_FAIL );
254 tet_result( TET_PASS );
257 static void UtcDaliTextViewSplitInWords()
259 ToolkitTestApplication application;
261 tet_infoline("UtcDaliTextViewSplitInWords : ");
263 struct SplitInWordsTest splitInWordsTest[] =
266 std::string( "Hello world, hello word!" ),
270 const std::size_t numberOfTests( 1 );
272 for( std::size_t index = 0; index < numberOfTests; ++index )
274 const SplitInWordsTest& test = splitInWordsTest[index];
276 if( !TestSplitInWords( test, TEST_LOCATION ) )
278 tet_result( TET_FAIL );
282 tet_result( TET_PASS );
285 static void UtcDaliTextViewBeginsRightToLeftCharacter()
287 ToolkitTestApplication application;
289 tet_infoline("UtcDaliTextViewBeginsRightToLeftCharacter : ");
291 struct BeginsRightToLeftCharacterTest beginsRightToLeftCharacterTest[] =
294 std::string( "Test if it begins with a right to left character. Should return false." ),
295 std::string( "Hello world مرحبا العالم." ),
299 std::string( "Test if it begins with a right to left character. Should return true." ),
300 std::string( "مرحبا العالم Hola mundo." ),
304 const std::size_t numberOfTests( 2 );
306 for( std::size_t index = 0; index < numberOfTests; ++index )
308 const BeginsRightToLeftCharacterTest& test = beginsRightToLeftCharacterTest[index];
310 if( !TestBeginsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
312 tet_result( TET_FAIL );
316 tet_result( TET_PASS );
319 static void UtcDaliTextViewContainsRightToLeftCharacter()
321 ToolkitTestApplication application;
323 tet_infoline("UtcDaliTextViewContainsRightToLeftCharacter : ");
325 struct ContainsRightToLeftCharacterTest containsRightToLeftCharacterTest[] =
328 std::string( "Test if it contains a right to left character. Should return true." ),
329 std::string( "Hello world مرحبا العالم." ),
333 std::string( "Test if it contains a right to left character. Should return true." ),
334 std::string( "مرحبا العالم Hola mundo." ),
338 std::string( "Test if it contains a right to left character. Should return false." ),
339 std::string( "Hello world." ),
343 std::string( "Test if it contains a right to left character. Should return true." ),
344 std::string( "مرحبا العالم." ),
348 const std::size_t numberOfTests( 4 );
350 for( std::size_t index = 0; index < numberOfTests; ++index )
352 const ContainsRightToLeftCharacterTest& test = containsRightToLeftCharacterTest[index];
354 if( !TestContainsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
356 tet_result( TET_FAIL );
360 tet_result( TET_PASS );
363 static void UtcDaliTextViewFindNearestWord()
365 ToolkitTestApplication application;
367 tet_infoline("UtcDaliTextViewFindNearestWord : ");
369 struct FindNearestWordTest findNearestWordTest[] =
373 std::string( "Hello world, hola mundo" ),
380 std::string( "Hello world, hola mundo" ),
387 std::string( "Hello world, hola mundo" ),
394 std::string( "Hello world, hola mundo" ),
401 std::string( "Hello world, hola mundo" ),
408 std::string( "Hello world, hola mundo مرحبا العالم" ),
415 const std::size_t numberOfTests( 6 );
417 for( std::size_t index = 0; index < numberOfTests; ++index )
419 const FindNearestWordTest& test = findNearestWordTest[index];
421 if( !TestFindNearestWord( test.description, test.input, test.offset, test.start, test.end, TEST_LOCATION ) )
423 tet_result( TET_FAIL );
427 tet_result( TET_PASS );