2 * Copyright (c) 2016 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.
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>
29 using namespace Toolkit;
32 // Tests the following functions.
34 // LineIndex GetClosestLine( VisualModelPtr visualModel,
36 // CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
37 // LogicalModelPtr logicalModel,
38 // MetricsPtr metrics,
42 //////////////////////////////////////////////////////////
47 struct GetClosestLineData
49 std::string description; ///< Description of the test.
50 std::string text; ///< Input text.
51 unsigned int numberOfTests; ///< The number of tests.
52 float* visualY; ///< The visual 'y' position for each test.
53 LineIndex* lineIndex; ///< The expected line index for each test.
56 struct GetClosestCursorIndexData
58 std::string description; ///< Description of the test.
59 std::string text; ///< Input text.
60 unsigned int numberOfTests; ///< The number of tests.
61 float* visualX; ///< The visual 'x' position for each test.
62 float* visualY; ///< The visual 'y' position for each test.
63 CharacterIndex* logicalIndex; ///< The expected logical cursor index for each test.
66 bool GetClosestLineTest( const GetClosestLineData& data )
68 std::cout << " testing : " << data.description << std::endl;
70 // 1) Create the model.
71 LogicalModelPtr logicalModel;
72 VisualModelPtr visualModel;
74 Size textArea(400.f, 600.f);
77 Vector<FontDescriptionRun> fontDescriptionRuns;
78 LayoutOptions options;
79 CreateTextModel( data.text,
88 for( unsigned int index = 0u; index < data.numberOfTests; ++index )
90 const LineIndex lineIndex = GetClosestLine( visualModel,
91 data.visualY[index] );
93 if( lineIndex != data.lineIndex[index] )
95 std::cout << " test " << index << " failed. Different line index : " << lineIndex << ", expected : " << data.lineIndex[index] << std::endl;
103 bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data )
105 std::cout << " testing : " << data.description << std::endl;
107 // 1) Create the model.
108 LogicalModelPtr logicalModel;
109 VisualModelPtr visualModel;
111 Size textArea(400.f, 600.f);
114 Vector<FontDescriptionRun> fontDescriptionRuns;
115 LayoutOptions options;
116 CreateTextModel( data.text,
125 for( unsigned int index = 0u; index < data.numberOfTests; ++index )
127 const CharacterIndex logicalCursorIndex = GetClosestCursorIndex( visualModel,
131 data.visualY[index] );
133 if( logicalCursorIndex != data.logicalIndex[index] )
135 std::cout << " test " << index << " failed. Different logical cursor index : " << logicalCursorIndex << ", expected : " << data.logicalIndex[index] << std::endl;
145 //////////////////////////////////////////////////////////
147 // UtcDaliGetClosestLine
148 // UtcDaliGetClosestCursorIndex
150 //////////////////////////////////////////////////////////
152 int UtcDaliGetClosestLine(void)
154 tet_infoline(" UtcDaliGetClosestLine");
156 float visualY01[] = { -4.f, 3.f, 1000.f };
157 LineIndex lineIndices01[] = { 0u, 0u, 0u };
159 float visualY02[] = { -4.f, 3.f, 1000.f };
160 LineIndex lineIndices02[] = { 0u, 0u, 0u };
162 float visualY03[] = { -4.f, 11.f, 30.f, 51.f, 68.f, 87.f, 109.f, 130.f };
163 LineIndex lineIndices03[] = { 0u, 0u, 1u, 2u, 3u, 4u, 5u, 5u };
165 struct GetClosestLineData data[] =
183 "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
184 "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
185 "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
186 "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
187 "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
188 "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
194 const unsigned int numberOfTests = 3u;
196 for( unsigned int index = 0u; index < numberOfTests; ++index )
198 ToolkitTestApplication application;
199 if( !GetClosestLineTest( data[index] ) )
201 tet_result(TET_FAIL);
205 tet_result(TET_PASS);
209 int UtcDaliGetClosestCursorIndex(void)
211 tet_infoline(" UtcDaliGetClosestCursorIndex");
212 float visualX01[] = { -100.f };
213 float visualY01[] = { -100.f };
214 CharacterIndex logicalIndex01[] = { 0u };
216 float visualX02[] = { -100.f, 1000.f, 60.f, 79.f, 83.f, 148.f, 99.f };
217 float visualY02[] = { -100.f, 1000.f, 12.f, 12.f, 12.f, 12.f, 12.f };
218 CharacterIndex logicalIndex02[] = { 0u, 21u, 7u, 10u, 11u, 13u, 20u };
220 float visualX03[] = { 19.f, 104.f, -2.f, 127.f };
221 float visualY03[] = { 12.f, 12.f, 12.f, 12.f };
222 CharacterIndex logicalIndex03[] = { 3u, 12u, 0u, 18u };
229 // different الأربعاء \n
230 float visualX04[] = { -100.f, 40.f, 44.f, 85.f, 500.f,
231 500.f, 367.f, 359.f, 329.f, -100.f,
232 -100.f, 19.f, 64.f, 72.f, 104.f, 111.f, 500.f};
233 float visualY04[] = { -100.f, 12.f, 12.f, 12.f, 12.f,
234 30.f, 30.f, 30.f, 30.f, 30.f,
235 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f };
236 CharacterIndex logicalIndex04[] = { 0u, 5u, 6u, 11u, 11u,
237 12u, 16u, 17u, 21u, 21u,
238 22u, 25u, 31u, 32u, 34u, 40u, 40u,
242 // abcשנבdefג קכghiעיןjk lחלךmnoצמם pqrפרףstuד אוvwxה
244 // סתyz טזץabcשנבd efגקכghiעי ןjklחלךmno צמםpqrפרףstuד
245 // 93 100 110 120 130 139
246 // אוvwxהס תyzטזץabcש נבdefגקכgh iעיןjklחלך mnoצמםpqr
247 // 139 150 160 170 180 186
248 // פרףstuדאוvw xהסתyzטזץa bcשנבdefגק כghiעיןjkl חלךmno
249 // 186 190 200 210 220 233
250 // צמםp qrפרףstuדא וvwxהסתyzט זץabcשנבde fגקכghiעיןjkl
251 // 233 240 250 260 265
252 // חלךmnoצ מםpqrפרףst uדאוvwxהסת yzטזץ
254 float visualX05[] = { -100.f, 96.f, 155.f, 250.f, 344.f, 500.f,
255 -100.f, 36.f, 124.f, 190.f, 280.f, 500.f,
256 -100.f, 56.f, 158.f, 237.f, 303.f, 500.f,
257 -100.f, 98.f, 184.f, 261.f, 337.f, 500.f,
258 -100.f, 40.f, 113.f, 223.f, 302.f, 500.f,
259 -100.f, 82.f, 160.f, 253.f, 500.f };
260 float visualY05[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
261 30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
262 50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
263 67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
264 87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
265 107.f, 107.f, 107.f, 107.f, 107.f };
266 CharacterIndex logicalIndex05[] = { 0u, 10u, 20u, 30u, 40u, 45u,
267 46u, 50u, 60u, 70u, 80u, 92u,
268 93u, 100u, 110u, 120u, 130u, 138u,
269 139u, 150u, 160u, 170u, 180u, 185u,
270 186u, 190u, 200u, 210u, 220u, 232u,
271 233u, 240u, 250u, 260u, 265u };
274 // שנבabcגקכd efעיןghiחל ךjklצמםmno פרףpqrדאוs tuהסתv
276 // wxטז ץyzשנבabcג קכdefעיןgh iחלךjklצמם mnoפרףpqrדאוs
277 // 93 100 110 120 130 139
278 // tuהסתvw xטזץyzשנבa bcגקכdefעי ןghiחלךjkl צמםmnoפרף
279 // 139 150 160 170 180 186
280 // pqrדאוstuהס תvwxטזץyzש נבabcגקכde fעיןghiחלך jklצמם
281 // 186 190 200 210 220 232
282 // mnoפ רףpqrדאוst uהסתvwxטזץ yzשנבabcגק כdefעיןghiחל
283 // 232 240 250 260 265
284 // ךjklצמםm noפרףpqrדא וstuהסתvwx טזץyz
286 float visualX06[] = { 500.f, 307.f, 237.f, 148.f, 55.f, -100.f,
287 500.f, 362.f, 276.f, 213.f, 121.f, -100.f,
288 500.f, 344.f, 238.f, 167.f, 93.f, -100.f,
289 500.f, 306.f, 216.f, 142.f, 58.f, -100.f,
290 500.f, 355.f, 279.f, 182.f, 92.f, -100.f,
291 500.f, 326.f, 238.f, 150.f, -100.f };
292 float visualY06[] = { -100.f, 12.f, 12.f, 12.f, 12.f, 12.f,
293 30.f, 30.f, 30.f, 30.f, 30.f, 30.f,
294 50.f, 50.f, 50.f, 50.f, 50.f, 50.f,
295 67.f, 67.f, 67.f, 67.f, 67.f, 67.f,
296 87.f, 87.f, 87.f, 87.f, 87.f, 87.f,
297 107.f, 107.f, 107.f, 107.f, 107.f };
298 CharacterIndex logicalIndex06[] = { 0u, 10u, 20u, 30u, 40u, 45u,
299 46u, 50u, 60u, 70u, 80u, 92u,
300 93u, 100u, 110u, 120u, 130u, 138u,
301 139u, 150u, 160u, 170u, 180u, 185u,
302 186u, 190u, 200u, 210u, 220u, 231u,
303 232u, 240u, 250u, 260u, 265u };
305 struct GetClosestCursorIndexData data[] =
317 "Hello world שלום עולם",
324 "Single line with ligatures",
325 "different الأربعاء",
332 "Multiline. Single line paragraphs",
335 "different الأربعاء\n",
342 "Multiline. Single bidirectional paragraph, starts LTR, wrapped lines",
343 "abcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuדאוvwxה"
344 "סתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqrפרףstuד"
345 "אוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmnoצמםpqr"
346 "פרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjklחלךmno"
347 "צמםpqrפרףstuדאוvwxהסתyzטזץabcשנבdefגקכghiעיןjkl"
348 "חלךmnoצמםpqrפרףstuדאוvwxהסתyzטזץ",
355 "Multiline. Single bidirectional paragraph, starts RTL, wrapped lines",
356 "שנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוstuהסתv"
357 "wxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרףpqrדאוs"
358 "tuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמםmnoפרף"
359 "pqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחלךjklצמם"
360 "mnoפרףpqrדאוstuהסתvwxטזץyzשנבabcגקכdefעיןghiחל"
361 "ךjklצמםmnoפרףpqrדאוstuהסתvwxטזץyz",
368 const unsigned int numberOfTests = 6u;
370 for( unsigned int index = 0u; index < numberOfTests; ++index )
372 ToolkitTestApplication application;
373 if( !GetClosestCursorIndexTest( data[index] ) )
375 tet_result(TET_FAIL);
379 tet_result(TET_PASS);