2 * Copyright (c) 2022 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 <dali-toolkit/internal/text/color-run.h>
26 #include <dali-toolkit/internal/text/font-description-run.h>
27 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
28 #include <dali-toolkit/internal/text/markup-processor.h>
29 #include <dali-toolkit/internal/text/text-definitions.h>
30 #include <dali-toolkit/internal/text/text-io.h>
31 #include <toolkit-text-utils.h>
34 using namespace Toolkit;
39 ///////////////////////////////////////////////////////////
41 struct TokenComparisonData
43 std::string description;
44 std::string string1; ///< must be in lower case!!!!
49 bool TokenComparisonTest(const TokenComparisonData& data)
51 std::cout << " testing " << data.description << std::endl;
53 const bool result = TokenComparison(data.string1,
57 if(result != data.expectedResult)
59 std::cout << " different conparison result : " << result << ", expected : " << data.expectedResult << std::endl;
60 std::cout << " comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl;
68 ///////////////////////////////////////////////////////////
70 struct ColorStringToVector4Data
72 std::string description;
74 Vector4 expectedColor;
77 bool ColorStringToVector4Test(const ColorStringToVector4Data& data)
79 std::cout << " testing " << data.description << std::endl;
82 ColorStringToVector4(data.colorStr.c_str(), data.colorStr.size(), color);
84 if(color != data.expectedColor)
86 std::cout << " different color : " << color << ", expected : " << data.expectedColor << std::endl;
93 ///////////////////////////////////////////////////////////
95 struct Vector4ToColorStringData
97 std::string description;
99 std::string expectedColorStr;
102 bool Vector4ToColorStringTest(const Vector4ToColorStringData& data)
104 std::cout << " testing " << data.description << std::endl;
106 std::string colorStr;
107 Vector4ToColorString(data.color, colorStr);
109 if(colorStr != data.expectedColorStr)
111 std::cout << " different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl;
118 ///////////////////////////////////////////////////////////
120 struct StringToVector2Data
122 std::string description;
123 std::string vector2Str;
124 Vector2 expectedVector2;
127 bool StringToVector2Test(const StringToVector2Data& data)
129 std::cout << " testing " << data.description << std::endl;
132 StringToVector2(data.vector2Str.c_str(), data.vector2Str.size(), vector2);
134 if(vector2 != data.expectedVector2)
136 std::cout << " different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl;
143 ///////////////////////////////////////////////////////////
145 struct Vector2ToStringData
147 std::string description;
149 std::string expectedVector2Str;
152 bool Vector2ToStringTest(const Vector2ToStringData& data)
154 std::cout << " testing " << data.description << std::endl;
156 std::string vector2Str;
157 Vector2ToString(data.vector2, vector2Str);
159 if(vector2Str != data.expectedVector2Str)
161 std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
168 ///////////////////////////////////////////////////////////
170 struct XHTMLEntityToUTF8Data
172 std::string description;
173 std::string xHTMLEntityString;
174 std::string expectedString;
177 bool XHTMLEntityToUTF8Test(const XHTMLEntityToUTF8Data& data)
179 std::cout << " testing " << data.description << std::endl;
181 Vector<ColorRun> colorRuns;
182 Vector<FontDescriptionRun> fontRuns;
183 Vector<EmbeddedItem> items;
184 Vector<Anchor> anchors;
185 Vector<UnderlinedCharacterRun> underlinedCharacterRuns;
186 Vector<ColorRun> backgroundColorRuns;
187 Vector<StrikethroughCharacterRun> strikethroughCharacterRuns;
188 Vector<BoundedParagraphRun> boundedParagraphRuns;
189 MarkupProcessData markupProcessData(colorRuns, fontRuns, items, anchors, underlinedCharacterRuns, backgroundColorRuns, strikethroughCharacterRuns, boundedParagraphRuns);
190 ProcessMarkupString(data.xHTMLEntityString, markupProcessData);
192 for(Vector<EmbeddedItem>::Iterator it = items.Begin(),
197 EmbeddedItem& item = *it;
202 if(markupProcessData.markupProcessedText != data.expectedString)
204 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
213 int UtcDaliTextTokenComparison(void)
215 tet_infoline(" UtcDaliTextTokenComparison");
217 const TokenComparisonData data[] =
223 {"different size text",
235 {"some punctuation characters, numbers, ...",
236 "hello0123456789.![?]",
237 "Hello0123456789.![?]",
241 const unsigned int numberOfTests = 5u;
243 for(unsigned int index = 0u; index < numberOfTests; ++index)
245 ToolkitTestApplication application;
246 if(!TokenComparisonTest(data[index]))
248 tet_result(TET_FAIL);
252 tet_result(TET_PASS);
256 int UtcDaliTextColorStringToVector4(void)
258 tet_infoline(" UtcDaliTextColorStringToVector4");
260 const ColorStringToVector4Data data[] =
286 {"transparent string",
289 {"3 component web color",
292 {"6 component web color",
295 {"hex color red (ARGB)",
298 {"hex color green (ARGB)",
305 const unsigned int numberOfTests = 14u;
307 for(unsigned int index = 0u; index < numberOfTests; ++index)
309 ToolkitTestApplication application;
310 if(!ColorStringToVector4Test(data[index]))
312 tet_result(TET_FAIL);
316 tet_result(TET_PASS);
320 int UtcDaliTextVector4ToColorString(void)
322 tet_infoline(" UtcDaliTextVector4ToColorString");
324 const Vector4ToColorStringData data[] =
352 {"transparent string",
356 Vector4(0.4f, 0.5f, 0.6f, 1.f),
359 const unsigned int numberOfTests = 10u;
361 for(unsigned int index = 0u; index < numberOfTests; ++index)
363 ToolkitTestApplication application;
364 if(!Vector4ToColorStringTest(data[index]))
366 tet_result(TET_FAIL);
370 tet_result(TET_PASS);
374 int UtcDaliTextStringToVector2(void)
376 tet_infoline(" UtcDaliTextStringToVector2");
377 const StringToVector2Data data[] =
388 const unsigned int numberOfTests = 3u;
390 for(unsigned int index = 0u; index < numberOfTests; ++index)
392 ToolkitTestApplication application;
393 if(!StringToVector2Test(data[index]))
395 tet_result(TET_FAIL);
399 tet_result(TET_PASS);
403 int UtcDaliTextVector2ToString(void)
405 tet_infoline(" UtcDaliTextVector2ToString");
406 const Vector2ToStringData data[] =
418 const unsigned int numberOfTests = 2u;
420 for(unsigned int index = 0u; index < numberOfTests; ++index)
422 ToolkitTestApplication application;
423 if(!Vector2ToStringTest(data[index]))
425 tet_result(TET_FAIL);
429 tet_result(TET_PASS);
433 int UtcDaliTextXHTMLEntityToUTF8(void)
435 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
436 const XHTMLEntityToUTF8Data data[] =
438 {"Text Without XHTML Entity",
439 "Checking XHTML Entitities",
440 "Checking XHTML Entitities"},
441 {"Text With XHTML Entity in Numeric form",
442 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
443 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "},
444 {"Text With XHTML Named Entities",
445 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
446 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "},
447 {"Testing of < special character",
448 "Testing of < special character",
450 {"Testing of & special character",
451 "Testing of & special character",
453 {"Testing of & < > special character",
454 "Testing of \\& \\< \\> special character",
455 "Testing of & < > special character"}};
456 const unsigned int numberOfTests = 6u;
458 for(unsigned int index = 0u; index < numberOfTests; ++index)
460 ToolkitTestApplication application;
461 if(!XHTMLEntityToUTF8Test(data[index]))
463 tet_result(TET_FAIL);
467 tet_result(TET_PASS);