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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
22 // Internal headers are allowed here
23 #include <dali-toolkit/internal/controls/text-view/text-processor.h>
26 using namespace Dali::Toolkit;
27 using namespace Dali::Toolkit::Internal;
29 void dali_text_view_processor_startup(void)
31 test_return_value = TET_UNDEF;
34 void dali_text_view_processor_cleanup(void)
36 test_return_value = TET_PASS;
42 // Data structures used to create an 'experiment' in TET cases
44 //////////////////////////////////////////////////////////////////
46 struct BeginsRightToLeftCharacterTest
48 std::string description;
53 bool TestBeginsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
55 // Creates a styled text with the markup or plain string.
56 MarkupProcessor::StyledTextArray styledText;
57 MarkupProcessor::GetStyledTextArray( input, styledText, true );
59 const bool ret = ( result == TextProcessor::BeginsRightToLeftCharacter( styledText ) );
63 tet_printf( "Fail. %s", location );
64 tet_printf( "Input : %s", input.c_str() );
70 //////////////////////////////////////////////////////////////////
72 struct ContainsRightToLeftCharacterTest
74 std::string description;
79 bool TestContainsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
81 // Creates a styled text with the markup or plain string.
82 MarkupProcessor::StyledTextArray styledText;
83 MarkupProcessor::GetStyledTextArray( input, styledText, true );
85 const bool ret = ( result == TextProcessor::ContainsRightToLeftCharacter( styledText ) );
89 tet_printf( "Fail. %s", location );
90 tet_printf( "Input : %s", input.c_str() );
96 //////////////////////////////////////////////////////////////////
98 struct FindNearestWordTest
100 std::string description;
107 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 )
109 // Creates a styled text with the markup or plain string.
110 MarkupProcessor::StyledTextArray styledText;
111 MarkupProcessor::GetStyledTextArray( input, styledText, true );
115 TextProcessor::FindNearestWord( styledText, offset, start, end );
117 const bool ret = ( start == startResult ) && ( end == endResult );
121 tet_printf( "Fail. %s", location );
122 tet_printf( "Input : %s, offset %d, start %d, end %d", input.c_str(), offset, start, end );
128 //////////////////////////////////////////////////////////////////
130 struct SplitInLinesTest
132 std::string inputText;
134 std::size_t resultNumberOfLines;
137 bool TestSplitInLines( const SplitInLinesTest& test, const char* location )
139 // Creates a styled text with the markup or plain string.
140 MarkupProcessor::StyledTextArray styledText;
141 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
143 std::vector<MarkupProcessor::StyledTextArray> lines;
145 TextProcessor::SplitInLines( styledText,
148 if( lines.size() != test.resultNumberOfLines )
150 tet_printf( "Fail. %s", location );
151 tet_printf( "Different number of lines, result %d, expected result %d", lines.size(), test.resultNumberOfLines );
159 //////////////////////////////////////////////////////////////////
161 struct SplitInWordsTest
163 std::string inputText;
165 std::size_t resultNumberOfWords;
168 bool TestSplitInWords( const SplitInWordsTest& test, const char* location )
170 // Creates a styled text with the markup or plain string.
171 MarkupProcessor::StyledTextArray styledText;
172 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
174 std::vector<MarkupProcessor::StyledTextArray> words;
176 TextProcessor::SplitInWords( styledText,
179 if( words.size() != test.resultNumberOfWords )
181 tet_printf( "Fail. %s", location );
182 tet_printf( "Different number of words, result %d, expected result %d", words.size(), test.resultNumberOfWords );
190 //////////////////////////////////////////////////////////////////
195 int UtcDaliTextViewSplitInLines(void)
197 ToolkitTestApplication application;
199 tet_infoline("UtcDaliTextViewSplitInLines : ");
201 struct SplitInLinesTest splitInLinesTest[] =
204 std::string( "Hello world\nhello world." ),
208 std::string( "Hello world\nhello world.\n\n" ),
212 const std::size_t numberOfTests( 2 );
214 for( std::size_t index = 0; index < numberOfTests; ++index )
216 const SplitInLinesTest& test = splitInLinesTest[index];
218 if( !TestSplitInLines( test, TEST_LOCATION ) )
220 tet_result( TET_FAIL );
224 tet_result( TET_PASS );
228 int UtcDaliTextViewSplitInWords(void)
230 ToolkitTestApplication application;
232 tet_infoline("UtcDaliTextViewSplitInWords : ");
234 struct SplitInWordsTest splitInWordsTest[] =
237 std::string( "Hello world, hello word!" ),
241 const std::size_t numberOfTests( 1 );
243 for( std::size_t index = 0; index < numberOfTests; ++index )
245 const SplitInWordsTest& test = splitInWordsTest[index];
247 if( !TestSplitInWords( test, TEST_LOCATION ) )
249 tet_result( TET_FAIL );
253 tet_result( TET_PASS );
257 int UtcDaliTextViewBeginsRightToLeftCharacter(void)
259 ToolkitTestApplication application;
261 tet_infoline("UtcDaliTextViewBeginsRightToLeftCharacter : ");
263 struct BeginsRightToLeftCharacterTest beginsRightToLeftCharacterTest[] =
266 std::string( "Test if it begins with a right to left character. Should return false." ),
267 std::string( "Hello world مرحبا العالم." ),
271 std::string( "Test if it begins with a right to left character. Should return true." ),
272 std::string( "مرحبا العالم Hola mundo." ),
276 const std::size_t numberOfTests( 2 );
278 for( std::size_t index = 0; index < numberOfTests; ++index )
280 const BeginsRightToLeftCharacterTest& test = beginsRightToLeftCharacterTest[index];
282 if( !TestBeginsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
284 tet_result( TET_FAIL );
288 tet_result( TET_PASS );
292 int UtcDaliTextViewContainsRightToLeftCharacter(void)
294 ToolkitTestApplication application;
296 tet_infoline("UtcDaliTextViewContainsRightToLeftCharacter : ");
298 struct ContainsRightToLeftCharacterTest containsRightToLeftCharacterTest[] =
301 std::string( "Test if it contains a right to left character. Should return true." ),
302 std::string( "Hello world مرحبا العالم." ),
306 std::string( "Test if it contains a right to left character. Should return true." ),
307 std::string( "مرحبا العالم Hola mundo." ),
311 std::string( "Test if it contains a right to left character. Should return false." ),
312 std::string( "Hello world." ),
316 std::string( "Test if it contains a right to left character. Should return true." ),
317 std::string( "مرحبا العالم." ),
321 const std::size_t numberOfTests( 4 );
323 for( std::size_t index = 0; index < numberOfTests; ++index )
325 const ContainsRightToLeftCharacterTest& test = containsRightToLeftCharacterTest[index];
327 if( !TestContainsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
329 tet_result( TET_FAIL );
333 tet_result( TET_PASS );
337 int UtcDaliTextViewFindNearestWord(void)
339 ToolkitTestApplication application;
341 tet_infoline("UtcDaliTextViewFindNearestWord : ");
343 struct FindNearestWordTest findNearestWordTest[] =
347 std::string( "Hello world, hola mundo" ),
354 std::string( "Hello world, hola mundo" ),
361 std::string( "Hello world, hola mundo" ),
368 std::string( "Hello world, hola mundo" ),
375 std::string( "Hello world, hola mundo" ),
382 std::string( "Hello world, hola mundo مرحبا العالم" ),
389 const std::size_t numberOfTests( 6 );
391 for( std::size_t index = 0; index < numberOfTests; ++index )
393 const FindNearestWordTest& test = findNearestWordTest[index];
395 if( !TestFindNearestWord( test.description, test.input, test.offset, test.start, test.end, TEST_LOCATION ) )
397 tet_result( TET_FAIL );
401 tet_result( TET_PASS );