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>
25 #include <dali-toolkit/internal/controls/text-view/text-processor-bidirectional-info.h>
28 using namespace Dali::Toolkit;
29 using namespace Dali::Toolkit::Internal;
31 void dali_text_view_processor_startup(void)
33 test_return_value = TET_UNDEF;
36 void dali_text_view_processor_cleanup(void)
38 test_return_value = TET_PASS;
44 // Data structures used to create an 'experiment' in TET cases
46 //////////////////////////////////////////////////////////////////
48 struct BeginsRightToLeftCharacterTest
50 std::string description;
55 bool TestBeginsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
57 // Creates a text with the string.
60 const bool ret = ( result == TextProcessor::BeginsRightToLeftCharacter( text ) );
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 text with the string.
85 const bool ret = ( result == TextProcessor::ContainsRightToLeftCharacter( text ) );
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 SplitInParagraphsTest
132 std::string inputText;
134 std::size_t resultNumberOfParagraphs;
137 bool TestSplitInParagraphs( const SplitInParagraphsTest& 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<Text> paragraphs;
144 std::vector< Vector<TextStyle*> > styles;
146 TextProcessor::SplitInParagraphs( styledText,
150 if( paragraphs.size() != test.resultNumberOfParagraphs )
152 tet_printf( "Fail. %s", location );
153 tet_printf( "Different number of paragraphs, result %d, expected result %d", paragraphs.size(), test.resultNumberOfParagraphs );
161 //////////////////////////////////////////////////////////////////
163 struct SplitInWordsTest
165 std::string inputText;
167 std::size_t resultNumberOfSeparators;
170 bool TestSplitInWords( const SplitInWordsTest& test, const char* location )
172 // Creates a text with the string.
173 Text text( test.inputText );
175 Vector<std::size_t> positions;
177 TextProcessor::SplitInWords( text,
180 if( positions.Count() != test.resultNumberOfSeparators )
182 tet_printf( "Fail. %s", location );
183 tet_printf( "Different number of separators, result %d, expected result %d", positions.Count(), test.resultNumberOfSeparators );
191 //////////////////////////////////////////////////////////////////
196 int UtcDaliTextViewSplitInParagraphs(void)
198 ToolkitTestApplication application;
200 tet_infoline("UtcDaliTextViewSplitInParagraphs : ");
202 struct SplitInParagraphsTest splitInParagraphsTest[] =
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 SplitInParagraphsTest& test = splitInParagraphsTest[index];
219 if( !TestSplitInParagraphs( 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 std::string( "Hello world\n" ),
246 const std::size_t numberOfTests( 2u );
248 for( std::size_t index = 0; index < numberOfTests; ++index )
250 const SplitInWordsTest& test = splitInWordsTest[index];
252 if( !TestSplitInWords( test, TEST_LOCATION ) )
254 tet_result( TET_FAIL );
258 tet_result( TET_PASS );
262 int UtcDaliTextViewBeginsRightToLeftCharacter(void)
264 ToolkitTestApplication application;
266 tet_infoline("UtcDaliTextViewBeginsRightToLeftCharacter : ");
268 struct BeginsRightToLeftCharacterTest beginsRightToLeftCharacterTest[] =
271 std::string( "Test if it begins with a right to left character. Should return false." ),
272 std::string( "Hello world مرحبا العالم." ),
276 std::string( "Test if it begins with a right to left character. Should return true." ),
277 std::string( "مرحبا العالم Hola mundo." ),
281 const std::size_t numberOfTests( 2 );
283 for( std::size_t index = 0; index < numberOfTests; ++index )
285 const BeginsRightToLeftCharacterTest& test = beginsRightToLeftCharacterTest[index];
287 if( !TestBeginsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
289 tet_result( TET_FAIL );
293 tet_result( TET_PASS );
297 int UtcDaliTextViewContainsRightToLeftCharacter(void)
299 ToolkitTestApplication application;
301 tet_infoline("UtcDaliTextViewContainsRightToLeftCharacter : ");
303 struct ContainsRightToLeftCharacterTest containsRightToLeftCharacterTest[] =
306 std::string( "Test if it contains a right to left character. Should return true." ),
307 std::string( "Hello world مرحبا العالم." ),
311 std::string( "Test if it contains a right to left character. Should return true." ),
312 std::string( "مرحبا العالم Hola mundo." ),
316 std::string( "Test if it contains a right to left character. Should return false." ),
317 std::string( "Hello world." ),
321 std::string( "Test if it contains a right to left character. Should return true." ),
322 std::string( "مرحبا العالم." ),
326 const std::size_t numberOfTests( 4 );
328 for( std::size_t index = 0; index < numberOfTests; ++index )
330 const ContainsRightToLeftCharacterTest& test = containsRightToLeftCharacterTest[index];
332 if( !TestContainsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
334 tet_result( TET_FAIL );
338 tet_result( TET_PASS );
342 int UtcDaliTextViewFindNearestWord(void)
344 ToolkitTestApplication application;
346 tet_infoline("UtcDaliTextViewFindNearestWord : ");
348 struct FindNearestWordTest findNearestWordTest[] =
352 std::string( "Hello world, hola mundo" ),
359 std::string( "Hello world, hola mundo" ),
366 std::string( "Hello world, hola mundo" ),
373 std::string( "Hello world, hola mundo" ),
380 std::string( "Hello world, hola mundo" ),
387 std::string( "Hello world, hola mundo مرحبا العالم" ),
394 const std::size_t numberOfTests( 6 );
396 for( std::size_t index = 0; index < numberOfTests; ++index )
398 const FindNearestWordTest& test = findNearestWordTest[index];
400 if( !TestFindNearestWord( test.description, test.input, test.offset, test.start, test.end, TEST_LOCATION ) )
402 tet_result( TET_FAIL );
406 tet_result( TET_PASS );