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 MarkupProcessData markupProcessData( colorRuns, fontRuns, items );
188 ProcessMarkupString( data.xHTMLEntityString, markupProcessData );
190 for( Vector<EmbeddedItem>::Iterator it = items.Begin(),
195 EmbeddedItem& item = *it;
200 if( markupProcessData.markupProcessedText != data.expectedString )
202 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
211 int UtcDaliTextTokenComparison(void)
213 tet_infoline(" UtcDaliTextTokenComparison");
215 const TokenComparisonData data[] =
224 "different size text",
242 "some punctuation characters, numbers, ...",
243 "hello0123456789.![?]",
244 "Hello0123456789.![?]",
249 const unsigned int numberOfTests = 5u;
251 for( unsigned int index = 0u; index < numberOfTests; ++index )
253 ToolkitTestApplication application;
254 if( !TokenComparisonTest( data[index] ) )
256 tet_result(TET_FAIL);
260 tet_result(TET_PASS);
264 int UtcDaliTextColorStringToVector4(void)
266 tet_infoline(" UtcDaliTextColorStringToVector4");
268 const ColorStringToVector4Data data[] =
311 "transparent string",
316 "3 component web color",
321 "6 component web color",
326 "hex color red (ARGB)",
331 "hex color green (ARGB)",
341 const unsigned int numberOfTests = 14u;
343 for( unsigned int index = 0u; index < numberOfTests; ++index )
345 ToolkitTestApplication application;
346 if( !ColorStringToVector4Test( data[index] ) )
348 tet_result(TET_FAIL);
352 tet_result(TET_PASS);
356 int UtcDaliTextVector4ToColorString(void)
358 tet_infoline(" UtcDaliTextVector4ToColorString");
360 const Vector4ToColorStringData data[] =
403 "transparent string",
409 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
413 const unsigned int numberOfTests = 10u;
415 for( unsigned int index = 0u; index < numberOfTests; ++index )
417 ToolkitTestApplication application;
418 if( !Vector4ToColorStringTest( data[index] ) )
420 tet_result(TET_FAIL);
424 tet_result(TET_PASS);
428 int UtcDaliTextStringToVector2(void)
430 tet_infoline(" UtcDaliTextStringToVector2");
431 const StringToVector2Data data[] =
449 const unsigned int numberOfTests = 3u;
451 for( unsigned int index = 0u; index < numberOfTests; ++index )
453 ToolkitTestApplication application;
454 if( !StringToVector2Test( data[index] ) )
456 tet_result(TET_FAIL);
460 tet_result(TET_PASS);
464 int UtcDaliTextVector2ToString(void)
466 tet_infoline(" UtcDaliTextVector2ToString");
467 const Vector2ToStringData data[] =
480 const unsigned int numberOfTests = 2u;
482 for( unsigned int index = 0u; index < numberOfTests; ++index )
484 ToolkitTestApplication application;
485 if( !Vector2ToStringTest( data[index] ) )
487 tet_result(TET_FAIL);
491 tet_result(TET_PASS);
495 int UtcDaliTextXHTMLEntityToUTF8(void)
497 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
498 const XHTMLEntityToUTF8Data data[] =
501 "Text Without XHTML Entity",
502 "Checking XHTML Entitities",
503 "Checking XHTML Entitities"
506 "Text With XHTML Entity in Numeric form",
507 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
508 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
511 "Text With XHTML Named Entities",
512 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
513 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
516 "Testing of < special character",
517 "Testing of < special character",
521 "Testing of & special character",
522 "Testing of & special character",
526 "Testing of & < > special character",
527 "Testing of \\& \\< \\> special character",
528 "Testing of & < > special character"
531 const unsigned int numberOfTests = 6u;
533 for( unsigned int index = 0u; index < numberOfTests; ++index )
535 ToolkitTestApplication application;
536 if( !XHTMLEntityToUTF8Test( data[index] ) )
538 tet_result(TET_FAIL);
542 tet_result(TET_PASS);