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.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-utils.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>
34 using namespace Toolkit;
40 ///////////////////////////////////////////////////////////
42 struct TokenComparisonData
44 std::string description;
45 std::string string1; ///< must be in lower case!!!!
50 bool TokenComparisonTest( const TokenComparisonData& data )
52 std::cout << " testing " << data.description << std::endl;
54 const bool result = TokenComparison( data.string1,
56 data.string2.size() );
58 if( result != data.expectedResult )
60 std::cout << " different conparison result : " << result << ", expected : " << data.expectedResult << std::endl;
61 std::cout << " comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl;
69 ///////////////////////////////////////////////////////////
71 struct ColorStringToVector4Data
73 std::string description;
75 Vector4 expectedColor;
78 bool ColorStringToVector4Test( const ColorStringToVector4Data& data )
80 std::cout << " testing " << data.description << std::endl;
83 ColorStringToVector4( data.colorStr.c_str(), data.colorStr.size(), color );
85 if( color != data.expectedColor )
87 std::cout << " different color : " << color << ", expected : " << data.expectedColor << std::endl;
94 ///////////////////////////////////////////////////////////
96 struct Vector4ToColorStringData
98 std::string description;
100 std::string expectedColorStr;
103 bool Vector4ToColorStringTest( const Vector4ToColorStringData& data )
105 std::cout << " testing " << data.description << std::endl;
107 std::string colorStr;
108 Vector4ToColorString( data.color, colorStr );
110 if( colorStr != data.expectedColorStr )
112 std::cout << " different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl;
119 ///////////////////////////////////////////////////////////
121 struct StringToVector2Data
123 std::string description;
124 std::string vector2Str;
125 Vector2 expectedVector2;
128 bool StringToVector2Test( const StringToVector2Data& data )
130 std::cout << " testing " << data.description << std::endl;
133 StringToVector2( data.vector2Str.c_str(), data.vector2Str.size(), vector2 );
135 if( vector2 != data.expectedVector2 )
137 std::cout << " different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl;
144 ///////////////////////////////////////////////////////////
147 struct Vector2ToStringData
149 std::string description;
151 std::string expectedVector2Str;
154 bool Vector2ToStringTest( const Vector2ToStringData& data )
156 std::cout << " testing " << data.description << std::endl;
158 std::string vector2Str;
159 Vector2ToString( data.vector2, vector2Str );
161 if( vector2Str != data.expectedVector2Str )
163 std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
170 ///////////////////////////////////////////////////////////
173 struct XHTMLEntityToUTF8Data
175 std::string description;
176 std::string xHTMLEntityString;
177 std::string expectedString;
180 bool XHTMLEntityToUTF8Test( const XHTMLEntityToUTF8Data& data )
182 std::cout << " testing " << data.description << std::endl;
184 Vector<ColorRun> colorRuns;
185 Vector<FontDescriptionRun> fontRuns;
186 Vector<EmbeddedItem> items;
187 Vector<Anchor> anchors;
188 MarkupProcessData markupProcessData( colorRuns, fontRuns, items, anchors );
189 ProcessMarkupString( data.xHTMLEntityString, markupProcessData );
191 for( Vector<EmbeddedItem>::Iterator it = items.Begin(),
196 EmbeddedItem& item = *it;
201 if( markupProcessData.markupProcessedText != data.expectedString )
203 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
212 int UtcDaliTextTokenComparison(void)
214 tet_infoline(" UtcDaliTextTokenComparison");
216 const TokenComparisonData data[] =
225 "different size text",
243 "some punctuation characters, numbers, ...",
244 "hello0123456789.![?]",
245 "Hello0123456789.![?]",
250 const unsigned int numberOfTests = 5u;
252 for( unsigned int index = 0u; index < numberOfTests; ++index )
254 ToolkitTestApplication application;
255 if( !TokenComparisonTest( data[index] ) )
257 tet_result(TET_FAIL);
261 tet_result(TET_PASS);
265 int UtcDaliTextColorStringToVector4(void)
267 tet_infoline(" UtcDaliTextColorStringToVector4");
269 const ColorStringToVector4Data data[] =
312 "transparent string",
317 "3 component web color",
322 "6 component web color",
327 "hex color red (ARGB)",
332 "hex color green (ARGB)",
342 const unsigned int numberOfTests = 14u;
344 for( unsigned int index = 0u; index < numberOfTests; ++index )
346 ToolkitTestApplication application;
347 if( !ColorStringToVector4Test( data[index] ) )
349 tet_result(TET_FAIL);
353 tet_result(TET_PASS);
357 int UtcDaliTextVector4ToColorString(void)
359 tet_infoline(" UtcDaliTextVector4ToColorString");
361 const Vector4ToColorStringData data[] =
404 "transparent string",
410 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
414 const unsigned int numberOfTests = 10u;
416 for( unsigned int index = 0u; index < numberOfTests; ++index )
418 ToolkitTestApplication application;
419 if( !Vector4ToColorStringTest( data[index] ) )
421 tet_result(TET_FAIL);
425 tet_result(TET_PASS);
429 int UtcDaliTextStringToVector2(void)
431 tet_infoline(" UtcDaliTextStringToVector2");
432 const StringToVector2Data data[] =
450 const unsigned int numberOfTests = 3u;
452 for( unsigned int index = 0u; index < numberOfTests; ++index )
454 ToolkitTestApplication application;
455 if( !StringToVector2Test( data[index] ) )
457 tet_result(TET_FAIL);
461 tet_result(TET_PASS);
465 int UtcDaliTextVector2ToString(void)
467 tet_infoline(" UtcDaliTextVector2ToString");
468 const Vector2ToStringData data[] =
481 const unsigned int numberOfTests = 2u;
483 for( unsigned int index = 0u; index < numberOfTests; ++index )
485 ToolkitTestApplication application;
486 if( !Vector2ToStringTest( data[index] ) )
488 tet_result(TET_FAIL);
492 tet_result(TET_PASS);
496 int UtcDaliTextXHTMLEntityToUTF8(void)
498 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
499 const XHTMLEntityToUTF8Data data[] =
502 "Text Without XHTML Entity",
503 "Checking XHTML Entitities",
504 "Checking XHTML Entitities"
507 "Text With XHTML Entity in Numeric form",
508 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
509 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
512 "Text With XHTML Named Entities",
513 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
514 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
517 "Testing of < special character",
518 "Testing of < special character",
522 "Testing of & special character",
523 "Testing of & special character",
527 "Testing of & < > special character",
528 "Testing of \\& \\< \\> special character",
529 "Testing of & < > special character"
532 const unsigned int numberOfTests = 6u;
534 for( unsigned int index = 0u; index < numberOfTests; ++index )
536 ToolkitTestApplication application;
537 if( !XHTMLEntityToUTF8Test( data[index] ) )
539 tet_result(TET_FAIL);
543 tet_result(TET_PASS);