2 * Copyright (c) 2015 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.
21 #include <dali-toolkit/internal/text/character-set-conversion.h>
22 #include <dali-toolkit/internal/text/segmentation.h>
23 #include <dali-toolkit/internal/text/multi-language-support.h>
24 #include <dali-toolkit/internal/text/logical-model-impl.h>
25 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
30 using namespace Toolkit;
33 // Tests the following functions with different scripts.
34 // Constructor, destructor and MultilanguageSupport::Get()
35 // void MultilanguageSupport::SetScripts( const Vector<Character>& text, const Vector<LineBreakInfo>& lineBreakInfo, Vector<ScriptRun>& scripts );
36 // void MultilanguageSupport::ValidateFonts( const Vector<Character>& text, const Vector<ScriptRun>& scripts, Vector<FontRun>& fonts );
38 //////////////////////////////////////////////////////////
45 std::string description; ///< Description of the experiment.
46 std::string text; ///< Input text.
47 Vector<ScriptRun> scriptRuns; ///< Expected script runs.
50 struct ValidateFontsData
52 std::string description; ///< Description of the experiment.
53 std::string text; ///< Input text.
56 //////////////////////////////////////////////////////////
58 bool ScriptsTest( const ScriptsData& data )
60 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
62 // 1) Convert to utf32
63 Vector<Character> utf32;
64 utf32.Resize( data.text.size() );
66 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
69 utf32.Resize( numberOfCharacters );
71 // 2) Set the script info.
72 Vector<ScriptRun> scripts;
73 multilanguageSupport.SetScripts( utf32,
76 // 3) Compare the results.
78 tet_printf( "Testing %s\n", data.description.c_str() );
79 if( scripts.Count() != data.scriptRuns.Count() )
81 tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() );
85 for( unsigned int index = 0u; index < scripts.Count(); ++index )
87 const ScriptRun& scriptRun1 = scripts[index];
88 const ScriptRun& scriptRun2 = data.scriptRuns[index];
90 if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
92 tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex );
96 if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
98 tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters );
102 if( scriptRun1.script != scriptRun2.script )
104 tet_printf("ScriptsTest FAIL: different script. %s, should be %s\n", TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] );
112 bool ValidateFontTest( const ValidateFontsData& data )
114 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
116 // 1) Convert to utf32
117 Vector<Character> utf32;
118 utf32.Resize( data.text.size() );
120 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
123 utf32.Resize( numberOfCharacters );
125 // 2) Set the script info.
126 Vector<ScriptRun> scripts;
127 multilanguageSupport.SetScripts( utf32,
130 Vector<FontRun> fonts;
131 // 3) Validate the fonts
132 multilanguageSupport.ValidateFonts( utf32,
141 int UtcDaliTextMultiLanguageConstructor(void)
143 ToolkitTestApplication application;
144 tet_infoline(" UtcDaliTextMultiLanguageConstructor");
146 MultilanguageSupport multilanguageSupport;
147 DALI_TEST_CHECK( !multilanguageSupport );
149 MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
150 DALI_TEST_CHECK( multilanguageSupport1 );
152 // To increase coverage.
153 MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
154 DALI_TEST_CHECK( multilanguageSupport2 );
156 DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
158 tet_result(TET_PASS);
162 int UtcDaliTextMultiLanguageSetScripts(void)
164 ToolkitTestApplication application;
165 tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
168 Vector<ScriptRun> scriptRuns00;
171 Vector<ScriptRun> scriptRuns01;
172 ScriptRun scriptRun0100 =
178 TextAbstraction::LATIN
180 scriptRuns01.PushBack( scriptRun0100 );
182 // Mix of LTR '\n'and RTL
183 Vector<ScriptRun> scriptRuns02;
184 ScriptRun scriptRun0200 =
190 TextAbstraction::LATIN
192 ScriptRun scriptRun0201 =
198 TextAbstraction::ARABIC
200 scriptRuns02.PushBack( scriptRun0200 );
201 scriptRuns02.PushBack( scriptRun0201 );
203 // Mix of RTL '\n'and LTR
204 Vector<ScriptRun> scriptRuns03;
205 ScriptRun scriptRun0300 =
211 TextAbstraction::ARABIC
213 ScriptRun scriptRun0301 =
219 TextAbstraction::LATIN
221 scriptRuns03.PushBack( scriptRun0300 );
222 scriptRuns03.PushBack( scriptRun0301 );
224 // White spaces. At the beginning of the text.
225 Vector<ScriptRun> scriptRuns04;
226 ScriptRun scriptRun0400 =
232 TextAbstraction::LATIN
234 scriptRuns04.PushBack( scriptRun0400 );
236 // White spaces. At the end of the text.
237 Vector<ScriptRun> scriptRuns05;
238 ScriptRun scriptRun0500 =
244 TextAbstraction::LATIN
246 scriptRuns05.PushBack( scriptRun0500 );
248 // White spaces. At the middle of the text.
249 Vector<ScriptRun> scriptRuns06;
250 ScriptRun scriptRun0600 =
256 TextAbstraction::LATIN
258 scriptRuns06.PushBack( scriptRun0600 );
260 // White spaces between different scripts.
261 Vector<ScriptRun> scriptRuns07;
262 ScriptRun scriptRun0700 =
268 TextAbstraction::LATIN
270 ScriptRun scriptRun0701 =
276 TextAbstraction::HANGUL
278 scriptRuns07.PushBack( scriptRun0700 );
279 scriptRuns07.PushBack( scriptRun0701 );
281 // White spaces between different scripts and differetn directions. Starting LTR.
282 Vector<ScriptRun> scriptRuns08;
283 ScriptRun scriptRun0800 =
289 TextAbstraction::LATIN
291 ScriptRun scriptRun0801 =
297 TextAbstraction::ARABIC
299 ScriptRun scriptRun0802 =
305 TextAbstraction::HANGUL
307 scriptRuns08.PushBack( scriptRun0800 );
308 scriptRuns08.PushBack( scriptRun0801 );
309 scriptRuns08.PushBack( scriptRun0802 );
311 // White spaces between different scripts and differetn directions. Starting RTL.
312 Vector<ScriptRun> scriptRuns09;
313 ScriptRun scriptRun0900 =
319 TextAbstraction::ARABIC
321 ScriptRun scriptRun0901 =
327 TextAbstraction::LATIN
329 ScriptRun scriptRun0902 =
335 TextAbstraction::HANGUL
337 ScriptRun scriptRun0903 =
343 TextAbstraction::ARABIC
345 scriptRuns09.PushBack( scriptRun0900 );
346 scriptRuns09.PushBack( scriptRun0901 );
347 scriptRuns09.PushBack( scriptRun0902 );
348 scriptRuns09.PushBack( scriptRun0903 );
350 // Paragraphs with different directions.
351 Vector<ScriptRun> scriptRuns10;
352 ScriptRun scriptRun1000 =
358 TextAbstraction::ARABIC
360 ScriptRun scriptRun1001 =
366 TextAbstraction::HEBREW
368 ScriptRun scriptRun1002 =
374 TextAbstraction::ARABIC
376 ScriptRun scriptRun1003 =
382 TextAbstraction::LATIN
384 ScriptRun scriptRun1004 =
390 TextAbstraction::HANGUL
392 ScriptRun scriptRun1005 =
398 TextAbstraction::ARABIC
400 ScriptRun scriptRun1006 =
406 TextAbstraction::LATIN
408 ScriptRun scriptRun1007 =
414 TextAbstraction::HEBREW
416 ScriptRun scriptRun1008 =
422 TextAbstraction::LATIN
424 ScriptRun scriptRun1009 =
430 TextAbstraction::ARABIC
432 ScriptRun scriptRun1010 =
438 TextAbstraction::HANGUL
440 scriptRuns10.PushBack( scriptRun1000 );
441 scriptRuns10.PushBack( scriptRun1001 );
442 scriptRuns10.PushBack( scriptRun1002 );
443 scriptRuns10.PushBack( scriptRun1003 );
444 scriptRuns10.PushBack( scriptRun1004 );
445 scriptRuns10.PushBack( scriptRun1005 );
446 scriptRuns10.PushBack( scriptRun1006 );
447 scriptRuns10.PushBack( scriptRun1007 );
448 scriptRuns10.PushBack( scriptRun1008 );
449 scriptRuns10.PushBack( scriptRun1009 );
450 scriptRuns10.PushBack( scriptRun1010 );
452 // Paragraphs with no scripts mixed with paragraphs with scripts.
453 Vector<ScriptRun> scriptRuns11;
454 ScriptRun scriptRun1100 =
460 TextAbstraction::LATIN
462 ScriptRun scriptRun1101 =
468 TextAbstraction::HEBREW
470 scriptRuns11.PushBack( scriptRun1100 );
471 scriptRuns11.PushBack( scriptRun1101 );
473 // Paragraphs with no scripts.
474 Vector<ScriptRun> scriptRuns12;
475 ScriptRun scriptRun1200 =
481 TextAbstraction::LATIN
483 scriptRuns12.PushBack( scriptRun1200 );
485 const ScriptsData data[] =
498 "Mix of LTR '\\n'and RTL",
499 "Hello world\nمرحبا بالعالم",
503 "Mix of RTL '\\n'and LTR",
504 "مرحبا بالعالم\nHello world",
508 "White spaces. At the beginning of the text.",
513 "White spaces. At the end of the text.",
518 "White spaces. At the middle of the text.",
523 "White spaces between different scripts.",
528 "White spaces between different scripts and differetn directions. Starting LTR.",
529 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
533 "White spaces between different scripts and differetn directions. Starting RTL.",
534 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
538 "Paragraphs with different directions.",
539 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
540 " Hello world 안녕하세요 세계 \n "
541 " مرحبا بالعالم Hello world שלום עולם \n "
542 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
547 "Paragraphs with no scripts mixed with paragraphs with scripts.",
548 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
552 "Paragraphs with no scripts.",
557 const unsigned int numberOfTests = 13u;
559 for( unsigned int index = 0u; index < numberOfTests; ++index )
561 if( !ScriptsTest( data[index] ) )
563 tet_result(TET_FAIL);
567 tet_result(TET_PASS);
571 int UtcDaliTextMultiLanguageValidateFonts01(void)
573 ToolkitTestApplication application;
574 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
576 const ValidateFontsData data[] =
587 const unsigned int numberOfTests = 2u;
589 for( unsigned int index = 0u; index < numberOfTests; ++index )
591 if( !ValidateFontTest( data[index] ) )
593 tet_result(TET_FAIL);
597 tet_result(TET_PASS);