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,
37 // const Vector<ScriptRun>& scripts,
38 // const Vector<FontDescriptionRun>& fontDescriptions,
39 // FontId defaultFontId,
40 // Vector<FontRun>& fonts );
42 //////////////////////////////////////////////////////////
49 std::string description; ///< Description of the experiment.
50 std::string text; ///< Input text.
51 Vector<ScriptRun> scriptRuns; ///< Expected script runs.
54 struct ValidateFontsData
56 std::string description; ///< Description of the experiment.
57 std::string text; ///< Input text.
60 //////////////////////////////////////////////////////////
62 bool ScriptsTest( const ScriptsData& data )
64 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
66 // 1) Convert to utf32
67 Vector<Character> utf32;
68 utf32.Resize( data.text.size() );
70 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
73 utf32.Resize( numberOfCharacters );
75 // 2) Set the script info.
76 Vector<ScriptRun> scripts;
77 multilanguageSupport.SetScripts( utf32,
80 // 3) Compare the results.
82 tet_printf( "Testing %s\n", data.description.c_str() );
83 if( scripts.Count() != data.scriptRuns.Count() )
85 tet_printf("ScriptsTest FAIL: different number of scripts. %d, should be %d\n", scripts.Count(), data.scriptRuns.Count() );
89 for( unsigned int index = 0u; index < scripts.Count(); ++index )
91 const ScriptRun& scriptRun1 = scripts[index];
92 const ScriptRun& scriptRun2 = data.scriptRuns[index];
94 if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
96 tet_printf("ScriptsTest FAIL: different character index. %d, should be %d\n", scriptRun1.characterRun.characterIndex, scriptRun2.characterRun.characterIndex );
100 if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
102 tet_printf("ScriptsTest FAIL: different number of characters. %d, should be %d\n", scriptRun1.characterRun.numberOfCharacters, scriptRun2.characterRun.numberOfCharacters );
106 if( scriptRun1.script != scriptRun2.script )
108 tet_printf("ScriptsTest FAIL: different script. %s, should be %s\n", TextAbstraction::ScriptName[scriptRun1.script], TextAbstraction::ScriptName[scriptRun2.script] );
116 bool ValidateFontTest( const ValidateFontsData& data )
118 MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
120 // 1) Convert to utf32
121 Vector<Character> utf32;
122 utf32.Resize( data.text.size() );
124 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
127 utf32.Resize( numberOfCharacters );
129 // 2) Set the script info.
130 Vector<ScriptRun> scripts;
131 multilanguageSupport.SetScripts( utf32,
134 // To be completed ...
135 Vector<FontDescriptionRun> fontDescriptions;
136 FontId defaultFontId = 0u;
137 Vector<FontRun> fonts;
139 // 3) Validate the fonts
140 multilanguageSupport.ValidateFonts( utf32,
150 int UtcDaliTextMultiLanguageConstructor(void)
152 ToolkitTestApplication application;
153 tet_infoline(" UtcDaliTextMultiLanguageConstructor");
155 MultilanguageSupport multilanguageSupport;
156 DALI_TEST_CHECK( !multilanguageSupport );
158 MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
159 DALI_TEST_CHECK( multilanguageSupport1 );
161 // To increase coverage.
162 MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
163 DALI_TEST_CHECK( multilanguageSupport2 );
165 DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
167 tet_result(TET_PASS);
171 int UtcDaliTextMultiLanguageSetScripts(void)
173 ToolkitTestApplication application;
174 tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
177 Vector<ScriptRun> scriptRuns00;
180 Vector<ScriptRun> scriptRuns01;
181 ScriptRun scriptRun0100 =
187 TextAbstraction::LATIN
189 scriptRuns01.PushBack( scriptRun0100 );
191 // Mix of LTR '\n'and RTL
192 Vector<ScriptRun> scriptRuns02;
193 ScriptRun scriptRun0200 =
199 TextAbstraction::LATIN
201 ScriptRun scriptRun0201 =
207 TextAbstraction::ARABIC
209 scriptRuns02.PushBack( scriptRun0200 );
210 scriptRuns02.PushBack( scriptRun0201 );
212 // Mix of RTL '\n'and LTR
213 Vector<ScriptRun> scriptRuns03;
214 ScriptRun scriptRun0300 =
220 TextAbstraction::ARABIC
222 ScriptRun scriptRun0301 =
228 TextAbstraction::LATIN
230 scriptRuns03.PushBack( scriptRun0300 );
231 scriptRuns03.PushBack( scriptRun0301 );
233 // White spaces. At the beginning of the text.
234 Vector<ScriptRun> scriptRuns04;
235 ScriptRun scriptRun0400 =
241 TextAbstraction::LATIN
243 scriptRuns04.PushBack( scriptRun0400 );
245 // White spaces. At the end of the text.
246 Vector<ScriptRun> scriptRuns05;
247 ScriptRun scriptRun0500 =
253 TextAbstraction::LATIN
255 scriptRuns05.PushBack( scriptRun0500 );
257 // White spaces. At the middle of the text.
258 Vector<ScriptRun> scriptRuns06;
259 ScriptRun scriptRun0600 =
265 TextAbstraction::LATIN
267 scriptRuns06.PushBack( scriptRun0600 );
269 // White spaces between different scripts.
270 Vector<ScriptRun> scriptRuns07;
271 ScriptRun scriptRun0700 =
277 TextAbstraction::LATIN
279 ScriptRun scriptRun0701 =
285 TextAbstraction::HANGUL
287 scriptRuns07.PushBack( scriptRun0700 );
288 scriptRuns07.PushBack( scriptRun0701 );
290 // White spaces between different scripts and differetn directions. Starting LTR.
291 Vector<ScriptRun> scriptRuns08;
292 ScriptRun scriptRun0800 =
298 TextAbstraction::LATIN
300 ScriptRun scriptRun0801 =
306 TextAbstraction::ARABIC
308 ScriptRun scriptRun0802 =
314 TextAbstraction::HANGUL
316 scriptRuns08.PushBack( scriptRun0800 );
317 scriptRuns08.PushBack( scriptRun0801 );
318 scriptRuns08.PushBack( scriptRun0802 );
320 // White spaces between different scripts and differetn directions. Starting RTL.
321 Vector<ScriptRun> scriptRuns09;
322 ScriptRun scriptRun0900 =
328 TextAbstraction::ARABIC
330 ScriptRun scriptRun0901 =
336 TextAbstraction::LATIN
338 ScriptRun scriptRun0902 =
344 TextAbstraction::HANGUL
346 ScriptRun scriptRun0903 =
352 TextAbstraction::ARABIC
354 scriptRuns09.PushBack( scriptRun0900 );
355 scriptRuns09.PushBack( scriptRun0901 );
356 scriptRuns09.PushBack( scriptRun0902 );
357 scriptRuns09.PushBack( scriptRun0903 );
359 // Paragraphs with different directions.
360 Vector<ScriptRun> scriptRuns10;
361 ScriptRun scriptRun1000 =
367 TextAbstraction::ARABIC
369 ScriptRun scriptRun1001 =
375 TextAbstraction::HEBREW
377 ScriptRun scriptRun1002 =
383 TextAbstraction::ARABIC
385 ScriptRun scriptRun1003 =
391 TextAbstraction::LATIN
393 ScriptRun scriptRun1004 =
399 TextAbstraction::HANGUL
401 ScriptRun scriptRun1005 =
407 TextAbstraction::ARABIC
409 ScriptRun scriptRun1006 =
415 TextAbstraction::LATIN
417 ScriptRun scriptRun1007 =
423 TextAbstraction::HEBREW
425 ScriptRun scriptRun1008 =
431 TextAbstraction::LATIN
433 ScriptRun scriptRun1009 =
439 TextAbstraction::ARABIC
441 ScriptRun scriptRun1010 =
447 TextAbstraction::HANGUL
449 scriptRuns10.PushBack( scriptRun1000 );
450 scriptRuns10.PushBack( scriptRun1001 );
451 scriptRuns10.PushBack( scriptRun1002 );
452 scriptRuns10.PushBack( scriptRun1003 );
453 scriptRuns10.PushBack( scriptRun1004 );
454 scriptRuns10.PushBack( scriptRun1005 );
455 scriptRuns10.PushBack( scriptRun1006 );
456 scriptRuns10.PushBack( scriptRun1007 );
457 scriptRuns10.PushBack( scriptRun1008 );
458 scriptRuns10.PushBack( scriptRun1009 );
459 scriptRuns10.PushBack( scriptRun1010 );
461 // Paragraphs with no scripts mixed with paragraphs with scripts.
462 Vector<ScriptRun> scriptRuns11;
463 ScriptRun scriptRun1100 =
469 TextAbstraction::LATIN
471 ScriptRun scriptRun1101 =
477 TextAbstraction::HEBREW
479 scriptRuns11.PushBack( scriptRun1100 );
480 scriptRuns11.PushBack( scriptRun1101 );
482 // Paragraphs with no scripts.
483 Vector<ScriptRun> scriptRuns12;
484 ScriptRun scriptRun1200 =
490 TextAbstraction::LATIN
492 scriptRuns12.PushBack( scriptRun1200 );
494 const ScriptsData data[] =
507 "Mix of LTR '\\n'and RTL",
508 "Hello world\nمرحبا بالعالم",
512 "Mix of RTL '\\n'and LTR",
513 "مرحبا بالعالم\nHello world",
517 "White spaces. At the beginning of the text.",
522 "White spaces. At the end of the text.",
527 "White spaces. At the middle of the text.",
532 "White spaces between different scripts.",
537 "White spaces between different scripts and differetn directions. Starting LTR.",
538 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
542 "White spaces between different scripts and differetn directions. Starting RTL.",
543 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
547 "Paragraphs with different directions.",
548 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
549 " Hello world 안녕하세요 세계 \n "
550 " مرحبا بالعالم Hello world שלום עולם \n "
551 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
556 "Paragraphs with no scripts mixed with paragraphs with scripts.",
557 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
561 "Paragraphs with no scripts.",
566 const unsigned int numberOfTests = 13u;
568 for( unsigned int index = 0u; index < numberOfTests; ++index )
570 if( !ScriptsTest( data[index] ) )
572 tet_result(TET_FAIL);
576 tet_result(TET_PASS);
580 int UtcDaliTextMultiLanguageValidateFonts01(void)
582 ToolkitTestApplication application;
583 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
585 const ValidateFontsData data[] =
596 const unsigned int numberOfTests = 2u;
598 for( unsigned int index = 0u; index < numberOfTests; ++index )
600 if( !ValidateFontTest( data[index] ) )
602 tet_result(TET_FAIL);
606 tet_result(TET_PASS);