068a84c610a7bfea7da66f64744ab7d1ee7c5de0
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-LogicalModel.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/internal/text/text-run-container.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-model.h>
26
27
28 using namespace Dali;
29 using namespace Toolkit;
30 using namespace Text;
31
32 // Tests the following functions.
33 //
34 // void CreateParagraphInfo( CharacterIndex startIndex,
35 //                           Length numberOfCharacters );
36 // void FindParagraphs( CharacterIndex index,
37 //                      Length numberOfCharacters,
38 //                      Vector<ParagraphRunIndex>& paragraphs );
39 // CharacterIndex GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const;
40 // CharacterIndex GetLogicalCursorIndex( CharacterIndex visualCursorIndex ) const;
41
42 //////////////////////////////////////////////////////////
43
44 namespace
45 {
46 struct CreateParagraphData
47 {
48   std::string    description;                    ///< Description of the test.
49   std::string    text;                           ///< Input text.
50   CharacterIndex index;                          ///< The first character index.
51   Length         numberOfCharacters;             ///< The number of characters.
52   unsigned int   numberOfParagraphs;             ///< The expected number of paragraphs.
53   unsigned int*  indices;                        ///< The expected paragraph info indices.
54   unsigned int*  numberOfCharactersPerParagraph; ///< The expected number of characters of each paragraph.
55 };
56
57 struct FindParagraphData
58 {
59   std::string    description;        ///< Description of the test.
60   std::string    text;               ///< Input text.
61   CharacterIndex index;              ///< The first character index.
62   Length         numberOfCharacters; ///< The number of characters.
63   unsigned int   numberOfParagraphs; ///< The expected number of paragraphs.
64   unsigned int*  paragraphs;         ///< The expected paragraph info.
65 };
66
67 struct GetLogicalCharacterIndexData
68 {
69   std::string   description;        ///< Description of the test.
70   std::string   text;               ///< Input text.
71   Size          textArea;           ///< The text area.
72   unsigned int  numberOfIndices;    ///< The number of characters to set.
73   unsigned int* visualToLogical;    ///< The expected visual to logical conversion table.
74   unsigned int* cachedBidiLine;     ///< The cached bidi line index for each character.
75 };
76
77 struct GetLogicalCursorIndexData
78 {
79   std::string    description;        ///< Description of the test.
80   std::string    text;               ///< Input text.
81   unsigned int   numberOfIndices;    ///< The number of characters to set.
82   unsigned int*  visualCursorIndex;  ///< The given cursor visual index.
83   unsigned int*  logicalCursorIndex; ///< The expected cursor logical index
84   unsigned int*  cachedBidiLine;     ///< The cached bidi line index for each character.
85 };
86
87 bool CreateParagraphTest( const CreateParagraphData& data )
88 {
89   // 1) Create the model.
90   LogicalModelPtr logicalModel = LogicalModel::New();
91   VisualModelPtr visualModel = VisualModel::New();
92   Size textArea(100.f, 60.f);
93   Size layoutSize;
94
95   Vector<FontDescriptionRun> fontDescriptionRuns;
96   LayoutOptions options;
97   CreateTextModel( data.text,
98                    textArea,
99                    fontDescriptionRuns,
100                    options,
101                    layoutSize,
102                    logicalModel,
103                    visualModel );
104
105   // 2) Clear the paragraphs.
106   Vector<ParagraphRun>& paragraphs = logicalModel->mParagraphInfo;
107   ClearCharacterRuns( data.index,
108                       data.index + data.numberOfCharacters - 1u,
109                       paragraphs );
110
111   // 3) Call the LogicalModel::CreateParagraphInfo() method
112   logicalModel->CreateParagraphInfo( data.index,
113                                      data.numberOfCharacters );
114
115   // 4) Compare the results.
116   if( data.numberOfParagraphs != paragraphs.Count() )
117   {
118     std::cout << "  Different number of paragraphs : " << paragraphs.Count() << ", expected : " << data.numberOfParagraphs << std::endl;
119     return false;
120   }
121
122   unsigned int index = 0u;
123   for( Vector<ParagraphRun>::ConstIterator it = paragraphs.Begin(),
124          endIt = paragraphs.End();
125        it != endIt;
126        ++it, ++index )
127   {
128     const ParagraphRun& paragraph( *it );
129
130     if( data.indices[index] != paragraph.characterRun.characterIndex )
131     {
132       std::cout << "  Different character index for paragraph : " << index << ", " << paragraph.characterRun.characterIndex << ", expected : " << data.indices[index] << std::endl;
133       return false;
134     }
135     if( data.numberOfCharactersPerParagraph[index] != paragraph.characterRun.numberOfCharacters )
136     {
137       std::cout << "  Different number of characters for paragraph : " << index << ", " << paragraph.characterRun.numberOfCharacters << ", expected : " << data.numberOfCharactersPerParagraph[index] << std::endl;
138       return false;
139     }
140   }
141
142   return true;
143 }
144
145 bool FindParagraphTest( const FindParagraphData& data )
146 {
147   // 1) Create the model.
148   LogicalModelPtr logicalModel = LogicalModel::New();
149   VisualModelPtr visualModel = VisualModel::New();
150   Size textArea(100.f, 60.f);
151   Size layoutSize;
152
153   Vector<FontDescriptionRun> fontDescriptionRuns;
154   LayoutOptions options;
155   CreateTextModel( data.text,
156                    textArea,
157                    fontDescriptionRuns,
158                    options,
159                    layoutSize,
160                    logicalModel,
161                    visualModel );
162
163   // 2) Find the paragraphs.
164   Vector<ParagraphRunIndex> paragraphs;
165   logicalModel->FindParagraphs( data.index, data.numberOfCharacters, paragraphs );
166
167   // 3) compare the results.
168   if( data.numberOfParagraphs != paragraphs.Count() )
169   {
170     return false;
171   }
172
173   unsigned int index = 0u;
174   for( Vector<ParagraphRunIndex>::ConstIterator it = paragraphs.Begin(),
175          endIt = paragraphs.End();
176        it != endIt;
177        ++it, ++index )
178   {
179     const ParagraphRunIndex paragraphIndex = *it;
180
181     if( paragraphIndex != data.paragraphs[index] )
182     {
183       return false;
184     }
185   }
186
187   return true;
188 }
189
190 bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data )
191 {
192   std::cout << "  testing : " << data.description << std::endl;
193   // Create the model.
194   LogicalModelPtr logicalModel = LogicalModel::New();
195   VisualModelPtr visualModel = VisualModel::New();
196   Size layoutSize;
197
198   // Create the model with the whole text.
199   const Vector<FontDescriptionRun> fontDescriptions;
200   const LayoutOptions options;
201   CreateTextModel( data.text,
202                    data.textArea,
203                    fontDescriptions,
204                    options,
205                    layoutSize,
206                    logicalModel,
207                    visualModel );
208
209   for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
210   {
211     // Check the current cached bidi line index. (Check it before call the GetLogicalCharacterIndex() method )
212     if( data.cachedBidiLine[index] != logicalModel->mBidirectionalLineIndex )
213     {
214       std::cout << "  index : " << index << ", different cached bidi index : " << logicalModel->mBidirectionalLineIndex << ", expected : " << data.cachedBidiLine[index] << std::endl;
215       return false;
216     }
217
218     const Character logicalIndex = logicalModel->GetLogicalCharacterIndex( index );
219     if( data.visualToLogical[index] != logicalIndex )
220     {
221       std::cout << "  visual index : " << index << ", different logical index : " << logicalIndex << ", expected : " << data.visualToLogical[index] << std::endl;
222       return false;
223     }
224   }
225   return true;
226 }
227
228 bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data )
229 {
230   std::cout << "  testing : " << data.description << std::endl;
231   // Create the model.
232   LogicalModelPtr logicalModel = LogicalModel::New();
233   VisualModelPtr visualModel = VisualModel::New();
234   Size textArea( 300.f, 300.f );
235   Size layoutSize;
236
237   // Create the model with the whole text.
238   const Vector<FontDescriptionRun> fontDescriptions;
239   const LayoutOptions options;
240   CreateTextModel( data.text,
241                    textArea,
242                    fontDescriptions,
243                    options,
244                    layoutSize,
245                    logicalModel,
246                    visualModel );
247
248   for( unsigned int index = 0u; index < data.numberOfIndices; ++index )
249   {
250     if( logicalModel->mBidirectionalLineIndex != data.cachedBidiLine[index] )
251     {
252       std::cout << "  test : " << index << ", different cached line index : " << logicalModel->mBidirectionalLineIndex << ", expected : " << data.cachedBidiLine[index] << std::endl;
253       return false;
254     }
255
256     const CharacterIndex logicalCursorIndex = logicalModel->GetLogicalCursorIndex( data.visualCursorIndex[index] );
257
258     if( logicalCursorIndex != data.logicalCursorIndex[index] )
259     {
260       std::cout << "  test : " << index << ", different logical cursor index : " << logicalCursorIndex << ", expected : " << data.logicalCursorIndex[index] << std::endl;
261       return false;
262     }
263   }
264
265   return true;
266 }
267
268 } // namespace
269
270 //////////////////////////////////////////////////////////
271 //
272 // UtcDaliCreateParagraph
273 // UtcDaliFindParagraph
274 // UtcDaliGetLogicalCharacterIndex
275 // UtcDaliGetLogicalCursorIndex
276 //
277 //////////////////////////////////////////////////////////
278
279 int UtcDaliCreateParagraph(void)
280 {
281   ToolkitTestApplication application;
282   tet_infoline(" UtcDaliCreateParagraph");
283
284   unsigned int paragraphsIndices01[] = { 0u };
285   unsigned int paragraphsNumberOfCharacters01[] = { 0u };
286   unsigned int paragraphsIndices02[] = { 0u, 12u, 17u };
287   unsigned int paragraphsNumberOfCharacters02[] = { 12u, 5u, 1u };
288   unsigned int paragraphsIndices03[] = { 0u, 12u, 17u, 34u };
289   unsigned int paragraphsNumberOfCharacters03[] = { 12u, 5u, 17u ,1u };
290
291   struct CreateParagraphData data[] =
292   {
293     {
294       "Zero characters",
295       "",
296       0u,
297       0u,
298       0u,
299       paragraphsIndices01,
300       paragraphsNumberOfCharacters01,
301     },
302     {
303       "Some paragraphs",
304       "Hello world\ndemo\n\n",
305       0u,
306       18u,
307       3u,
308       paragraphsIndices02,
309       paragraphsNumberOfCharacters02,
310     },
311     {
312       "Some paragraphs. Update the initial paragraphs.",
313       "Hello world\ndemo\nhello world demo\n\n",
314       0u,
315       17u,
316       4u,
317       paragraphsIndices03,
318       paragraphsNumberOfCharacters03,
319     },
320     {
321       "Some paragraphs. Update the mid paragraphs.",
322       "Hello world\ndemo\nhello world demo\n\n",
323       12u,
324       5u,
325       4u,
326       paragraphsIndices03,
327       paragraphsNumberOfCharacters03,
328     },
329     {
330       "Some paragraphs. Update the final paragraphs.",
331       "Hello world\ndemo\nhello world demo\n\n",
332       17u,
333       18u,
334       4u,
335       paragraphsIndices03,
336       paragraphsNumberOfCharacters03,
337     },
338   };
339   const unsigned int numberOfTests = 5u;
340
341   for( unsigned int index = 0u; index < numberOfTests; ++index )
342   {
343     // ToolkitTestApplication application;
344     if( !CreateParagraphTest( data[index] ) )
345     {
346       tet_result(TET_FAIL);
347     }
348   }
349
350   tet_result(TET_PASS);
351   END_TEST;
352 }
353
354 int UtcDaliFindParagraph(void)
355 {
356   tet_infoline(" UtcDaliFindParagraph");
357
358   unsigned int paragraphs01[] = {};
359   unsigned int paragraphs02[] = { 0u, 1u, 2u };
360   unsigned int paragraphs03[] = { 0u };
361   unsigned int paragraphs04[] = { 1u };
362   unsigned int paragraphs05[] = { 0u, 1u, 2u };
363
364   struct FindParagraphData data[] =
365   {
366     {
367       "Zero characters",
368       "",
369       0u,
370       100u,
371       0u,
372       paragraphs01,
373     },
374     {
375       "Some paragraphs",
376       "Hello world\ndemo\n\n",
377       0u,
378       18u,
379       3u,
380       paragraphs02
381     },
382     {
383       "Some paragraphs",
384       "Hello world\ndemo\n\n",
385       0u,
386       12u,
387       1u,
388       paragraphs03
389     },
390     {
391       "Some paragraphs",
392       "Hello world\ndemo\n\n",
393       12u,
394       5u,
395       1u,
396       paragraphs04
397     },
398     {
399       "Some paragraphs",
400       "Hello world\ndemo\n\n",
401       3u,
402       15u,
403       3u,
404       paragraphs05
405     },
406   };
407   const unsigned int numberOfTests = 5u;
408
409   for( unsigned int index = 0u; index < numberOfTests; ++index )
410   {
411     ToolkitTestApplication application;
412     if( !FindParagraphTest( data[index] ) )
413     {
414       tet_result(TET_FAIL);
415     }
416   }
417
418   tet_result(TET_PASS);
419   END_TEST;
420 }
421
422 int UtcDaliGetLogicalCharacterIndex(void)
423 {
424   tet_infoline(" UtcDaliSetVisualToLogicalMap");
425
426   unsigned int visualToLogical01[] = {};
427   unsigned int  cachedBidiLine01[] = {};
428   unsigned int visualToLogical02[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u };
429   unsigned int  cachedBidiLine02[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,  0u };
430   unsigned int visualToLogical03[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
431   unsigned int  cachedBidiLine03[] = {  0u,  0u,  0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u };
432
433   unsigned int visualToLogical04[] = { 0u,  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u, 10u, 11u, 12u, 25u, 24u, 23u, 22u, 21u, 20u, 19u, 18u, 17u, 16u, 15u, 14u, 13u, 26u, 27u, 28u, 29u, 30u, 31u, 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, 81u, 80u, 79u, 78u, 77u, 76u, 75u, 74u, 73u, 72u, 71u, 70u, 69u, 68u, 67u, 66u, 55u, 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, 64u, 65u, 54u, 53u, 52u, 51u, 50u, 49u, 48u, 47u, 46u, 45u, 44u, 43u, 42u, 41u, 40u, 95u, 94u, 93u, 92u, 91u, 90u, 89u, 88u, 87u, 86u, 85u, 84u, 83u, 82u, 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, 104u, 105u, 106u };
434   unsigned int  cachedBidiLine04[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
435                                        0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
436                                        1u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u };
437
438 // size 300, 300
439 // LO   H  e  l  l  o  _  w  o  r  l  d  ,  _  م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,   _  h  e  l  l  o  _  w  o  r  l  d \n
440 //      0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
441 // VO   H  e  l  l  o  _  w  o  r  l  d  ,  _  م  ل  ا  ع   ل  ا  ب  _  ا   ب  ح  ر  م  ,   _  h  e  l  l  o  _  w  o  r  l  d \n
442 //      0  1  2  3  4  5  6  7  8  9 10 11 12 25 24 23 22 21 20 19 18 17 16 15 14 13 26 27 28 29 30 31 32 33 34 35 36 37 38 39
443
444 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,  _  h  e  l  l  o  _  w  o  r  l  d   ,  _  م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
445 //     40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
446 // VO  \n  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م  _  ,  h  e  l  l  o  _  w  o  r  l  d   _  ,  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م
447 //     81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 55 56 57 58 59 60 61 62 63 64 65 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40
448
449 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
450 //     82 83 84 85 86 87 88 89 90 91 92 93 94 95
451 // VO  \n  م  ل  ا  ع  ل   ا  ب  _  ا   ب  ح  ر  م
452 //     95 94 93 92 91 90 89 88 87 86 85 84 83 82
453
454
455 // LO   h   e   l   l   o   _   w   o   r   l   d
456 //     96  97  98  99 100 101 102 103 104 105 106
457 // VO   h   e   l   l   o   _   w   o   r   l   d
458 //     96  97  98  99 100 101 102 103 104 105 106
459
460   unsigned int visualToLogical05[] = { 0u,  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u, 10u, 11u, 12u, 25u, 24u, 23u, 22u, 21u, 20u, 19u, 18u, 17u, 16u, 15u, 14u, 13u, 26u, 27u, 28u, 29u, 30u, 31u, 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, 67u, 66u, 55u, 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, 64u, 65u, 54u, 53u, 52u, 51u, 50u, 49u, 48u, 47u, 46u, 45u, 44u, 43u, 42u, 41u, 40u, 81u, 80u, 79u, 78u, 77u, 76u, 75u, 74u, 73u, 72u, 71u, 70u, 69u, 68u, 95u, 94u, 93u, 92u, 91u, 90u, 89u, 88u, 87u, 86u, 85u, 84u, 83u, 82u, 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, 104u, 105u, 106u };
461   unsigned int  cachedBidiLine05[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u };
462
463 // size 300, 300
464 // LO   H  e  l  l  o  _  w  o  r  l  d  ,  _  م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,   _
465 //      0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
466 // VO   H  e  l  l  o  _  w  o  r  l  d  ,  _  م  ل  ا  ع   ل  ا  ب  _  ا   ب  ح  ر  م  ,   _
467 //      0  1  2  3  4  5  6  7  8  9 10 11 12 25 24 23 22 21 20 19 18 17 16 15 14 13 26 27
468
469 // LO    h  e  l  l  o  _  w  o  r  l  d \n
470 //      28 29 30 31 32 33 34 35 36 37 38 39
471 // VO    h  e  l  l  o  _  w  o  r  l  d \n
472 //      28 29 30 31 32 33 34 35 36 37 38 39
473
474 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,  _  h  e  l  l  o  _  w  o  r  l  d   ,  _
475 //     40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
476 // VO  _  ,  h  e  l  l  o  _  w  o  r  l  d   _  ,  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م
477 //     67 66 55 56 57 58 59 60 61 62 63 64 65 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40
478
479 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
480 //     68 69 70 71 72 73 74 75 76 77 78 79 80 81
481 // VO  \n  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م
482 //     81 80 79 78 77 76 75 74 73 72 71 70 69 68
483
484 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
485 //     82 83 84 85 86 87 88 89 90 91 92 93 94 95
486 // VO  \n  م  ل  ا  ع  ل   ا  ب  _  ا   ب  ح  ر  م
487 //     95 94 93 92 91 90 89 88 87 86 85 84 83 82
488
489
490 // LO   h   e   l   l   o   _   w   o   r   l   d
491 //     96  97  98  99 100 101 102 103 104 105 106
492 // VO   h   e   l   l   o   _   w   o   r   l   d
493 //     96  97  98  99 100 101 102 103 104 105 106
494
495   unsigned int visualToLogical06[] = { 0u,  1u,  2u,  3u,  4u,  5u,  6u,  7u,  8u,  9u, 10u, 11u, 12u, 25u, 24u, 23u, 22u, 21u, 20u, 19u, 18u, 17u, 16u, 15u, 14u, 13u, 26u, 27u, 28u, 29u, 30u, 31u, 32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u, 54u, 53u, 52u, 51u, 50u, 49u, 48u, 47u, 46u, 45u, 44u, 43u, 42u, 41u, 40u, 67u, 66u, 55u, 56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u, 64u, 65u, 81u, 80u, 79u, 78u, 77u, 76u, 75u, 74u, 73u, 72u, 71u, 70u, 69u, 68u, 95u, 94u, 93u, 92u, 91u, 90u, 89u, 88u, 87u, 86u, 85u, 84u, 83u, 82u, 96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u, 104u, 105u, 106u };
496   unsigned int  cachedBidiLine06[] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
497                                        0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
498                                        1u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u,
499                                        2u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u,
500                                        3u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u,
501                                        4u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u, 5u,
502                                        5u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u,
503                                        6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u, 6u };
504
505 // size 100, 600
506 // LO   H  e  l  l  o  _  w  o  r  l  d  ,  _
507 //      0  1  2  3  4  5  6  7  8  9 10 11 12
508 // VO   H  e  l  l  o  _  w  o  r  l  d  ,  _
509 //      0  1  2  3  4  5  6  7  8  9 10 11 12
510
511 // LO    م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,   _
512 //      13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
513 // VO    م  ل  ا  ع   ل  ا  ب  _  ا   ب  ح  ر  م  ,   _
514 //      25 24 23 22 21 20 19 18 17 16 15 14 13 26 27
515
516 // LO    h  e  l  l  o  _  w  o  r  l  d \n
517 //      28 29 30 31 32 33 34 35 36 37 38 39
518 // VO    h  e  l  l  o  _  w  o  r  l  d \n
519 //      28 29 30 31 32 33 34 35 36 37 38 39
520
521 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  ,  _
522 //     40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
523 // VO   _  ,  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م
524 //     54 53 52 51 50 49 48 47 46 45 44 43 42 41 40
525
526 // LO   h  e  l  l  o  _  w  o  r  l  d   ,  _
527 //     55 56 57 58 59 60 61 62 63 64 65 66 67
528 // VO   _  ,  h  e  l  l  o  _  w  o  r  l  d
529 //     67 66 55 56 57 58 59 60 61 62 63 64 65
530
531 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
532 //     68 69 70 71 72 73 74 75 76 77 78 79 80 81
533 // VO  \n  م  ل  ا   ع  ل  ا  ب  _  ا   ب  ح  ر  م
534 //     81 80 79 78 77 76 75 74 73 72 71 70 69 68
535
536 // LO   م  ر  ح  ب   ا  _  ب  ا  ل  ع   ا  ل  م  \n
537 //     82 83 84 85 86 87 88 89 90 91 92 93 94 95
538 // VO  \n  م  ل  ا  ع  ل   ا  ب  _  ا   ب  ح  ر  م
539 //     95 94 93 92 91 90 89 88 87 86 85 84 83 82
540
541
542 // LO   h   e   l   l   o   _   w   o   r   l   d
543 //     96  97  98  99 100 101 102 103 104 105 106
544 // VO   h   e   l   l   o   _   w   o   r   l   d
545 //     96  97  98  99 100 101 102 103 104 105 106
546
547   struct GetLogicalCharacterIndexData data[] =
548   {
549     {
550       "Zero characters text",
551       "",
552       Size( 300.f, 300.f ),
553       0u,
554       visualToLogical01,
555       cachedBidiLine01
556     },
557     {
558       "Left to right text only",
559       "Hello world",
560       Size( 300.f, 300.f ),
561       11u,
562       visualToLogical02,
563       cachedBidiLine02
564     },
565     {
566       "Right to left text only",
567       "مرحبا بالعالم",
568       Size( 300.f, 300.f ),
569       13u,
570       visualToLogical03,
571       cachedBidiLine03
572     },
573     {
574       "Mix of left to right and right to left text.",
575       "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
576       Size( 300.f, 300.f ),
577       107u,
578       visualToLogical04,
579       cachedBidiLine04
580     },
581     {
582       "Mix of left to right and right to left text.",
583       "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
584       Size( 200.f, 400.f ),
585       107u,
586       visualToLogical05,
587       cachedBidiLine05
588     },
589     {
590       "Mix of left to right and right to left text.",
591       "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
592       Size( 100.f, 600.f ),
593       107u,
594       visualToLogical06,
595       cachedBidiLine06
596     },
597   };
598   const unsigned int numberOfTests = 6u;
599
600   for( unsigned int index = 0u; index < numberOfTests; ++index )
601   {
602     ToolkitTestApplication application;
603     if( !GetLogicalCharacterIndexTest( data[index] ) )
604     {
605       tet_result(TET_FAIL);
606     }
607   }
608
609   tet_result(TET_PASS);
610   END_TEST;
611 }
612
613 int UtcDaliGetLogicalCursorIndex(void)
614 {
615   tet_infoline(" UtcDaliGetLogicalCursorIndex");
616
617   unsigned int visualIndex01[] = { 10u };
618   unsigned int logicalIndex01[] = { 10u };
619   unsigned int bidirectionalLineIndex01[] = { 0u };
620
621   unsigned int visualIndex02[] = { 0u, 16u, 11u, 12u };
622   unsigned int logicalIndex02[] = { 0u, 16u, 11u, 12u };
623   unsigned int bidirectionalLineIndex02[] = { 0u, 0u, 0u, 0u };
624
625
626
627 // LO     H  e  l  l  o  _  w  o  r  l  d  ,  _  \n
628 //       0  1  2  3  4  5  6  7  8  9 10 11 12 13 14
629 // VO     H  e  l  l  o  _  w  o  r  l  d  ,  _  \n
630
631 // LO      ש  ל  ו  ם  _  ע  ו  ל  ם  ,  _ \n
632 //       14 15 16 17 18 19 20 21 22 23 24 25 26
633 // VO      \n _  ,  ם  ל  ו  ע  _  ם  ו  ל  ש
634
635 // LO      h  e  l  l  o  _  w  o  r  l  d  ,  _ \n
636 //       26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
637 // VO      h  e  l  l  o  _  w  o  r  l  d  ,  _ \n
638
639 // LO      h  e  l  l  o  _  w  o  r  l  d  ,  _  ש  ל  ו  ם  _  ע  ו  ל  ם \n
640 //       40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
641 // VO      h  e  l  l  o  _  w  o  r  l  d  ,  _  ם  ל  ו  ע  _  ם  ו  ל  ש \n
642
643 // LO      ש  ל  ו  ם  _  ע  ו  ל  ם
644 //       63 64 65 66 67 68 69 70 71 72
645 // VO      ם  ל  ו  ע  _  ם  ו  ל  ש
646
647   unsigned int visualIndex03[] = { 0u, 18u, 25u, 60u, 54u, 65u, 0u, 18u, 65u, 33u };
648   unsigned int logicalIndex03[] = { 0u, 22u, 15u, 55u, 61u, 70u, 0u, 22u, 70u, 33u };
649   unsigned int bidirectionalLineIndex03[] = { 0u, 0u, 0u, 0u, 1u, 1u, 2u, 2u, 0u, 2u };
650
651
652 // LO      ש  ל  ו  ם  _  ע  ו  ל  ם  ,  _ \n
653 //        0  1  2  3  4  5  6  7  8  9 10 11 12
654 // VO      \n ,  ם  ל  ו  ע  _  ם  ו  ל  ש
655
656 // LO      h  e  l  l  o  _  w  o  r  l  d  ,  _  \n
657 //       12 13 14 15 16 17 18 19 20 21 22 23 24 25  26
658 // VO      h  e  l  l  o  _  w  o  r  l  d  ,  _  \n
659
660 // LO      h  e  l  l  o  _  w  o  r  l  d  ,  _  ש  ל  ו  ם  _  ע  ו  ל  ם  \n
661 //       26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  49
662 // VO      h  e  l  l  o  _  w  o  r  l  d  ,  _  ש  ל  ו  ם  _  ע  ו  ל  ם  \n
663
664 // LO      ש  ל  ו  ם  _  ע  ו  ל  ם  ,  _  \n
665 //       49 50 51 52 53 54 55 56 57 58 59 60  61
666 // VO      ם  ל  ו  ע  _  ם  ו  ל  ש  ,  \n
667
668 // LO      h  e  l  l  o  _  w  o  r  l  d
669 //       61 62 63 64 65 66 67 68 69 70 71 72
670 // VO      h  e  l  l  o  _  w  o  r  l  d
671
672
673   unsigned int visualIndex04[] = { 0u };
674   unsigned int logicalIndex04[] = { 72u };
675   unsigned int bidirectionalLineIndex04[] = { 0u };
676
677
678
679   struct GetLogicalCursorIndexData data[] =
680   {
681     {
682       "Zero characters text",
683       "",
684       1u,
685       visualIndex01,
686       logicalIndex01,
687       bidirectionalLineIndex01,
688     },
689     {
690       "All left to right text 01.",
691       "Hello world\ndemo",
692       4u,
693       visualIndex02,
694       logicalIndex02,
695       bidirectionalLineIndex02,
696     },
697     {
698       "bidirectional text 01.",
699       "Hello world, \nשלום עולם, \nhello world, \nhello world, שלום עולם\nשלום עולם",
700       10u,
701       visualIndex03,
702       logicalIndex03,
703       bidirectionalLineIndex03,
704     },
705     {
706       "bidirectional text 02.",
707       "שלום עולם, \nhello world, \nhello world, שלום עולם\nשלום עולם, \nhello world",
708       1u,
709       visualIndex04,
710       logicalIndex04,
711       bidirectionalLineIndex04,
712     },
713   };
714   const unsigned int numberOfTests = 4u;
715
716   for( unsigned int index = 0u; index < numberOfTests; ++index )
717   {
718     ToolkitTestApplication application;
719     if( !GetLogicalCursorIndexTest( data[index] ) )
720     {
721       tet_result(TET_FAIL);
722     }
723   }
724
725   tet_result(TET_PASS);
726   END_TEST;
727 }