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 =
176 TextAbstraction::LATIN
178 scriptRuns01.PushBack( scriptRun0100 );
180 // Mix of LTR '\n'and RTL
181 Vector<ScriptRun> scriptRuns02;
182 ScriptRun scriptRun0200 =
186 TextAbstraction::LATIN
188 ScriptRun scriptRun0201 =
192 TextAbstraction::ARABIC
194 scriptRuns02.PushBack( scriptRun0200 );
195 scriptRuns02.PushBack( scriptRun0201 );
197 // Mix of RTL '\n'and LTR
198 Vector<ScriptRun> scriptRuns03;
199 ScriptRun scriptRun0300 =
203 TextAbstraction::ARABIC
205 ScriptRun scriptRun0301 =
209 TextAbstraction::LATIN
211 scriptRuns03.PushBack( scriptRun0300 );
212 scriptRuns03.PushBack( scriptRun0301 );
214 // White spaces. At the beginning of the text.
215 Vector<ScriptRun> scriptRuns04;
216 ScriptRun scriptRun0400 =
220 TextAbstraction::LATIN
222 scriptRuns04.PushBack( scriptRun0400 );
224 // White spaces. At the end of the text.
225 Vector<ScriptRun> scriptRuns05;
226 ScriptRun scriptRun0500 =
230 TextAbstraction::LATIN
232 scriptRuns05.PushBack( scriptRun0500 );
234 // White spaces. At the middle of the text.
235 Vector<ScriptRun> scriptRuns06;
236 ScriptRun scriptRun0600 =
240 TextAbstraction::LATIN
242 scriptRuns06.PushBack( scriptRun0600 );
244 // White spaces between different scripts.
245 Vector<ScriptRun> scriptRuns07;
246 ScriptRun scriptRun0700 =
250 TextAbstraction::LATIN
252 ScriptRun scriptRun0701 =
256 TextAbstraction::HANGUL
258 scriptRuns07.PushBack( scriptRun0700 );
259 scriptRuns07.PushBack( scriptRun0701 );
261 // White spaces between different scripts and differetn directions. Starting LTR.
262 Vector<ScriptRun> scriptRuns08;
263 ScriptRun scriptRun0800 =
267 TextAbstraction::LATIN
269 ScriptRun scriptRun0801 =
273 TextAbstraction::ARABIC
275 ScriptRun scriptRun0802 =
279 TextAbstraction::HANGUL
281 scriptRuns08.PushBack( scriptRun0800 );
282 scriptRuns08.PushBack( scriptRun0801 );
283 scriptRuns08.PushBack( scriptRun0802 );
285 // White spaces between different scripts and differetn directions. Starting RTL.
286 Vector<ScriptRun> scriptRuns09;
287 ScriptRun scriptRun0900 =
291 TextAbstraction::ARABIC
293 ScriptRun scriptRun0901 =
297 TextAbstraction::LATIN
299 ScriptRun scriptRun0902 =
303 TextAbstraction::HANGUL
305 ScriptRun scriptRun0903 =
309 TextAbstraction::ARABIC
311 scriptRuns09.PushBack( scriptRun0900 );
312 scriptRuns09.PushBack( scriptRun0901 );
313 scriptRuns09.PushBack( scriptRun0902 );
314 scriptRuns09.PushBack( scriptRun0903 );
316 // Paragraphs with different directions.
317 Vector<ScriptRun> scriptRuns10;
318 ScriptRun scriptRun1000 =
322 TextAbstraction::ARABIC
324 ScriptRun scriptRun1001 =
328 TextAbstraction::HEBREW
330 ScriptRun scriptRun1002 =
334 TextAbstraction::ARABIC
336 ScriptRun scriptRun1003 =
340 TextAbstraction::LATIN
342 ScriptRun scriptRun1004 =
346 TextAbstraction::HANGUL
348 ScriptRun scriptRun1005 =
352 TextAbstraction::ARABIC
354 ScriptRun scriptRun1006 =
358 TextAbstraction::LATIN
360 ScriptRun scriptRun1007 =
364 TextAbstraction::HEBREW
366 ScriptRun scriptRun1008 =
370 TextAbstraction::LATIN
372 ScriptRun scriptRun1009 =
376 TextAbstraction::ARABIC
378 ScriptRun scriptRun1010 =
382 TextAbstraction::HANGUL
384 scriptRuns10.PushBack( scriptRun1000 );
385 scriptRuns10.PushBack( scriptRun1001 );
386 scriptRuns10.PushBack( scriptRun1002 );
387 scriptRuns10.PushBack( scriptRun1003 );
388 scriptRuns10.PushBack( scriptRun1004 );
389 scriptRuns10.PushBack( scriptRun1005 );
390 scriptRuns10.PushBack( scriptRun1006 );
391 scriptRuns10.PushBack( scriptRun1007 );
392 scriptRuns10.PushBack( scriptRun1008 );
393 scriptRuns10.PushBack( scriptRun1009 );
394 scriptRuns10.PushBack( scriptRun1010 );
396 // Paragraphs with no scripts mixed with paragraphs with scripts.
397 Vector<ScriptRun> scriptRuns11;
398 ScriptRun scriptRun1100 =
402 TextAbstraction::LATIN
404 ScriptRun scriptRun1101 =
408 TextAbstraction::HEBREW
410 scriptRuns11.PushBack( scriptRun1100 );
411 scriptRuns11.PushBack( scriptRun1101 );
413 // Paragraphs with no scripts.
414 Vector<ScriptRun> scriptRuns12;
415 ScriptRun scriptRun1200 =
419 TextAbstraction::LATIN
421 scriptRuns12.PushBack( scriptRun1200 );
423 const ScriptsData data[] =
436 "Mix of LTR '\\n'and RTL",
437 "Hello world\nمرحبا بالعالم",
441 "Mix of RTL '\\n'and LTR",
442 "مرحبا بالعالم\nHello world",
446 "White spaces. At the beginning of the text.",
451 "White spaces. At the end of the text.",
456 "White spaces. At the middle of the text.",
461 "White spaces between different scripts.",
466 "White spaces between different scripts and differetn directions. Starting LTR.",
467 " Hello world مرحبا بالعالم 안녕하세요 세계 ",
471 "White spaces between different scripts and differetn directions. Starting RTL.",
472 " مرحبا بالعالم Hello world 안녕하세요 세계 مرحبا بالعالم ",
476 "Paragraphs with different directions.",
477 " مرحبا بالعالم שלום עולם مرحبا بالعالم \n "
478 " Hello world 안녕하세요 세계 \n "
479 " مرحبا بالعالم Hello world שלום עולם \n "
480 " Hello world مرحبا بالعالم 안녕하세요 세계 \n "
485 "Paragraphs with no scripts mixed with paragraphs with scripts.",
486 " \n \n Hello world \n \n \n שלום עולם \n \n \n ",
490 "Paragraphs with no scripts.",
495 const unsigned int numberOfTests = 13u;
497 for( unsigned int index = 0u; index < numberOfTests; ++index )
499 if( !ScriptsTest( data[index] ) )
501 tet_result(TET_FAIL);
505 tet_result(TET_PASS);
509 int UtcDaliTextMultiLanguageValidateFonts01(void)
511 ToolkitTestApplication application;
512 tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
514 const ValidateFontsData data[] =
525 const unsigned int numberOfTests = 2u;
527 for( unsigned int index = 0u; index < numberOfTests; ++index )
529 if( !ValidateFontTest( data[index] ) )
531 tet_result(TET_FAIL);
535 tet_result(TET_PASS);