1e2b72d0d292873cd4dd0ae4487800b44b4e6142
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-Cursor.cpp
1 /*
2  * Copyright (c) 2017 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/cursor-helper-functions.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-utils.h>
26
27
28 using namespace Dali;
29 using namespace Toolkit;
30 using namespace Text;
31
32 // Tests the following functions.
33 //
34 // LineIndex GetClosestLine( VisualModelPtr visualModel,
35 //                           float visualY,
36 //                           bool& isLineHit )
37 // CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
38 //                                       LogicalModelPtr logicalModel,
39 //                                       MetricsPtr metrics,
40 //                                       float visualX,
41 //                                       float visualY,
42 //                                       CharacterHitTest::Mode mode,
43 //                                       bool& isCharacterHit )
44
45 //////////////////////////////////////////////////////////
46
47 namespace
48 {
49
50 struct GetClosestLineData
51 {
52   std::string    description;                    ///< Description of the test.
53   std::string    text;                           ///< Input text.
54   unsigned int   numberOfTests;                  ///< The number of tests.
55   float*         visualY;                        ///< The visual 'y' position for each test.
56   LineIndex*     lineIndex;                      ///< The expected line index for each test.
57   bool*          isLineHit;                      ///< The expected line hit value for each test.
58 };
59
60 struct GetClosestCursorIndexData
61 {
62   std::string             description;           ///< Description of the test.
63   std::string             text;                  ///< Input text.
64   unsigned int            numberOfTests;         ///< The number of tests.
65   float*                  visualX;               ///< The visual 'x' position for each test.
66   float*                  visualY;               ///< The visual 'y' position for each test.
67   CharacterHitTest::Mode* mode;                  ///< The type of hit test.
68   CharacterIndex*         logicalIndex;          ///< The expected logical cursor index for each test.
69   bool*                   isCharacterHit;        ///< The expected character hit value for each test.
70 };
71
72 struct GetCursorPositionData
73 {
74   std::string     description;                    ///< Description of the test.
75   std::string     text;                           ///< Input text.
76   unsigned int    numberOfTests;                  ///< The number of tests.
77   CharacterIndex* logicalIndex;                   ///< The logical cursor index for each test.
78   float*          visualX;                        ///< The expected visual 'x' position for each test.
79   float*          visualY;                        ///< The expected visual 'y' position for each test.
80 };
81
82 struct FindSelectionIndicesData
83 {
84   std::string     description;                    ///< Description of the test.
85   std::string     text;                           ///< Input text.
86   unsigned int    numberOfTests;                  ///< The number of tests.
87   float*          visualX;                        ///< The visual 'x' position for each test.
88   float*          visualY;                        ///< The visual 'y' position for each test.
89   bool*           found;                          ///< Whether selection indices are found.
90   CharacterIndex* startIndex;                     ///< The expected start cursor index for each test.
91   CharacterIndex* endIndex;                       ///< The expected end cursor index for each test.
92   CharacterIndex* noTextHitIndex;                 ///< The expected character index when there is no hit.
93 };
94
95 bool GetClosestLineTest( const GetClosestLineData& data )
96 {
97   std::cout << "  testing : " << data.description << std::endl;
98
99   // 1) Create the model.
100   LogicalModelPtr logicalModel;
101   VisualModelPtr visualModel;
102   MetricsPtr metrics;
103   Size textArea(400.f, 600.f);
104   Size layoutSize;
105
106   Vector<FontDescriptionRun> fontDescriptionRuns;
107   LayoutOptions options;
108   CreateTextModel( data.text,
109                    textArea,
110                    fontDescriptionRuns,
111                    options,
112                    layoutSize,
113                    logicalModel,
114                    visualModel,
115                    metrics );
116
117   for( unsigned int index = 0; index < data.numberOfTests; ++index )
118   {
119     bool isLineHit = false;
120     const LineIndex lineIndex = GetClosestLine( visualModel,
121                                                 data.visualY[index],
122                                                 isLineHit );
123
124     if( lineIndex != data.lineIndex[index] )
125     {
126       std::cout << "  test " << index << " failed. Different line index : " << lineIndex << ", expected : " << data.lineIndex[index] << std::endl;
127       return false;
128     }
129     if( isLineHit != data.isLineHit[index] )
130     {
131       std::cout << "  test " << index << " failed. Different line hit value : " << isLineHit << ", expected : " << data.isLineHit[index] << std::endl;
132       return false;
133     }
134   }
135
136   return true;
137 }
138
139 bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data )
140 {
141   std::cout << "  testing : " << data.description << std::endl;
142
143   // 1) Create the model.
144   LogicalModelPtr logicalModel;
145   VisualModelPtr visualModel;
146   MetricsPtr metrics;
147   Size textArea(400.f, 600.f);
148   Size layoutSize;
149
150   Vector<FontDescriptionRun> fontDescriptionRuns;
151   LayoutOptions options;
152   CreateTextModel( data.text,
153                    textArea,
154                    fontDescriptionRuns,
155                    options,
156                    layoutSize,
157                    logicalModel,
158                    visualModel,
159                    metrics );
160
161   for( unsigned int index = 0; index < data.numberOfTests; ++index )
162   {
163     bool isCharacterHit = false;
164     const CharacterIndex logicalCursorIndex = GetClosestCursorIndex( visualModel,
165                                                                      logicalModel,
166                                                                      metrics,
167                                                                      data.visualX[index],
168                                                                      data.visualY[index],
169                                                                      data.mode[index],
170                                                                      isCharacterHit );
171
172     if( logicalCursorIndex != data.logicalIndex[index] )
173     {
174       std::cout << "  test " << index << " failed. Different logical cursor index : " << logicalCursorIndex << ", expected : " << data.logicalIndex[index] << std::endl;
175       return false;
176     }
177     if( isCharacterHit != data.isCharacterHit[index] )
178     {
179       std::cout << "  test " << index << " failed. Different character hit value : " << isCharacterHit << ", expected : " << data.isCharacterHit[index] << std::endl;
180       return false;
181     }
182   }
183
184   return true;
185 }
186
187 bool GetCursorPositionTest( const GetCursorPositionData& data )
188 {
189   std::cout << "  testing : " << data.description << std::endl;
190
191   // 1) Create the model.
192   LogicalModelPtr logicalModel;
193   VisualModelPtr visualModel;
194   MetricsPtr metrics;
195   Size textArea(400.f, 600.f);
196   Size layoutSize;
197
198   Vector<FontDescriptionRun> fontDescriptionRuns;
199   LayoutOptions options;
200   CreateTextModel( data.text,
201                    textArea,
202                    fontDescriptionRuns,
203                    options,
204                    layoutSize,
205                    logicalModel,
206                    visualModel,
207                    metrics );
208
209   for( unsigned int index = 0; index < data.numberOfTests; ++index )
210   {
211     CursorInfo cursorInfo;
212     GetCursorPosition( visualModel,
213                        logicalModel,
214                        metrics,
215                        data.logicalIndex[index],
216                        cursorInfo );
217
218     if( cursorInfo.primaryPosition.x != data.visualX[index] )
219     {
220       std::cout << "  test " << index << " failed. Different 'x' cursor position : " << cursorInfo.primaryPosition.x << ", expected : " << data.visualX[index] << std::endl;
221       return false;
222     }
223     if( cursorInfo.primaryPosition.y != data.visualY[index] )
224     {
225       std::cout << "  test " << index << " failed. Different 'y' cursor position : " << cursorInfo.primaryPosition.y << ", expected : " << data.visualY[index] << std::endl;
226        return false;
227     }
228   }
229
230   return true;
231 }
232
233 bool FindSelectionIndicesTest( const FindSelectionIndicesData& data )
234 {
235   std::cout << "  testing : " << data.description << std::endl;
236
237   // 1) Create the model.
238   LogicalModelPtr logicalModel;
239   VisualModelPtr visualModel;
240   MetricsPtr metrics;
241   Size textArea(400.f, 600.f);
242   Size layoutSize;
243
244   Vector<FontDescriptionRun> fontDescriptionRuns;
245   LayoutOptions options;
246   CreateTextModel( data.text,
247                    textArea,
248                    fontDescriptionRuns,
249                    options,
250                    layoutSize,
251                    logicalModel,
252                    visualModel,
253                    metrics );
254
255   for( unsigned int index = 0; index < data.numberOfTests; ++index )
256   {
257     CharacterIndex startIndex = 0;
258     CharacterIndex endIndex = 0;
259     CharacterIndex noTextHitIndex = 0;
260     const bool found = FindSelectionIndices( visualModel,
261                                              logicalModel,
262                                              metrics,
263                                              data.visualX[index],
264                                              data.visualY[index],
265                                              startIndex,
266                                              endIndex,
267                                              noTextHitIndex );
268
269     if( found != data.found[index] )
270     {
271       std::cout << "  test " << index << " failed. Different found value : " << found << ", expected : " <<  data.found[index] << std::endl;
272       return false;
273     }
274     if( startIndex != data.startIndex[index] )
275     {
276       std::cout << "  test " << index << " failed. Different start index : " << startIndex << ", expected : " << data.startIndex[index] << std::endl;
277       return false;
278     }
279     if( endIndex != data.endIndex[index] )
280     {
281       std::cout << "  test " << index << " failed. Different end index : " << endIndex << ", expected : " << data.endIndex[index] << std::endl;
282       return false;
283     }
284     if( noTextHitIndex != data.noTextHitIndex[index] )
285     {
286       std::cout << "  test " << index << " failed. Different no text hit index : " << noTextHitIndex << ", expected : " << data.noTextHitIndex[index] << std::endl;
287       return false;
288     }
289   }
290   return true;
291 }
292
293 } // namespace
294
295 //////////////////////////////////////////////////////////
296 //
297 // UtcDaliGetClosestLine
298 // UtcDaliGetClosestCursorIndex
299 //
300 //////////////////////////////////////////////////////////
301
302 int UtcDaliGetClosestLine(void)
303 {
304   tet_infoline(" UtcDaliGetClosestLine");
305
306   float visualY01[] = { -4.f, 3.f, 1000.f };
307   LineIndex lineIndices01[] = { 0, 0, 0 };
308   bool isLineHit01[] = { false, false, false };
309
310   float visualY02[] = { -4.f, 3.f, 1000.f };
311   LineIndex lineIndices02[] = { 0, 0, 0 };
312   bool isLineHit02[] = { false, true, false };
313
314   float visualY03[] = { -4.f, 11.f, 30.f, 51.f, 68.f, 87.f, 109.f, 130.f };
315   LineIndex lineIndices03[] = { 0, 0, 1u, 2u, 3u, 4u, 5u, 5u };
316   bool isLineHit03[] = { false, true, true, true, true, true, true, false };
317
318   struct GetClosestLineData data[] =
319   {
320     {
321       "void text.",
322       "",
323       3u,
324       visualY01,
325       lineIndices01,
326       isLineHit01
327     },
328     {
329       "Single line text.",
330       "hello world",
331       3u,
332       visualY02,
333       lineIndices02,
334       isLineHit02
335     },
336     {
337       "Multi-line text.",
338       "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
339       "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
340       "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
341       "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
342       "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
343       "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
344       8u,
345       visualY03,
346       lineIndices03,
347       isLineHit03
348     }
349   };
350   const unsigned int numberOfTests = 3u;
351
352   for( unsigned int index = 0; index < numberOfTests; ++index )
353   {
354     ToolkitTestApplication application;
355     if( !GetClosestLineTest( data[index] ) )
356     {
357       tet_result(TET_FAIL);
358     }
359   }
360
361   tet_result(TET_PASS);
362   END_TEST;
363 }
364
365 int UtcDaliGetClosestCursorIndex(void)
366 {
367   tet_infoline(" UtcDaliGetClosestCursorIndex");
368
369   float visualX01[] = { -100.f };
370   float visualY01[] = { -100.f };
371   CharacterHitTest::Mode mode01[] = { CharacterHitTest::TAP };
372   CharacterIndex logicalIndex01[] = { 0 };
373   bool isCharacterHit01[] = { false };
374
375   float visualX02[] = { -100.f, 1000.f, 60.f, 79.f, 83.f, 148.f, 99.f };
376   float visualY02[] = { -100.f, 1000.f, 12.f, 12.f, 12.f, 12.f, 12.f };
377   CharacterHitTest::Mode mode02[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP };
378   CharacterIndex logicalIndex02[] = { 0, 21u, 7u, 10u, 11u, 13u, 20u };
379   bool isCharacterHit02[] = { false, false, true, true, true, true, true  };
380
381   float visualX03[] = { 19.f, 104.f, -2.f, 127.f };
382   float visualY03[] = { 12.f, 12.f, 12.f, 12.f };
383   CharacterHitTest::Mode mode03[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP };
384   CharacterIndex logicalIndex03[] = { 3u, 12u, 0, 18u };
385   bool isCharacterHit03[] = { true, true, false, false };
386
387   //  0     5 _ 6     11  12
388   //   Hello     world  \n
389   // 12    16 _ 17    21   22
390   //   שלום       עולם  \n
391   // 22         31_32      40  41
392   //   different     الأربعاء  \n
393   float visualX04[] = { -100.f, 40.f, 44.f, 85.f, 500.f,
394                          500.f, 367.f, 359.f, 329.f, -100.f,
395                         -100.f, 19.f, 64.f, 72.f, 104.f, 111.f, 500.f};
396   float visualY04[] = { -100.f, 12.f, 12.f, 12.f, 12.f,
397                           30.f, 30.f, 30.f, 30.f, 30.f,
398                           50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f };
399   CharacterHitTest::Mode mode04[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
400                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
401                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP };
402   CharacterIndex logicalIndex04[] = {    0,  5u,  6u, 11u, 11u,
403                                        12u, 16u, 17u, 21u, 21u,
404                                        22u, 25u, 31u, 32u, 34u, 40u, 40u,
405                                        41u };
406   bool isCharacterHit04[] = { false, true, true, false, false,
407                               false, true, true, true, false,
408                               false, true, true, true, true, true, false };
409
410   //   0           10           20            30           40      46
411   //    abcשנבdefג   קכghiעיןjk   lחלךmnoצמם   pqrפרףstuד   אוvwxה
412   //  46     50            60            70           80               93
413   //    סתyz   טזץabcשנבd    efגקכghiעי    ןjklחלךmno   צמםpqrפרףstuד
414   //  93       100           110          120         130          139
415   //    אוvwxהס   תyzטזץabcש   נבdefגקכgh   iעיןjklחלך   mnoצמםpqr
416   // 139           150           160           170          180       186
417   //    פרףstuדאוvw   xהסתyzטזץa   bcשנבdefגק    כghiעיןjkl    חלךmno
418   // 186     190           200           210          220            233
419   //    צמםp   qrפרףstuדא    וvwxהסתyzט   זץabcשנבde   fגקכghiעיןjkl
420   // 233        240            250           260     265
421   //    חלךmnoצ    מםpqrפרףst   uדאוvwxהסת    yzטזץ
422
423   float visualX05[] = { -100.f, 96.f, 155.f, 250.f, 344.f, 500.f,
424                         -100.f, 36.f, 124.f, 190.f, 280.f, 500.f,
425                         -100.f, 56.f, 158.f, 237.f, 303.f, 500.f,
426                         -100.f, 98.f, 184.f, 261.f, 337.f, 500.f,
427                         -100.f, 40.f, 113.f, 223.f, 302.f, 500.f,
428                         -100.f, 82.f, 160.f, 253.f, 500.f };
429   float visualY05[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
430                         30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
431                         50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
432                         67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
433                         87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
434                         107.f, 107.f, 107.f, 107.f, 107.f };
435   CharacterHitTest::Mode mode05[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
436                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
437                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
438                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
439                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
440                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP };
441   CharacterIndex logicalIndex05[] = {    0,  10u,  20u,  30u,  40u,  45u,
442                                        46u,  50u,  60u,  70u,  80u,  92u,
443                                        93u, 100u, 110u, 120u, 130u, 138u,
444                                       139u, 150u, 160u, 170u, 180u, 185u,
445                                       186u, 190u, 200u, 210u, 220u, 232u,
446                                       233u, 240u, 250u, 260u, 265u };
447   bool isCharacterHit05[] = { false, true, true, true, true, false,
448                               false, true, true, true, true, false,
449                               false, true, true, true, true, false,
450                               false, true, true, true, true, false,
451                               false, true, true, true, true, false,
452                               false, true, true, true, false };
453
454   //   0            10           20           30           40        46
455   //    שנבabcגקכd    efעיןghiחל   ךjklצמםmno   פרףpqrדאוs   tuהסתv
456   //  46     50           60          70            80              93
457   //    wxטז   ץyzשנבabcג   קכdefעיןgh   iחלךjklצמם   mnoפרףpqrדאוs
458   //  93        100          110          120           130           139
459   //    tuהסתvw   xטזץyzשנבa   bcגקכdefעי    ןghiחלךjkl    צמםmnoפרף
460   // 139           150           160          170         180       186
461   //    pqrדאוstuהס   תvwxטזץyzש   נבabcגקכde   fעיןghiחלך   jklצמם
462   // 186    190          200           210           220            232
463   //    mnoפ   רףpqrדאוst   uהסתvwxטזץ   yzשנבabcגק    כdefעיןghiחל
464   // 232         240           250           260     265
465   //    ךjklצמםm   noפרףpqrדא    וstuהסתvwx   טזץyz
466
467   float visualX06[] = { 500.f, 307.f, 237.f, 148.f, 55.f, -100.f,
468                         500.f, 362.f, 276.f, 213.f, 121.f, -100.f,
469                         500.f, 344.f, 238.f, 167.f, 93.f, -100.f,
470                         500.f, 306.f, 216.f, 142.f, 58.f, -100.f,
471                         500.f, 355.f, 279.f, 182.f, 92.f, -100.f,
472                         500.f, 326.f, 238.f, 150.f, -100.f };
473   float visualY06[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
474                         30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
475                         50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
476                         67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
477                         87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
478                         107.f, 107.f, 107.f, 107.f, 107.f };
479   CharacterHitTest::Mode mode06[] = { CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
480                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
481                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
482                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
483                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP,
484                                       CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP, CharacterHitTest::TAP };
485   CharacterIndex logicalIndex06[] = {    0,  10u,  20u,  30u,  40u,  45u,
486                                        46u,  50u,  60u,  70u,  80u,  92u,
487                                        93u, 100u, 110u, 120u, 130u, 138u,
488                                       139u, 150u, 160u, 170u, 180u, 185u,
489                                       186u, 190u, 200u, 210u, 220u, 231u,
490                                       232u, 240u, 250u, 260u, 265u  };
491   bool isCharacterHit06[] = { false, true, true, true, true, false,
492                               false, true, true, true, true, false,
493                               false, true, true, true, true, false,
494                               false, true, true, true, true, false,
495                               false, true, true, true, true, false,
496                               false, true, true, true, false };
497
498   float visualX07[] = { 395.f };
499   float visualY07[] = { 12.f };
500   CharacterHitTest::Mode mode07[] = { CharacterHitTest::TAP };
501   CharacterIndex logicalIndex07[] = { 1u };
502   bool isCharacterHit07[] = { true };
503
504   float visualX08[] = { 7.f };
505   float visualY08[] = { 12.f };
506   CharacterHitTest::Mode mode08[] = { CharacterHitTest::TAP };
507   CharacterIndex logicalIndex08[] = { 1u };
508   bool isCharacterHit08[] = { true };
509
510   struct GetClosestCursorIndexData data[] =
511   {
512     {
513       "Void text.",
514       "",
515       1u,
516       visualX01,
517       visualY01,
518       mode01,
519       logicalIndex01,
520       isCharacterHit01
521     },
522     {
523       "Single line text.",
524       "Hello world שלום עולם",
525       7u,
526       visualX02,
527       visualY02,
528       mode02,
529       logicalIndex02,
530       isCharacterHit02
531     },
532     {
533       "Single line with ligatures",
534       "different الأربعاء",
535       4u,
536       visualX03,
537       visualY03,
538       mode03,
539       logicalIndex03,
540       isCharacterHit03
541     },
542     {
543       "Multiline. Single line paragraphs",
544       "Hello world\n"
545       "שלום עולם\n"
546       "different الأربعاء\n",
547       17u,
548       visualX04,
549       visualY04,
550       mode04,
551       logicalIndex04,
552       isCharacterHit04
553     },
554     {
555       "Multiline. Single bidirectional paragraph, starts LTR, wrapped lines",
556       "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
557       "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
558       "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
559       "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
560       "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
561       "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
562       35u,
563       visualX05,
564       visualY05,
565       mode05,
566       logicalIndex05,
567       isCharacterHit05
568     },
569     {
570       "Multiline. Single bidirectional paragraph, starts RTL, wrapped lines",
571       "שנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוstuהסתv"
572       "wxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוs"
573       "tuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרף"
574       "pqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמם"
575       "mnoפרףpqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחל"
576       "ךjklצמםmnoפרףpqrדאוstuהסתvwxטזץyz",
577       35u,
578       visualX06,
579       visualY06,
580       mode06,
581       logicalIndex06,
582       isCharacterHit06
583     },
584     {
585       "Testing complex characters. Arabic ligatures",
586       "الأَبْجَدِيَّة العَرَبِيَّة",
587       1u,
588       visualX07,
589       visualY07,
590       mode07,
591       logicalIndex07,
592       isCharacterHit07
593     },
594     {
595       "Testing complex characters. Latin ligatures",
596       "fi ligature",
597       1u,
598       visualX08,
599       visualY08,
600       mode08,
601       logicalIndex08,
602       isCharacterHit08
603     }
604   };
605   const unsigned int numberOfTests = 8u;
606
607   for( unsigned int index = 0; index < numberOfTests; ++index )
608   {
609     ToolkitTestApplication application;
610     if( !GetClosestCursorIndexTest( data[index] ) )
611     {
612       tet_result(TET_FAIL);
613     }
614   }
615
616   tet_result(TET_PASS);
617   END_TEST;
618 }
619
620 int UtcDaliGetCursorPosition(void)
621 {
622   tet_infoline(" UtcDaliGetCursorPosition");
623
624   float visualX08[] = { 5.f };
625   float visualY08[] = { 0.f };
626   CharacterIndex logicalIndex08[] = { 1u };
627
628   struct GetCursorPositionData data[] =
629   {
630     {
631       "Testing complex characters. Latin ligatures",
632       "fi ligature",
633       1u,
634       logicalIndex08,
635       visualX08,
636       visualY08,
637     }
638   };
639   const unsigned int numberOfTests = 1u;
640
641   for( unsigned int index = 0; index < numberOfTests; ++index )
642   {
643     ToolkitTestApplication application;
644     if( !GetCursorPositionTest( data[index] ) )
645     {
646       tet_result(TET_FAIL);
647     }
648   }
649
650   tet_result(TET_PASS);
651   END_TEST;
652 }
653
654 int UtcDaliFindSelectionIndices(void)
655 {
656   tet_infoline(" UtcDaliFindSelectionIndices");
657
658   float visualX01[] = { -100.f };
659   float visualY01[] = { -100.f };
660   bool found01[] = { false };
661   CharacterIndex startIndex01[] = { 0 };
662   CharacterIndex endIndex01[] = { 0 };
663   CharacterIndex noHitText01[] = { 0 };
664
665   float visualX02[] = { -100.f, 1000.f, 1000.f };
666   float visualY02[] = { -100.f, 12.f, 1000.f };
667   bool found02[] = { false, false, false };
668   CharacterIndex startIndex02[] = { 0, 6u, 6u };
669   CharacterIndex endIndex02[] = { 5u, 11u, 11u };
670   CharacterIndex noHitText02[] = { 0, 11u, 11u };
671
672   float visualX03[] = { 70.f };
673   float visualY03[] = { 12.f };
674   bool found03[] = { true };
675   CharacterIndex startIndex03[] = { 6u };
676   CharacterIndex endIndex03[] = { 11u };
677   CharacterIndex noHitText03[] = { 0u };
678
679   float visualX04[] = { 132.f };
680   float visualY04[] = { 12.f };
681   bool found04[] = { true };
682   CharacterIndex startIndex04[] = { 12u };
683   CharacterIndex endIndex04[] = { 16u };
684   CharacterIndex noHitText04[] = { 0u };
685
686   float visualX05[] = { 1.f };
687   float visualY05[] = { 12.f };
688   bool found05[] = { true };
689   CharacterIndex startIndex05[] = { 0 };
690   CharacterIndex endIndex05[] = { 1u };
691   CharacterIndex noHitText05[] = { 0 };
692
693   float visualX06[] = { 10.f };
694   float visualY06[] = { 12.f };
695   bool found06[] = { true };
696   CharacterIndex startIndex06[] = { 0 };
697   CharacterIndex endIndex06[] = { 1u };
698   CharacterIndex noHitText06[] = { 0u };
699
700   struct FindSelectionIndicesData data[] =
701   {
702     {
703       "void text",
704       "",
705       1u,
706       visualX01,
707       visualY01,
708       found01,
709       startIndex01,
710       endIndex01,
711       noHitText01
712     },
713     {
714       "touch out of text's boundaries",
715       "Hello world",
716       3u,
717       visualX02,
718       visualY02,
719       found02,
720       startIndex02,
721       endIndex02,
722       noHitText02
723     },
724     {
725       "touch on the text",
726       "Hello world demo",
727       1u,
728       visualX03,
729       visualY03,
730       found03,
731       startIndex03,
732       endIndex03,
733       noHitText03
734     },
735     {
736       "touch on the new paragraph character at the end of line",
737       "Hello world demo\n",
738       1u,
739       visualX04,
740       visualY04,
741       found04,
742       startIndex04,
743       endIndex04,
744       noHitText04
745     },
746     {
747       "touch on a white space character. is the unique character of the line",
748       " ",
749       1u,
750       visualX05,
751       visualY05,
752       found05,
753       startIndex05,
754       endIndex05,
755       noHitText05
756     },
757     {
758       "touch on a white space character. is between two words",
759       "h ello",
760       1u,
761       visualX06,
762       visualY06,
763       found06,
764       startIndex06,
765       endIndex06,
766       noHitText06
767     },
768   };
769   const unsigned int numberOfTests = 6u;
770
771   for( unsigned int index = 0; index < numberOfTests; ++index )
772   {
773     ToolkitTestApplication application;
774     if( !FindSelectionIndicesTest( data[index] ) )
775     {
776       tet_result(TET_FAIL);
777     }
778   }
779
780   tet_result(TET_PASS);
781   END_TEST;
782 }