Remove UNSIGNED_INTEGER property type (removed from core)
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-MultiLanguage.cpp
1 /*
2  * Copyright (c) 2015 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 #include <dali-toolkit/internal/text/character-set-conversion.h>
22 #include <dali-toolkit/internal/text/segmentation.h>
23 #include <dali-toolkit/internal/text/multi-language-support.h>
24 #include <dali-toolkit/internal/text/logical-model-impl.h>
25 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
27
28
29 using namespace Dali;
30 using namespace Toolkit;
31 using namespace Text;
32
33 // Tests the following functions with different scripts.
34 // Constructor, destructor and MultilanguageSupport::Get()
35 // void MultilanguageSupport::SetScripts( const Vector<Character>& text, const Vector<LineBreakInfo>& lineBreakInfo, Vector<ScriptRun>& scripts );
36 // void MultilanguageSupport::ValidateFonts( const Vector<Character>& text, const Vector<ScriptRun>& scripts, Vector<FontRun>& fonts );
37
38 //////////////////////////////////////////////////////////
39
40 namespace
41 {
42
43 struct ScriptsData
44 {
45   std::string description;      ///< Description of the experiment.
46   std::string text;             ///< Input text.
47   Vector<ScriptRun> scriptRuns; ///< Expected script runs.
48 };
49
50 struct ValidateFontsData
51 {
52   std::string description;  ///< Description of the experiment.
53   std::string text;         ///< Input text.
54 };
55
56 //////////////////////////////////////////////////////////
57
58 bool ScriptsTest( const ScriptsData& data )
59 {
60   MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
61
62   // 1) Convert to utf32
63   Vector<Character> utf32;
64   utf32.Resize( data.text.size() );
65
66   const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
67                                                    data.text.size(),
68                                                    &utf32[0u] );
69   utf32.Resize( numberOfCharacters );
70
71   // 2) Set the line break info.
72   Vector<LineBreakInfo> lineBreakInfo;
73   lineBreakInfo.Resize( numberOfCharacters );
74
75   SetLineBreakInfo( utf32, lineBreakInfo );
76
77   // 3) Set the script info.
78   Vector<ScriptRun> scripts;
79   multilanguageSupport.SetScripts( utf32,
80                                    lineBreakInfo,
81                                    scripts );
82
83   // 4) Compare the results.
84
85   if( scripts.Count() != data.scriptRuns.Count() )
86   {
87     tet_infoline("ScriptsTest: different number of scripts.");
88     return false;
89   }
90
91   for( unsigned int index = 0u; index < scripts.Count(); ++index )
92   {
93     const ScriptRun& scriptRun1 = scripts[index];
94     const ScriptRun& scriptRun2 = data.scriptRuns[index];
95
96     if( scriptRun1.characterRun.characterIndex != scriptRun2.characterRun.characterIndex )
97     {
98       tet_infoline("ScriptsTest: different character index.");
99       return false;
100     }
101
102     if( scriptRun1.characterRun.numberOfCharacters != scriptRun2.characterRun.numberOfCharacters )
103     {
104       tet_infoline("ScriptsTest: different number of characters.");
105       return false;
106     }
107
108     if( scriptRun1.script != scriptRun2.script )
109     {
110       tet_infoline("ScriptsTest: different script.");
111       return false;
112     }
113   }
114
115   return true;
116 }
117
118 bool ValidateFontTest( const ValidateFontsData& data )
119 {
120   MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
121
122   // 1) Convert to utf32
123   Vector<Character> utf32;
124   utf32.Resize( data.text.size() );
125
126   const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
127                                                    data.text.size(),
128                                                    &utf32[0u] );
129   utf32.Resize( numberOfCharacters );
130
131   // 2) Set the line break info.
132   Vector<LineBreakInfo> lineBreakInfo;
133   lineBreakInfo.Resize( numberOfCharacters );
134
135   SetLineBreakInfo( utf32, lineBreakInfo );
136
137   // 3) Set the script info.
138   Vector<ScriptRun> scripts;
139   multilanguageSupport.SetScripts( utf32,
140                                    lineBreakInfo,
141                                    scripts );
142
143   Vector<FontRun> fonts;
144   // 4) Validate the fonts
145   multilanguageSupport.ValidateFonts( utf32,
146                                       scripts,
147                                       fonts );
148
149   return true;
150 }
151
152 } // namespace
153
154 int UtcDaliTextMultiLanguageConstructor(void)
155 {
156   ToolkitTestApplication application;
157   tet_infoline(" UtcDaliTextMultiLanguageConstructor");
158
159   MultilanguageSupport multilanguageSupport;
160   DALI_TEST_CHECK( !multilanguageSupport );
161
162   MultilanguageSupport multilanguageSupport1 = MultilanguageSupport::Get();
163   DALI_TEST_CHECK( multilanguageSupport1 );
164
165   // To increase coverage.
166   MultilanguageSupport multilanguageSupport2 = MultilanguageSupport::Get();
167   DALI_TEST_CHECK( multilanguageSupport2 );
168
169   DALI_TEST_CHECK( multilanguageSupport1 == multilanguageSupport2 );
170
171   tet_result(TET_PASS);
172   END_TEST;
173 }
174
175 int UtcDaliTextMultiLanguageSetScripts(void)
176 {
177   ToolkitTestApplication application;
178   tet_infoline(" UtcDaliTextMultiLanguageSetScripts" );
179
180   // Void text.
181   Vector<ScriptRun> scriptRuns00;
182
183   // Hello world.
184   Vector<ScriptRun> scriptRuns01;
185   ScriptRun scriptRun0100 =
186   {
187     0u,
188     11u,
189     TextAbstraction::LATIN
190   };
191   scriptRuns01.PushBack( scriptRun0100 );
192
193   const ScriptsData data[] =
194   {
195     {
196       "void text",
197       "",
198       scriptRuns00,
199     },
200     {
201       "Easy latin script",
202       "Hello world",
203       scriptRuns01,
204     },
205   };
206   const unsigned int numberOfTests = 2u;
207
208   for( unsigned int index = 0u; index < numberOfTests; ++index )
209   {
210     if( !ScriptsTest( data[index] ) )
211     {
212       tet_result(TET_FAIL);
213     }
214   }
215
216   tet_result(TET_PASS);
217   END_TEST;
218 }
219
220 int UtcDaliTextMultiLanguageValidateFonts01(void)
221 {
222   ToolkitTestApplication application;
223   tet_infoline(" UtcDaliTextMultiLanguageValidateFonts");
224
225   const ValidateFontsData data[] =
226   {
227     {
228       "void text",
229       "",
230     },
231     {
232       "Easy latin script",
233       "Hello world",
234     },
235   };
236   const unsigned int numberOfTests = 2u;
237
238   for( unsigned int index = 0u; index < numberOfTests; ++index )
239   {
240     if( !ValidateFontTest( data[index] ) )
241     {
242       tet_result(TET_FAIL);
243     }
244   }
245
246   tet_result(TET_PASS);
247   END_TEST;
248 }