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 CreateTextModel( data.text,
69 // Get the visual to logical map.
70 Vector<CharacterIndex>& visualToLogicalMap = logicalModel->mVisualToLogicalMap;
72 // Compare the results.
73 if( data.expectedNumberOfCharacters != visualToLogicalMap.Count() )
75 std::cout << " differetn number of characters : " << visualToLogicalMap.Count() << ", expected : " << data.expectedNumberOfCharacters << std::endl;
79 for( unsigned int index = 0u; index < data.expectedNumberOfCharacters; ++index )
81 if( data.visualToLogical[index] != visualToLogicalMap[index] )
83 std::cout << " different visualToLogical table : " << std::endl;
84 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
86 std::cout << visualToLogicalMap[i] << " ";
88 std::cout << std::endl;
89 std::cout << " expected : " << std::endl;
90 for( unsigned int i = 0; i < data.expectedNumberOfCharacters; ++i )
92 std::cout << data.visualToLogical[i] << " ";
94 std::cout << std::endl;
104 //////////////////////////////////////////////////////////
106 int UtcDaliSetVisualToLogicalMap(void)
108 ToolkitTestApplication application;
109 tet_infoline(" UtcDaliSetVisualToLogicalMap");
111 unsigned int* visualToLogical01 = NULL;
112 unsigned int* visualToLogical02 = NULL;
113 unsigned int visualToLogical03[] = { 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u };
114 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, };
115 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 };
116 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 };
117 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 };
118 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 };
119 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 };
121 struct SetVisualToLogicalMapData data[] =
124 "Zero characters text",
128 Size( 100.f, 300.f ),
133 "Left to right text only",
137 Size( 100.f, 300.f ),
142 "Right to left text only",
146 Size( 100.f, 300.f ),
151 "Mix of left to right and right to left text.",
152 "Hello world, مرحبا بالعالم",
155 Size( 100.f, 300.f ),
160 "Mix of left to right and right to left text.",
161 "Hello world, \nمرحبا بالعالم",
164 Size( 100.f, 300.f ),
169 "Mix of left to right and right to left text.",
170 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
173 Size( 100.f, 300.f ),
178 "Mix of left to right and right to left text. Updates from character index 5",
179 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
182 Size( 100.f, 300.f ),
187 "Mix of left to right and right to left text. Updates from character index 39",
188 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
191 Size( 100.f, 300.f ),
196 "Mix of left to right and right to left text. Updates from character index 70",
197 "Hello world, مرحبا بالعالم, hello world\nمرحبا بالعالم, hello world, مرحبا بالعالم\nمرحبا بالعالم\nhello world",
200 Size( 100.f, 300.f ),
205 const unsigned int numberOfTests = 9u;
207 for( unsigned int index = 0u; index < numberOfTests; ++index )
209 if( !SetVisualToLogicalMapTest( data[index] ) )
211 tet_result(TET_FAIL);
215 tet_result(TET_PASS);