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/text-run-container.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-model.h>
29 using namespace Toolkit;
32 // Tests the following functions.
34 // void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
35 // Length numberOfRuns,
36 // CharacterIndex startIndex )
39 //////////////////////////////////////////////////////////
43 struct CreateParagraphData
45 std::string description; ///< Description of the test.
46 std::string text; ///< Input text.
47 CharacterIndex index; ///< The first character index.
48 Length numberOfCharacters; ///< The number of characters.
49 unsigned int numberOfParagraphs; ///< The expected number of paragraphs.
50 unsigned int* indices; ///< The expected paragraph info indices.
51 unsigned int* numberOfCharactersPerParagraph; ///< The expected number of characters of each paragraph.
54 struct FindParagraphData
56 std::string description; ///< Description of the test.
57 std::string text; ///< Input text.
58 CharacterIndex index; ///< The first character index.
59 Length numberOfCharacters; ///< The number of characters.
60 unsigned int numberOfParagraphs; ///< The expected number of paragraphs.
61 unsigned int* paragraphs; ///< The expected paragraph info.
64 struct SetVisualToLogicalMapData
66 std::string description; ///< Description of the test.
67 std::string text; ///< Input text.
68 unsigned int startIndex; ///< The start index from where the visual to logical conversion table is set.
69 unsigned int numberOfCharacters; ///< The number of characters to set.
70 Size textArea; ///< The size of the area where the text is laid-out.
71 unsigned int expectedNumberOfCharacters; ///< The expected number of characters.
72 unsigned int* visualToLogical; ///< The expected visual to logical conversion table.
75 bool CreateParagraphTest( const CreateParagraphData& data )
77 // 1) Create the model.
78 LogicalModelPtr logicalModel = LogicalModel::New();
79 VisualModelPtr visualModel = VisualModel::New();
80 Size textArea(100.f, 60.f);
83 Vector<FontDescriptionRun> fontDescriptionRuns;
84 LayoutOptions options;
85 CreateTextModel( data.text,
93 // 2) Clear the paragraphs.
94 Vector<ParagraphRun>& paragraphs = logicalModel->mParagraphInfo;
95 ClearCharacterRuns( data.index,
96 data.index + data.numberOfCharacters - 1u,
99 // 3) Call the LogicalModel::CreateParagraphInfo() method
100 logicalModel->CreateParagraphInfo( data.index,
101 data.numberOfCharacters );
103 // 4) Compare the results.
104 if( data.numberOfParagraphs != paragraphs.Count() )
106 std::cout << " Different number of paragraphs : " << paragraphs.Count() << ", expected : " << data.numberOfParagraphs << std::endl;
110 unsigned int index = 0u;
111 for( Vector<ParagraphRun>::ConstIterator it = paragraphs.Begin(),
112 endIt = paragraphs.End();
116 const ParagraphRun& paragraph( *it );
118 if( data.indices[index] != paragraph.characterRun.characterIndex )
120 std::cout << " Different character index for paragraph : " << index << ", " << paragraph.characterRun.characterIndex << ", expected : " << data.indices[index] << std::endl;
123 if( data.numberOfCharactersPerParagraph[index] != paragraph.characterRun.numberOfCharacters )
125 std::cout << " Different number of characters for paragraph : " << index << ", " << paragraph.characterRun.numberOfCharacters << ", expected : " << data.numberOfCharactersPerParagraph[index] << std::endl;
133 bool FindParagraphTest( const FindParagraphData& data )
135 // 1) Create the model.
136 LogicalModelPtr logicalModel = LogicalModel::New();
137 VisualModelPtr visualModel = VisualModel::New();
138 Size textArea(100.f, 60.f);
141 Vector<FontDescriptionRun> fontDescriptionRuns;
142 LayoutOptions options;
143 CreateTextModel( data.text,
151 // 2) Find the paragraphs.
152 Vector<ParagraphRunIndex> paragraphs;
153 logicalModel->FindParagraphs( data.index, data.numberOfCharacters, paragraphs );
155 // 3) compare the results.
156 if( data.numberOfParagraphs != paragraphs.Count() )
161 unsigned int index = 0u;
162 for( Vector<ParagraphRunIndex>::ConstIterator it = paragraphs.Begin(),
163 endIt = paragraphs.End();
167 const ParagraphRunIndex paragraphIndex = *it;
169 if( paragraphIndex != data.paragraphs[index] )
178 bool SetVisualToLogicalMapTest( const SetVisualToLogicalMapData& data )
180 std::cout << " testing : " << data.description << std::endl;
182 LogicalModelPtr logicalModel = LogicalModel::New();
183 VisualModelPtr visualModel = VisualModel::New();
186 // Create the model with the whole text.
187 const Vector<FontDescriptionRun> fontDescriptions;
188 const LayoutOptions options;
189 CreateTextModel( data.text,
197 // Get the visual to logical map.
198 Vector<CharacterIndex>& visualToLogicalMap = logicalModel->mVisualToLogicalMap;
200 // Compare the results.
201 if( data.expectedNumberOfCharacters != visualToLogicalMap.Count() )
203 std::cout << " differetn number of characters : " << visualToLogicalMap.Count() << ", expected : " << data.expectedNumberOfCharacters << std::endl;
207 for( unsigned int index = 0u; index < data.expectedNumberOfCharacters; ++index )
209 if( data.visualToLogical[index] != visualToLogicalMap[index] )
211 std::cout << " different visualToLogical table : " << std::endl;
212 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
214 std::cout << visualToLogicalMap[i] << " ";
216 std::cout << std::endl;
217 std::cout << " expected : " << std::endl;
218 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
220 std::cout << data.visualToLogical[i] << " ";
222 std::cout << std::endl;
232 //////////////////////////////////////////////////////////
234 // UtcDaliCreateParagraph
235 // UtcDaliFindParagraph
236 // UtcDaliSetVisualToLogicalMap
238 //////////////////////////////////////////////////////////
240 int UtcDaliCreateParagraph(void)
242 ToolkitTestApplication application;
243 tet_infoline(" UtcDaliCreateParagraph");
245 unsigned int paragraphsIndices01[] = { 0u };
246 unsigned int paragraphsNumberOfCharacters01[] = { 0u };
247 unsigned int paragraphsIndices02[] = { 0u, 12u, 17u };
248 unsigned int paragraphsNumberOfCharacters02[] = { 12u, 5u, 1u };
249 unsigned int paragraphsIndices03[] = { 0u, 12u, 17u, 34u };
250 unsigned int paragraphsNumberOfCharacters03[] = { 12u, 5u, 17u ,1u };
252 struct CreateParagraphData data[] =
261 paragraphsNumberOfCharacters01,
265 "Hello world\ndemo\n\n",
270 paragraphsNumberOfCharacters02,
273 "Some paragraphs. Update the initial paragraphs.",
274 "Hello world\ndemo\nhello world demo\n\n",
279 paragraphsNumberOfCharacters03,
282 "Some paragraphs. Update the mid paragraphs.",
283 "Hello world\ndemo\nhello world demo\n\n",
288 paragraphsNumberOfCharacters03,
291 "Some paragraphs. Update the final paragraphs.",
292 "Hello world\ndemo\nhello world demo\n\n",
297 paragraphsNumberOfCharacters03,
300 const unsigned int numberOfTests = 5u;
302 for( unsigned int index = 0u; index < numberOfTests; ++index )
304 // ToolkitTestApplication application;
305 if( !CreateParagraphTest( data[index] ) )
307 tet_result(TET_FAIL);
311 tet_result(TET_PASS);
315 int UtcDaliFindParagraph(void)
317 tet_infoline(" UtcDaliFindParagraph");
319 unsigned int paragraphs01[] = {};
320 unsigned int paragraphs02[] = { 0u, 1u, 2u };
321 unsigned int paragraphs03[] = { 0u };
322 unsigned int paragraphs04[] = { 1u };
323 unsigned int paragraphs05[] = { 0u, 1u, 2u };
325 struct FindParagraphData data[] =
337 "Hello world\ndemo\n\n",
345 "Hello world\ndemo\n\n",
353 "Hello world\ndemo\n\n",
361 "Hello world\ndemo\n\n",
368 const unsigned int numberOfTests = 5u;
370 for( unsigned int index = 0u; index < numberOfTests; ++index )
372 ToolkitTestApplication application;
373 if( !FindParagraphTest( data[index] ) )
375 tet_result(TET_FAIL);
379 tet_result(TET_PASS);
383 int UtcDaliSetVisualToLogicalMap(void)
385 tet_infoline(" UtcDaliSetVisualToLogicalMap");
387 unsigned int* visualToLogical01 = NULL;
388 unsigned int* visualToLogical02 = NULL;
389 unsigned int visualToLogical03[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
390 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, };
391 unsigned int visualToLogical05[] = { 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u, 26u, 25u, 24u, 23u, 22u, 21u, 20u, 19u, 18u, 17u, 16u, 15u, 14u };
392 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 };
393 unsigned int visualToLogical07[] = { 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 };
394 unsigned int visualToLogical08[] = { 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 };
395 unsigned int visualToLogical09[] = { 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 };
397 struct SetVisualToLogicalMapData data[] =
400 "Zero characters text",
404 Size( 100.f, 300.f ),
409 "Left to right text only",
413 Size( 100.f, 300.f ),
418 "Right to left text only",
422 Size( 100.f, 300.f ),
427 "Mix of left to right and right to left text.",
428 "Hello world, مرحبا بالعالم",
431 Size( 100.f, 300.f ),
436 "Mix of left to right and right to left text.",
437 "Hello world, \nمرحبا بالعالم",
440 Size( 100.f, 300.f ),
445 "Mix of left to right and right to left text.",
446 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
449 Size( 100.f, 300.f ),
454 "Mix of left to right and right to left text. Updates from character index 5",
455 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
458 Size( 100.f, 300.f ),
463 "Mix of left to right and right to left text. Updates from character index 39",
464 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
467 Size( 100.f, 300.f ),
472 "Mix of left to right and right to left text. Updates from character index 70",
473 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
476 Size( 100.f, 300.f ),
481 const unsigned int numberOfTests = 9u;
483 for( unsigned int index = 0u; index < numberOfTests; ++index )
485 ToolkitTestApplication application;
486 if( !SetVisualToLogicalMapTest( data[index] ) )
488 tet_result(TET_FAIL);
492 tet_result(TET_PASS);