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-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Toolkit;
31 // Tests the following functions with different scripts.
32 // void SetLineBreakInfo( const Vector<Character>& text,
33 // Vector<LineBreakInfo>& lineBreakInfo );
34 // void SetWordBreakInfo( const Vector<Character>& text,
35 // CharacterIndex startIndex,
36 // Length numberOfCharacters,
37 // Vector<WordBreakInfo>& wordBreakInfo );
39 //////////////////////////////////////////////////////////
46 std::string description; ///< Description of the test.
47 std::string text; ///< input text.
48 uint32_t index; ///< The index from where to start to query the break info.
49 uint32_t numberOfCharacters; ///< The requested number of characters.
50 std::string breakInfo; ///< The expected break info.
53 bool LineBreakInfoTest( const BreakInfoData& data )
55 // 1) Convert to utf32
56 Vector<Character> utf32;
57 utf32.Resize( data.text.size() );
59 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
63 utf32.Resize( numberOfCharacters );
65 // 2) Set the line break info for the whole text.
66 Vector<LineBreakInfo> lineBreakInfo;
67 lineBreakInfo.Resize( numberOfCharacters );
69 SetLineBreakInfo( utf32,
74 // 3) Update the word text info if it's requested for part of the text.
75 if( ( 0u != data.index ) &&
76 ( numberOfCharacters != data.numberOfCharacters ) )
78 // Clear part of the line break info.
79 lineBreakInfo.Erase( lineBreakInfo.Begin() + data.index,
80 lineBreakInfo.Begin() + data.index + data.numberOfCharacters );
82 // Update the word line info.
83 SetLineBreakInfo( utf32,
85 data.numberOfCharacters,
89 // 4) compare the results
90 std::ostringstream breakInfo;
92 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
94 breakInfo << static_cast<unsigned int>( lineBreakInfo[index] );
97 if( data.breakInfo != breakInfo.str() )
99 std::cout << " text : [" << data.text << "]" << std::endl;
100 std::cout << " index : " << data.index << std::endl;
101 std::cout << " numberOfCharacters : " << data.numberOfCharacters << std::endl;
102 std::cout << " expected : [" << data.breakInfo << "]" << std::endl;
103 std::cout << " got : [" << breakInfo.str() << "]" << std::endl;
110 bool WordBreakInfoTest( const BreakInfoData& data )
112 // 1) Convert to utf32
113 Vector<Character> utf32;
114 utf32.Resize( data.text.size() );
116 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
120 utf32.Resize( numberOfCharacters );
122 // 2) Set the word break info for the whole text.
123 Vector<WordBreakInfo> wordBreakInfo;
124 wordBreakInfo.Resize( numberOfCharacters );
126 SetWordBreakInfo( utf32,
131 // 3) Update the word text info if it's requested for part of the text.
132 if( ( 0u != data.index ) &&
133 ( numberOfCharacters != data.numberOfCharacters ) )
135 // Clear part of the word break info.
136 wordBreakInfo.Erase( wordBreakInfo.Begin() + data.index,
137 wordBreakInfo.Begin() + data.index + data.numberOfCharacters );
139 // Update the word break info.
140 SetWordBreakInfo( utf32,
142 data.numberOfCharacters,
146 // 4) compare the results
147 std::ostringstream breakInfo;
149 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
151 breakInfo << static_cast<unsigned int>( wordBreakInfo[index] );
154 if( data.breakInfo != breakInfo.str() )
156 std::cout << " text : [" << data.text << "]" << std::endl;
157 std::cout << " index : " << data.index << std::endl;
158 std::cout << " numberOfCharacters : " << data.numberOfCharacters << std::endl;
159 std::cout << " expected : [" << data.breakInfo << "]" << std::endl;
160 std::cout << " got : [" << breakInfo.str() << "]" << std::endl;
169 //////////////////////////////////////////////////////////
171 int UtcDaliTextSegnemtationSetLineBreakInfo(void)
173 tet_infoline(" UtcDaliTextSegnemtationSetLineBreakInfo");
175 struct BreakInfoData data[] =
186 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
187 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
188 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
189 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
190 "Quidam corpora at duo. An eos possim scripserit?",
193 "22222122222122222122212222212222212222222222122122221222221222222222122122220"
194 "2221221222212222222122222222221222222122222222122222222122212220"
195 "221222122222122222221222222222122212222221222222212220"
196 "22122222212222222122222222222122221222122222122222222222122222222222212220"
197 "222222122222221221222212212221222222122222222220",
200 "Latin script. Update initial paragraphs.",
201 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
202 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
203 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
204 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
205 "Quidam corpora at duo. An eos possim scripserit?",
208 "22222122222122222122212222212222212222222222122122221222221222222222122122220"
209 "2221221222212222222122222222221222222122222222122222222122212220"
210 "221222122222122222221222222222122212222221222222212220"
211 "22122222212222222122222222222122221222122222122222222222122222222222212220"
212 "222222122222221221222212212221222222122222222220",
215 "Latin script. Update mid paragraphs.",
216 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
217 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
218 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
219 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
220 "Quidam corpora at duo. An eos possim scripserit?",
223 "22222122222122222122212222212222212222222222122122221222221222222222122122220"
224 "2221221222212222222122222222221222222122222222122222222122212220"
225 "221222122222122222221222222222122212222221222222212220"
226 "22122222212222222122222222222122221222122222122222222222122222222222212220"
227 "222222122222221221222212212221222222122222222220",
230 "Latin script. Update final paragraphs.",
231 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
232 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
233 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
234 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
235 "Quidam corpora at duo. An eos possim scripserit?",
238 "22222122222122222122212222212222212222222222122122221222221222222222122122220"
239 "2221221222212222222122222222221222222122222222122222222122212220"
240 "221222122222122222221222222222122212222221222222212220"
241 "22122222212222222122222222222122221222122222122222222222122222222222212220"
242 "222222122222221221222212212221222222122222222220",
246 "韓国側は北朝鮮当局を通じて米ドルで賃金を支払う。\n"
247 "国際社会から様々な経済制裁を受ける北朝鮮にとっては出稼ぎ労働などと並んで重要な外貨稼ぎの手段となっている。\n"
248 "韓国統一省によると15年だけで1320億ウォン(約130億円)が同工業団地を通じ北朝鮮に支払われたという。",
251 "1111111111111111111111220"
252 "111111211111111111111111111111111111111111111111111220"
253 "11111111121111122211111212211211111111111111111111120",
257 "在被捕的64人中,警方落案起訴了35名男子和3名女子,他們年齡介乎15到70歲。\n"
259 "16名年齡介乎14到33歲的被捕人士獲准保釋候查,另有10人仍被拘留作進一步調查。",
262 "11112112111111112111111112111111121121220"
264 "21111112112111111111111211121111111111120",
267 const unsigned int numberOfTests = 7u;
269 for( unsigned int index = 0u; index < numberOfTests; ++index )
271 ToolkitTestApplication application;
272 if( !LineBreakInfoTest( data[index] ) )
274 tet_result(TET_FAIL);
278 tet_result(TET_PASS);
282 int UtcDaliTextSegnemtationSetWordBreakInfo(void)
284 tet_infoline(" UtcDaliTextSegnemtationSetWordBreakInfo");
286 struct BreakInfoData data[] =
296 "Latin script, full text.",
297 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
298 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
299 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
300 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
301 "Quidam corpora at duo. An eos possim scripserit?",
304 "11110011110011110011001110001111001111111110010011000111100111111110010011000"
305 "1100100111001111110011111111000111110011111110011111110011001000"
306 "100110011110011111100111111100011001111100111111001000"
307 "10011111001111110011111111110011000110011110011111111110011111111111001000"
308 "111110011111100100110001001100111110011111111100",
311 "Latin script, update first paragraph.",
312 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
313 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
314 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
315 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
316 "Quidam corpora at duo. An eos possim scripserit?",
319 "11110011110011110011001110001111001111111110010011000111100111111110010011000"
320 "1100100111001111110011111111000111110011111110011111110011001000"
321 "100110011110011111100111111100011001111100111111001000"
322 "10011111001111110011111111110011000110011110011111111110011111111111001000"
323 "111110011111100100110001001100111110011111111100",
326 "Latin script, update middle paragraphs.",
327 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
328 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
329 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
330 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
331 "Quidam corpora at duo. An eos possim scripserit?",
334 "11110011110011110011001110001111001111111110010011000111100111111110010011000"
335 "1100100111001111110011111111000111110011111110011111110011001000"
336 "100110011110011111100111111100011001111100111111001000"
337 "10011111001111110011111111110011000110011110011111111110011111111111001000"
338 "111110011111100100110001001100111110011111111100",
341 "Latin script, update last paragraph.",
342 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
343 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
344 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
345 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
346 "Quidam corpora at duo. An eos possim scripserit?",
349 "11110011110011110011001110001111001111111110010011000111100111111110010011000"
350 "1100100111001111110011111111000111110011111110011111110011001000"
351 "100110011110011111100111111100011001111100111111001000"
352 "10011111001111110011111111110011000110011110011111111110011111111111001000"
353 "111110011111100100110001001100111110011111111100",
356 "Japanese script, full text.",
357 "韓国側は北朝鮮当局を通じて米ドルで賃金を支払う。\n"
358 "国際社会から様々な経済制裁を受ける北朝鮮にとっては出稼ぎ労働などと並んで重要な外貨稼ぎの手段となっている。\n"
359 "韓国統一省によると15年だけで1320億ウォン(約130億円)が同工業団地を通じ北朝鮮に支払われたという。",
362 "0000000000000010000000000"
363 "000000000000000000000000000000000000000000000000000000"
364 "00000000010000011100110001100000000000000000000000000",
367 "Japanese script, update first paragraph.",
368 "韓国側は北朝鮮当局を通じて米ドルで賃金を支払う。\n"
369 "国際社会から様々な経済制裁を受ける北朝鮮にとっては出稼ぎ労働などと並んで重要な外貨稼ぎの手段となっている。\n"
370 "韓国統一省によると15年だけで1320億ウォン(約130億円)が同工業団地を通じ北朝鮮に支払われたという。",
373 "0000000000000010000000000"
374 "000000000000000000000000000000000000000000000000000000"
375 "00000000010000011100110001100000000000000000000000000",
378 "Japanese script, update middle paragraph.",
379 "韓国側は北朝鮮当局を通じて米ドルで賃金を支払う。\n"
380 "国際社会から様々な経済制裁を受ける北朝鮮にとっては出稼ぎ労働などと並んで重要な外貨稼ぎの手段となっている。\n"
381 "韓国統一省によると15年だけで1320億ウォン(約130億円)が同工業団地を通じ北朝鮮に支払われたという。",
384 "0000000000000010000000000"
385 "000000000000000000000000000000000000000000000000000000"
386 "00000000010000011100110001100000000000000000000000000",
389 "Japanese script, update last paragraph.",
390 "韓国側は北朝鮮当局を通じて米ドルで賃金を支払う。\n"
391 "国際社会から様々な経済制裁を受ける北朝鮮にとっては出稼ぎ労働などと並んで重要な外貨稼ぎの手段となっている。\n"
392 "韓国統一省によると15年だけで1320億ウォン(約130億円)が同工業団地を通じ北朝鮮に支払われたという。",
395 "0000000000000010000000000"
396 "000000000000000000000000000000000000000000000000000000"
397 "00000000010000011100110001100000000000000000000000000",
400 "Chinese script, full text.",
401 "在被捕的64人中,警方落案起訴了35名男子和3名女子,他們年齡介乎15到70歲。\n"
403 "16名年齡介乎14到33歲的被捕人士獲准保釋候查,另有10人仍被拘留作進一步調查。",
406 "00001000000000001000000000000000010010000"
408 "10000001001000000000000000010000000000000",
411 "Chinese script, update first paragraph.",
412 "在被捕的64人中,警方落案起訴了35名男子和3名女子,他們年齡介乎15到70歲。\n"
414 "16名年齡介乎14到33歲的被捕人士獲准保釋候查,另有10人仍被拘留作進一步調查。",
417 "00001000000000001000000000000000010010000"
419 "10000001001000000000000000010000000000000",
422 "Chinese script, update middle paragraph.",
423 "在被捕的64人中,警方落案起訴了35名男子和3名女子,他們年齡介乎15到70歲。\n"
425 "16名年齡介乎14到33歲的被捕人士獲准保釋候查,另有10人仍被拘留作進一步調查。",
428 "00001000000000001000000000000000010010000"
430 "10000001001000000000000000010000000000000",
433 "Chinese script, update last paragraph.",
434 "在被捕的64人中,警方落案起訴了35名男子和3名女子,他們年齡介乎15到70歲。\n"
436 "16名年齡介乎14到33歲的被捕人士獲准保釋候查,另有10人仍被拘留作進一步調查。",
439 "00001000000000001000000000000000010010000"
441 "10000001001000000000000000010000000000000",
444 const unsigned int numberOfTests = 13u;
446 for( unsigned int index = 0u; index < numberOfTests; ++index )
448 ToolkitTestApplication application;
449 if( !WordBreakInfoTest( data[index] ) )
451 tet_result(TET_FAIL);
455 tet_result(TET_PASS);