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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
28 // Internal headers are allowed here
29 #include <dali-toolkit/internal/controls/text-view/text-processor.h>
32 using namespace Dali::Toolkit;
33 using namespace Dali::Toolkit::Internal;
37 // Data structures used to create an 'experiment' in TET cases
39 //////////////////////////////////////////////////////////////////
41 struct BeginsRightToLeftCharacterTest
43 std::string description;
48 bool TestBeginsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
50 // Creates a styled text with the markup or plain string.
51 MarkupProcessor::StyledTextArray styledText;
52 MarkupProcessor::GetStyledTextArray( input, styledText, true );
54 const bool ret = ( result == TextProcessor::BeginsRightToLeftCharacter( styledText ) );
58 tet_printf( "Fail. %s", location );
59 tet_printf( "Input : %s", input.c_str() );
65 //////////////////////////////////////////////////////////////////
67 struct ContainsRightToLeftCharacterTest
69 std::string description;
74 bool TestContainsRightToLeftCharacter( const std::string& description, const std::string& input, const bool result, const char* location )
76 // Creates a styled text with the markup or plain string.
77 MarkupProcessor::StyledTextArray styledText;
78 MarkupProcessor::GetStyledTextArray( input, styledText, true );
80 const bool ret = ( result == TextProcessor::ContainsRightToLeftCharacter( styledText ) );
84 tet_printf( "Fail. %s", location );
85 tet_printf( "Input : %s", input.c_str() );
91 //////////////////////////////////////////////////////////////////
93 struct FindNearestWordTest
95 std::string description;
102 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 )
104 // Creates a styled text with the markup or plain string.
105 MarkupProcessor::StyledTextArray styledText;
106 MarkupProcessor::GetStyledTextArray( input, styledText, true );
110 TextProcessor::FindNearestWord( styledText, offset, start, end );
112 const bool ret = ( start == startResult ) && ( end == endResult );
116 tet_printf( "Fail. %s", location );
117 tet_printf( "Input : %s, offset %d, start %d, end %d", input.c_str(), offset, start, end );
123 //////////////////////////////////////////////////////////////////
125 struct SplitInLinesTest
127 std::string inputText;
129 std::size_t resultNumberOfLines;
132 bool TestSplitInLines( const SplitInLinesTest& test, const char* location )
134 // Creates a styled text with the markup or plain string.
135 MarkupProcessor::StyledTextArray styledText;
136 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
138 std::vector<MarkupProcessor::StyledTextArray> lines;
140 TextProcessor::SplitInLines( styledText,
143 if( lines.size() != test.resultNumberOfLines )
145 tet_printf( "Fail. %s", location );
146 tet_printf( "Different number of lines, result %d, expected result %d", lines.size(), test.resultNumberOfLines );
154 //////////////////////////////////////////////////////////////////
156 struct SplitInWordsTest
158 std::string inputText;
160 std::size_t resultNumberOfWords;
163 bool TestSplitInWords( const SplitInWordsTest& test, const char* location )
165 // Creates a styled text with the markup or plain string.
166 MarkupProcessor::StyledTextArray styledText;
167 MarkupProcessor::GetStyledTextArray( test.inputText, styledText, true );
169 std::vector<MarkupProcessor::StyledTextArray> words;
171 TextProcessor::SplitInWords( styledText,
174 if( words.size() != test.resultNumberOfWords )
176 tet_printf( "Fail. %s", location );
177 tet_printf( "Different number of words, result %d, expected result %d", words.size(), test.resultNumberOfWords );
185 //////////////////////////////////////////////////////////////////
189 static void Startup();
190 static void Cleanup();
193 void (*tet_startup)() = Startup;
194 void (*tet_cleanup)() = Cleanup;
198 POSITIVE_TC_IDX = 0x01,
202 #define MAX_NUMBER_OF_TESTS 10000
204 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
207 // Add test functionality for all APIs in the class (Positive and Negative)
208 TEST_FUNCTION( UtcDaliTextViewSplitInLines, POSITIVE_TC_IDX );
209 TEST_FUNCTION( UtcDaliTextViewSplitInWords, POSITIVE_TC_IDX );
210 TEST_FUNCTION( UtcDaliTextViewBeginsRightToLeftCharacter, POSITIVE_TC_IDX );
211 TEST_FUNCTION( UtcDaliTextViewContainsRightToLeftCharacter, POSITIVE_TC_IDX );
212 TEST_FUNCTION( UtcDaliTextViewFindNearestWord, POSITIVE_TC_IDX );
213 // TEST_FUNCTION( , POSITIVE_TC_IDX );
214 // TEST_FUNCTION( , NEGATIVE_TC_IDX );
216 // Called only once before first test is run.
217 static void Startup()
221 // Called only once after last test is run
222 static void Cleanup()
226 static void UtcDaliTextViewSplitInLines()
228 ToolkitTestApplication application;
230 tet_infoline("UtcDaliTextViewSplitInLines : ");
232 struct SplitInLinesTest splitInLinesTest[] =
235 std::string( "Hello world\nhello world." ),
239 std::string( "Hello world\nhello world.\n\n" ),
243 const std::size_t numberOfTests( 2 );
245 for( std::size_t index = 0; index < numberOfTests; ++index )
247 const SplitInLinesTest& test = splitInLinesTest[index];
249 if( !TestSplitInLines( test, TEST_LOCATION ) )
251 tet_result( TET_FAIL );
255 tet_result( TET_PASS );
258 static void UtcDaliTextViewSplitInWords()
260 ToolkitTestApplication application;
262 tet_infoline("UtcDaliTextViewSplitInWords : ");
264 struct SplitInWordsTest splitInWordsTest[] =
267 std::string( "Hello world, hello word!" ),
271 const std::size_t numberOfTests( 1 );
273 for( std::size_t index = 0; index < numberOfTests; ++index )
275 const SplitInWordsTest& test = splitInWordsTest[index];
277 if( !TestSplitInWords( test, TEST_LOCATION ) )
279 tet_result( TET_FAIL );
283 tet_result( TET_PASS );
286 static void UtcDaliTextViewBeginsRightToLeftCharacter()
288 ToolkitTestApplication application;
290 tet_infoline("UtcDaliTextViewBeginsRightToLeftCharacter : ");
292 struct BeginsRightToLeftCharacterTest beginsRightToLeftCharacterTest[] =
295 std::string( "Test if it begins with a right to left character. Should return false." ),
296 std::string( "Hello world مرحبا العالم." ),
300 std::string( "Test if it begins with a right to left character. Should return true." ),
301 std::string( "مرحبا العالم Hola mundo." ),
305 const std::size_t numberOfTests( 2 );
307 for( std::size_t index = 0; index < numberOfTests; ++index )
309 const BeginsRightToLeftCharacterTest& test = beginsRightToLeftCharacterTest[index];
311 if( !TestBeginsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
313 tet_result( TET_FAIL );
317 tet_result( TET_PASS );
320 static void UtcDaliTextViewContainsRightToLeftCharacter()
322 ToolkitTestApplication application;
324 tet_infoline("UtcDaliTextViewContainsRightToLeftCharacter : ");
326 struct ContainsRightToLeftCharacterTest containsRightToLeftCharacterTest[] =
329 std::string( "Test if it contains a right to left character. Should return true." ),
330 std::string( "Hello world مرحبا العالم." ),
334 std::string( "Test if it contains a right to left character. Should return true." ),
335 std::string( "مرحبا العالم Hola mundo." ),
339 std::string( "Test if it contains a right to left character. Should return false." ),
340 std::string( "Hello world." ),
344 std::string( "Test if it contains a right to left character. Should return true." ),
345 std::string( "مرحبا العالم." ),
349 const std::size_t numberOfTests( 4 );
351 for( std::size_t index = 0; index < numberOfTests; ++index )
353 const ContainsRightToLeftCharacterTest& test = containsRightToLeftCharacterTest[index];
355 if( !TestContainsRightToLeftCharacter( test.description, test.input, test.result, TEST_LOCATION ) )
357 tet_result( TET_FAIL );
361 tet_result( TET_PASS );
364 static void UtcDaliTextViewFindNearestWord()
366 ToolkitTestApplication application;
368 tet_infoline("UtcDaliTextViewFindNearestWord : ");
370 struct FindNearestWordTest findNearestWordTest[] =
374 std::string( "Hello world, hola mundo" ),
381 std::string( "Hello world, hola mundo" ),
388 std::string( "Hello world, hola mundo" ),
395 std::string( "Hello world, hola mundo" ),
402 std::string( "Hello world, hola mundo" ),
409 std::string( "Hello world, hola mundo مرحبا العالم" ),
416 const std::size_t numberOfTests( 6 );
418 for( std::size_t index = 0; index < numberOfTests; ++index )
420 const FindNearestWordTest& test = findNearestWordTest[index];
422 if( !TestFindNearestWord( test.description, test.input, test.offset, test.start, test.end, TEST_LOCATION ) )
424 tet_result( TET_FAIL );
428 tet_result( TET_PASS );