Convert the Underline and Shadow deprecated APIs to the new ones.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-Markup.cpp
1 /*
2  * Copyright (c) 2016 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 <limits>
22
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-model.h>
26 #include <dali-toolkit/internal/text/markup-processor.h>
27 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
28 #include <dali-toolkit/internal/text/color-run.h>
29 #include <dali-toolkit/internal/text/font-description-run.h>
30 #include <dali-toolkit/internal/text/text-definitions.h>
31 #include <dali-toolkit/internal/text/text-io.h>
32
33 using namespace Dali;
34 using namespace Toolkit;
35 using namespace Text;
36
37 namespace
38 {
39   ///////////////////////////////////////////////////////////
40
41   struct TokenComparisonData
42   {
43     std::string description;
44     std::string string1; ///< must be in lower case!!!!
45     std::string string2;
46     bool expectedResult;
47   };
48
49   bool TokenComparisonTest( const TokenComparisonData& data )
50   {
51     std::cout << "  testing " << data.description << std::endl;
52
53     const bool result = TokenComparison( data.string1,
54                                          data.string2.c_str(),
55                                          data.string2.size() );
56
57     if( result != data.expectedResult )
58     {
59       std::cout << "  different conparison result : " << result << ", expected : " << data.expectedResult << std::endl;
60       std::cout << "  comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl;
61
62       return false;
63     }
64
65     return true;
66   }
67
68   ///////////////////////////////////////////////////////////
69
70   struct ColorStringToVector4Data
71   {
72     std::string description;
73     std::string colorStr;
74     Vector4 expectedColor;
75   };
76
77   bool ColorStringToVector4Test( const ColorStringToVector4Data& data )
78   {
79     std::cout << "  testing " << data.description << std::endl;
80
81     Vector4 color;
82     ColorStringToVector4( data.colorStr.c_str(), data.colorStr.size(), color );
83
84     if( color != data.expectedColor )
85     {
86       std::cout << "  different color : " << color << ", expected : " << data.expectedColor << std::endl;
87       return false;
88     }
89
90     return true;
91   }
92
93   ///////////////////////////////////////////////////////////
94
95   struct Vector4ToColorStringData
96   {
97     std::string description;
98     Vector4 color;
99     std::string expectedColorStr;
100   };
101
102   bool Vector4ToColorStringTest( const Vector4ToColorStringData& data )
103   {
104     std::cout << "  testing " << data.description << std::endl;
105
106     std::string colorStr;
107     Vector4ToColorString( data.color, colorStr );
108
109     if( colorStr != data.expectedColorStr )
110     {
111       std::cout << "  different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl;
112       return false;
113     }
114
115     return true;
116   }
117
118   ///////////////////////////////////////////////////////////
119
120   struct StringToVector2Data
121   {
122     std::string description;
123     std::string vector2Str;
124     Vector2 expectedVector2;
125   };
126
127   bool StringToVector2Test( const StringToVector2Data& data )
128   {
129     std::cout << "  testing " << data.description << std::endl;
130
131     Vector2 vector2;
132     StringToVector2( data.vector2Str.c_str(), data.vector2Str.size(), vector2 );
133
134     if( vector2 != data.expectedVector2 )
135     {
136       std::cout << "  different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl;
137       return false;
138     }
139
140     return true;
141   }
142
143   ///////////////////////////////////////////////////////////
144
145
146   struct Vector2ToStringData
147   {
148     std::string description;
149     Vector2 vector2;
150     std::string expectedVector2Str;
151   };
152
153   bool Vector2ToStringTest( const Vector2ToStringData& data )
154   {
155     std::cout << "  testing " << data.description << std::endl;
156
157     std::string vector2Str;
158     Vector2ToString( data.vector2, vector2Str );
159
160     if( vector2Str != data.expectedVector2Str )
161     {
162       std::cout << "  different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
163       return false;
164     }
165
166     return true;
167   }
168
169 } // namespace
170
171 int UtcDaliTextTokenComparison(void)
172 {
173   tet_infoline(" UtcDaliTextTokenComparison");
174
175   const TokenComparisonData data[] =
176   {
177     {
178       "void texts",
179       "",
180       "",
181       true
182     },
183     {
184       "different size text",
185       "hello",
186       "world!",
187       false
188     },
189     {
190       "different texts",
191       "hello",
192       "world",
193       false
194     },
195     {
196       "same texts",
197       "world",
198       "wOrLD",
199       true
200     },
201     {
202       "some punctuation characters, numbers, ...",
203       "hello0123456789.![?]",
204       "Hello0123456789.![?]",
205       true
206     }
207
208   };
209   const unsigned int numberOfTests = 5u;
210
211   for( unsigned int index = 0u; index < numberOfTests; ++index )
212   {
213     ToolkitTestApplication application;
214     if( !TokenComparisonTest( data[index] ) )
215     {
216       tet_result(TET_FAIL);
217     }
218   }
219
220   tet_result(TET_PASS);
221   END_TEST;
222 }
223
224 int UtcDaliTextColorStringToVector4(void)
225 {
226   tet_infoline(" UtcDaliTextColorStringToVector4");
227
228   const ColorStringToVector4Data data[] =
229   {
230     {
231       "black string",
232       "bLack",
233       Color::BLACK
234     },
235     {
236       "white string",
237       "White",
238       Color::WHITE
239     },
240     {
241       "red string",
242       "reD",
243       Color::RED
244     },
245     {
246       "green string",
247       "green",
248       Color::GREEN
249     },
250     {
251       "blue string",
252       "blue",
253       Color::BLUE
254     },
255     {
256       "yellow string",
257       "yeLloW",
258       Color::YELLOW
259     },
260     {
261       "magenta string",
262       "MagEnta",
263       Color::MAGENTA
264     },
265     {
266       "cyan string",
267       "CyaN",
268       Color::CYAN
269     },
270     {
271       "transparent string",
272       "transparent",
273       Color::TRANSPARENT
274     },
275     {
276       "3 component web color",
277       "#F00",
278       Color::RED
279     },
280     {
281       "6 component web color",
282       "#fF0000",
283       Color::RED
284     },
285     {
286       "hex color red (ARGB)",
287       "0xffff0000",
288       Color::RED
289     },
290     {
291       "hex color green (ARGB)",
292       "0xFf00FF00",
293       Color::GREEN
294     },
295     {
296       "undefined color",
297       "undefined",
298       Vector4::ZERO
299     },
300   };
301   const unsigned int numberOfTests = 14u;
302
303   for( unsigned int index = 0u; index < numberOfTests; ++index )
304   {
305     ToolkitTestApplication application;
306     if( !ColorStringToVector4Test( data[index] ) )
307     {
308       tet_result(TET_FAIL);
309     }
310   }
311
312   tet_result(TET_PASS);
313   END_TEST;
314 }
315
316 int UtcDaliTextVector4ToColorString(void)
317 {
318   tet_infoline(" UtcDaliTextVector4ToColorString");
319
320   const Vector4ToColorStringData data[] =
321   {
322     {
323       "black color",
324       Color::BLACK,
325       "black"
326     },
327     {
328       "white string",
329       Color::WHITE,
330       "white"
331     },
332     {
333       "red string",
334       Color::RED,
335       "red"
336     },
337     {
338       "green string",
339       Color::GREEN,
340       "green"
341     },
342     {
343       "blue string",
344       Color::BLUE,
345       "blue"
346     },
347     {
348       "yellow string",
349       Color::YELLOW,
350       "yellow"
351     },
352     {
353       "magenta string",
354       Color::MAGENTA,
355       "magenta",
356     },
357     {
358       "cyan string",
359       Color::CYAN,
360       "cyan"
361     },
362     {
363       "transparent string",
364       Color::TRANSPARENT,
365       "transparent"
366     },
367     {
368       "hex color",
369       Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
370       "0xff667f99"
371     },
372   };
373   const unsigned int numberOfTests = 10u;
374
375   for( unsigned int index = 0u; index < numberOfTests; ++index )
376   {
377     ToolkitTestApplication application;
378     if( !Vector4ToColorStringTest( data[index] ) )
379     {
380       tet_result(TET_FAIL);
381     }
382   }
383
384   tet_result(TET_PASS);
385   END_TEST;
386 }
387
388 int UtcDaliTextStringToVector2(void)
389 {
390   tet_infoline(" UtcDaliTextStringToVector2");
391   const StringToVector2Data data[] =
392   {
393     {
394       "void text",
395       "",
396       Vector2::ZERO
397     },
398     {
399       "zero zero",
400       "0 0",
401       Vector2::ZERO
402     },
403     {
404       "five four",
405       "5 4",
406       Vector2(5.f, 4.f)
407     }
408   };
409   const unsigned int numberOfTests = 3u;
410
411   for( unsigned int index = 0u; index < numberOfTests; ++index )
412   {
413     ToolkitTestApplication application;
414     if( !StringToVector2Test( data[index] ) )
415     {
416       tet_result(TET_FAIL);
417     }
418   }
419
420   tet_result(TET_PASS);
421   END_TEST;
422 }
423
424 int UtcDaliTextVector2ToString(void)
425 {
426   tet_infoline(" UtcDaliTextVector2ToString");
427   const Vector2ToStringData data[] =
428   {
429     {
430       "zero zero",
431       Vector2::ZERO,
432       "0 0",
433     },
434     {
435       "five four",
436       Vector2(5.f, 4.f),
437       "5 4",
438     }
439   };
440   const unsigned int numberOfTests = 2u;
441
442   for( unsigned int index = 0u; index < numberOfTests; ++index )
443   {
444     ToolkitTestApplication application;
445     if( !Vector2ToStringTest( data[index] ) )
446     {
447       tet_result(TET_FAIL);
448     }
449   }
450
451   tet_result(TET_PASS);
452   END_TEST;
453 }