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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
23 // Internal headers are allowed here
24 #include <dali-toolkit/internal/controls/text-view/text-processor.h>
27 using namespace Dali::Toolkit;
28 using namespace Dali::Toolkit::Internal;
30 void dali_text_view_processor_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_text_view_processor_cleanup(void)
37 test_return_value = TET_PASS;
43 // Data structures used to create an 'experiment' in TET cases
45 //////////////////////////////////////////////////////////////////
47 struct BeginsRightToLeftCharacterTest
49 std::string description;
54 bool TestBeginsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
56 // Creates a styled text with the markup or plain string.
57 MarkupProcessor::StyledTextArray styledText;
58 MarkupProcessor::GetStyledTextArray( input, styledText, true );
60 const bool ret = ( result == TextProcessor::BeginsRightToLeftCharacter( styledText ) );
64 tet_printf( "Fail. %s", location );
65 tet_printf( "Input : %s", input.c_str() );
71 //////////////////////////////////////////////////////////////////
73 struct ContainsRightToLeftCharacterTest
75 std::string description;
80 bool TestContainsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
82 // Creates a styled text with the markup or plain string.
83 MarkupProcessor::StyledTextArray styledText;
84 MarkupProcessor::GetStyledTextArray( input, styledText, true );
86 const bool ret = ( result == TextProcessor::ContainsRightToLeftCharacter( styledText ) );
90 tet_printf( "Fail. %s", location );
91 tet_printf( "Input : %s", input.c_str() );
97 //////////////////////////////////////////////////////////////////
99 struct FindNearestWordTest
101 std::string description;
108 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 )
110 // Creates a styled text with the markup or plain string.
111 MarkupProcessor::StyledTextArray styledText;
112 MarkupProcessor::GetStyledTextArray( input, styledText, true );
116 TextProcessor::FindNearestWord( styledText, offset, start, end );
118 const bool ret = ( start == startResult ) && ( end == endResult );
122 tet_printf( "Fail. %s", location );
123 tet_printf( "Input : %s, offset %d, start %d, end %d", input.c_str(), offset, start, end );
129 //////////////////////////////////////////////////////////////////
131 struct SplitInLinesTest
133 std::string inputText;
135 std::size_t resultNumberOfLines;
138 bool TestSplitInLines( const SplitInLinesTest& test, const char* location )
140 // Creates a styled text with the markup or plain string.
141 MarkupProcessor::StyledTextArray styledText;
142 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
144 std::vector<MarkupProcessor::StyledTextArray> lines;
146 TextProcessor::SplitInLines( styledText,
149 if( lines.size() != test.resultNumberOfLines )
151 tet_printf( "Fail. %s", location );
152 tet_printf( "Different number of lines, result %d, expected result %d", lines.size(), test.resultNumberOfLines );
160 //////////////////////////////////////////////////////////////////
162 struct SplitInWordsTest
164 std::string inputText;
166 std::size_t resultNumberOfWords;
169 bool TestSplitInWords( const SplitInWordsTest& test, const char* location )
171 // Creates a styled text with the markup or plain string.
172 MarkupProcessor::StyledTextArray styledText;
173 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
175 std::vector<MarkupProcessor::StyledTextArray> words;
177 TextProcessor::SplitInWords( styledText,
180 if( words.size() != test.resultNumberOfWords )
182 tet_printf( "Fail. %s", location );
183 tet_printf( "Different number of words, result %d, expected result %d", words.size(), test.resultNumberOfWords );
191 //////////////////////////////////////////////////////////////////
196 int UtcDaliTextViewSplitInLines(void)
198 ToolkitTestApplication application;
200 tet_infoline("UtcDaliTextViewSplitInLines : ");
202 struct SplitInLinesTest splitInLinesTest[] =
205 std::string( "Hello world\nhello world." ),
209 std::string( "Hello world\nhello world.\n\n" ),
213 const std::size_t numberOfTests( 2 );
215 for( std::size_t index = 0; index < numberOfTests; ++index )
217 const SplitInLinesTest& test = splitInLinesTest[index];
219 if( !TestSplitInLines( test, TEST_LOCATION ) )
221 tet_result( TET_FAIL );
225 tet_result( TET_PASS );
229 int UtcDaliTextViewSplitInWords(void)
231 ToolkitTestApplication application;
233 tet_infoline("UtcDaliTextViewSplitInWords : ");
235 struct SplitInWordsTest splitInWordsTest[] =
238 std::string( "Hello world, hello word!" ),
242 const std::size_t numberOfTests( 1 );
244 for( std::size_t index = 0; index < numberOfTests; ++index )
246 const SplitInWordsTest& test = splitInWordsTest[index];
248 if( !TestSplitInWords( test, TEST_LOCATION ) )
250 tet_result( TET_FAIL );
254 tet_result( TET_PASS );
258 int UtcDaliTextViewBeginsRightToLeftCharacter(void)
260 ToolkitTestApplication application;
262 tet_infoline("UtcDaliTextViewBeginsRightToLeftCharacter : ");
264 struct BeginsRightToLeftCharacterTest beginsRightToLeftCharacterTest[] =
267 std::string( "Test if it begins with a right to left character. Should return false." ),
268 std::string( "Hello world مرحبا العالم." ),
272 std::string( "Test if it begins with a right to left character. Should return true." ),
273 std::string( "مرحبا العالم Hola mundo." ),
277 const std::size_t numberOfTests( 2 );
279 for( std::size_t index = 0; index < numberOfTests; ++index )
281 const BeginsRightToLeftCharacterTest& test = beginsRightToLeftCharacterTest[index];
283 if( !TestBeginsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
285 tet_result( TET_FAIL );
289 tet_result( TET_PASS );
293 int UtcDaliTextViewContainsRightToLeftCharacter(void)
295 ToolkitTestApplication application;
297 tet_infoline("UtcDaliTextViewContainsRightToLeftCharacter : ");
299 struct ContainsRightToLeftCharacterTest containsRightToLeftCharacterTest[] =
302 std::string( "Test if it contains a right to left character. Should return true." ),
303 std::string( "Hello world مرحبا العالم." ),
307 std::string( "Test if it contains a right to left character. Should return true." ),
308 std::string( "مرحبا العالم Hola mundo." ),
312 std::string( "Test if it contains a right to left character. Should return false." ),
313 std::string( "Hello world." ),
317 std::string( "Test if it contains a right to left character. Should return true." ),
318 std::string( "مرحبا العالم." ),
322 const std::size_t numberOfTests( 4 );
324 for( std::size_t index = 0; index < numberOfTests; ++index )
326 const ContainsRightToLeftCharacterTest& test = containsRightToLeftCharacterTest[index];
328 if( !TestContainsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
330 tet_result( TET_FAIL );
334 tet_result( TET_PASS );
338 int UtcDaliTextViewFindNearestWord(void)
340 ToolkitTestApplication application;
342 tet_infoline("UtcDaliTextViewFindNearestWord : ");
344 struct FindNearestWordTest findNearestWordTest[] =
348 std::string( "Hello world, hola mundo" ),
355 std::string( "Hello world, hola mundo" ),
362 std::string( "Hello world, hola mundo" ),
369 std::string( "Hello world, hola mundo" ),
376 std::string( "Hello world, hola mundo" ),
383 std::string( "Hello world, hola mundo مرحبا العالم" ),
390 const std::size_t numberOfTests( 6 );
392 for( std::size_t index = 0; index < numberOfTests; ++index )
394 const FindNearestWordTest& test = findNearestWordTest[index];
396 if( !TestFindNearestWord( test.description, test.input, test.offset, test.start, test.end, TEST_LOCATION ) )
398 tet_result( TET_FAIL );
402 tet_result( TET_PASS );