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/dali-toolkit.h>
24 #include <toolkit-text-model.h>
28 using namespace Toolkit;
31 // Tests the following functions.
33 // void SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo,
34 // Length numberOfRuns,
35 // CharacterIndex startIndex )
38 //////////////////////////////////////////////////////////
43 struct SetVisualToLogicalMapData
45 std::string description; ///< Description of the test.
46 std::string text; ///< Input text.
47 unsigned int startIndex; ///< The start index from where the visual to logical conversion table is set.
48 unsigned int numberOfCharacters; ///< The number of characters to set.
49 Size textArea; ///< The size of the area where the text is laid-out.
50 unsigned int expectedNumberOfCharacters; ///< The expected number of characters.
51 unsigned int* visualToLogical; ///< The expected visual to logical conversion table.
54 bool SetVisualToLogicalMapTest( const SetVisualToLogicalMapData& data )
56 std::cout << " testing : " << data.description << std::endl;
58 LogicalModelPtr logicalModel = LogicalModel::New();
59 VisualModelPtr visualModel = VisualModel::New();
62 // Create the model with the whole text.
63 const Vector<FontDescriptionRun> fontDescriptions;
64 const LayoutOptions options;
65 CreateTextModel( data.text,
73 // Get the visual to logical map.
74 Vector<CharacterIndex>& visualToLogicalMap = logicalModel->mVisualToLogicalMap;
76 // Compare the results.
77 if( data.expectedNumberOfCharacters != visualToLogicalMap.Count() )
79 std::cout << " differetn number of characters : " << visualToLogicalMap.Count() << ", expected : " << data.expectedNumberOfCharacters << std::endl;
83 for( unsigned int index = 0u; index < data.expectedNumberOfCharacters; ++index )
85 if( data.visualToLogical[index] != visualToLogicalMap[index] )
87 std::cout << " different visualToLogical table : " << std::endl;
88 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
90 std::cout << visualToLogicalMap[i] << " ";
92 std::cout << std::endl;
93 std::cout << " expected : " << std::endl;
94 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
96 std::cout << data.visualToLogical[i] << " ";
98 std::cout << std::endl;
108 //////////////////////////////////////////////////////////
110 int UtcDaliSetVisualToLogicalMap(void)
112 ToolkitTestApplication application;
113 tet_infoline(" UtcDaliSetVisualToLogicalMap");
115 unsigned int* visualToLogical01 = NULL;
116 unsigned int* visualToLogical02 = NULL;
117 unsigned int visualToLogical03[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
118 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, };
119 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 };
120 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 };
121 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 };
122 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 };
123 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 };
125 struct SetVisualToLogicalMapData data[] =
128 "Zero characters text",
132 Size( 100.f, 300.f ),
137 "Left to right text only",
141 Size( 100.f, 300.f ),
146 "Right to left text only",
150 Size( 100.f, 300.f ),
155 "Mix of left to right and right to left text.",
156 "Hello world, مرحبا بالعالم",
159 Size( 100.f, 300.f ),
164 "Mix of left to right and right to left text.",
165 "Hello world, \nمرحبا بالعالم",
168 Size( 100.f, 300.f ),
173 "Mix of left to right and right to left text.",
174 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
177 Size( 100.f, 300.f ),
182 "Mix of left to right and right to left text. Updates from character index 5",
183 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
186 Size( 100.f, 300.f ),
191 "Mix of left to right and right to left text. Updates from character index 39",
192 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
195 Size( 100.f, 300.f ),
200 "Mix of left to right and right to left text. Updates from character index 70",
201 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
204 Size( 100.f, 300.f ),
209 const unsigned int numberOfTests = 9u;
211 for( unsigned int index = 0u; index < numberOfTests; ++index )
213 if( !SetVisualToLogicalMapTest( data[index] ) )
215 tet_result(TET_FAIL);
219 tet_result(TET_PASS);