• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test/unittest/adapter/ohos/capability/convert_test_tools.h"
17 
18 #undef private
19 #undef protected
20 
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS::Ace::NG {
24 
25 namespace {
26     std::string testStr[] = { "微软雅黑", "宋体", "Times New Roman", "未知字体", "Unknow", "楷体"};
27     Font testFont1 { OHOS::Ace::FontWeight::BOLDER, Dimension(0.0, DimensionUnit::VP), OHOS::Ace::FontStyle::NORMAL,
28         std::vector<std::string>(testStr, testStr + 5), OHOS::Ace::Color::WHITE };
29     Font testFont2 { OHOS::Ace::FontWeight::LIGHTER, Dimension(20.0, DimensionUnit::PX), OHOS::Ace::FontStyle::ITALIC,
30         std::vector<std::string>(testStr, testStr + 5), OHOS::Ace::Color::BLACK };
31 }
32 
33 // imageOption1: default parameter
34 auto imageOption1 = HtmlConvertTestNg::GetImageOption(
35     "src/icon-1.png",
36     Dimension(50.0, DimensionUnit::VP),
37     Dimension(50.0, DimensionUnit::VP)
38 );
39 
40 // imageOption2: define ImageFit, VerticalAlign and BorderRadiusProperty
41 auto imageOption2 = HtmlConvertTestNg::GetImageOption(
42     "src/icon-2.png",
43     Dimension(100.0, DimensionUnit::VP),
44     Dimension(100.0, DimensionUnit::VP),
45     ImageFit::COVER,
46     VerticalAlign::TOP,
47     BorderRadiusProperty(Dimension(10.0, DimensionUnit::VP))
48 );
49 
50 // imageOption3: ImageFit, VerticalAlign and BorderRadiusProperty set 2
51 auto imageOption3 = HtmlConvertTestNg::GetImageOption(
52     "src/icon-3.png",
53     Dimension(75.0, DimensionUnit::VP),
54     Dimension(75.0, DimensionUnit::VP),
55     ImageFit::FILL,
56     VerticalAlign::BOTTOM,
57     BorderRadiusProperty(Dimension(5.0, DimensionUnit::VP))
58 );
59 
60 // imageOption3: ImageFit, VerticalAlign and BorderRadiusProperty set 3
61 auto imageOption4 = HtmlConvertTestNg::GetImageOption(
62     "src/icon-4.png",
63     Dimension(150.0, DimensionUnit::VP),
64     Dimension(150.0, DimensionUnit::VP),
65     ImageFit::NONE,
66     VerticalAlign::CENTER,
67     BorderRadiusProperty(Dimension(20.0, DimensionUnit::VP))
68 );
69 
70 /**
71  * @tc.name: HtmlConvertComplex01
72  * @tc.desc: This test case checks the conversion of a span string with various complex styles like font,
73  *           letter spacing, background color, line height, text shadow, image spans, and paragraph styles.
74  *           It ensures that all styles are properly applied and the correct number of span items is produced.
75  * @tc.level: 1
76  */
77 HWTEST_F(HtmlConvertTestNg, HtmlConvertComplex01, TestSize.Level1)
78 {
79     /**
80      * @tc.steps1: Initialize mutable SpanString and add a variety of styles like font, letter spacing,
81      *             background color, line height, and text shadow.
82      * @tc.expected: Span string should apply all styles correctly and be ready for conversion.
83      */
84     auto imageOption = GetImageOption("src/icon-2.png");
85     auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
86     auto spanString3 = AceType::MakeRefPtr<SpanString>(u"Hello World! This is a test to cover complex cases.");
87 
88     // Adding Font Spans
89     spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 5));
90     spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 6, 11));
91 
92     // Adding Letter Spacing
93     spanString3->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(3), 12, 18));
94 
95     // Adding Background Color Span
96     NG::BorderRadiusProperty borderRadius;
97     borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
98     borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
99     borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
100     borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
101     TextBackgroundStyle textBackgroundStyle;
102     textBackgroundStyle.backgroundColor = Color::RED;
103     textBackgroundStyle.backgroundRadius = borderRadius;
104     spanString3->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 19, 25));
105 
106     // Adding Line Height Span
107     spanString3->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(1.5), 26, 32));
108 
109     // Adding Text Shadow Span
110     Shadow shadow1;
111     shadow1.SetBlurRadius(2.0);
112     shadow1.SetColor(Color::RED);
113     shadow1.SetOffsetX(4.0);
114     shadow1.SetOffsetY(4.0);
115 
116     spanString3->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 15, 25));
117 
118     // Adding Image Span
119     auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption);
120     spanString3->AddSpan(imageSpan);
121 
122     // Adding a complex Paragraph Style
123     auto paragraphStyle = GetDefaultParagraphStyle();
124     auto paraSpan = AceType::MakeRefPtr<ParagraphStyleSpan>(paragraphStyle, 8, 15);
125     spanString3->AddSpan(paraSpan);
126 
127     mutableStr->InsertSpanString(0, spanString3);
128 
129     /**
130      * @tc.steps2: Create a new SpanString with Chinese content and more complex styles,
131      *             and insert into mutable string.
132      * @tc.expected: Correct application of font, letter spacing, and span insertion.
133      */
134     auto spanString2 = AceType::MakeRefPtr<SpanString>(u"中文文本,包含更多复杂的样式。123456");
135     spanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 2));
136     spanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 3, 6));
137     spanString2->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(8), 7, 10));
138 
139     mutableStr->InsertSpanString(16, spanString2);
140 
141     /**
142      * @tc.steps3: Call the conversion function to convert the mutable span string to HTML.
143      * @tc.expected: Ensure that the conversion correctly maintains all span properties and styles.
144      */
145     SpanToHtml convert;
146     auto out = convert.ToHtml(*mutableStr);
147 
148     /**
149      * @tc.steps4: Convert HTML back to SpanString and validate the number of span items.
150      * @tc.expected: The number of span items should match the total number of spans added.
151      */
152     HtmlToSpan toSpan;
153     auto dstSpan = toSpan.ToSpanString(out);
154     EXPECT_NE(dstSpan, nullptr);
155     auto items = dstSpan->GetSpanItems();
156     EXPECT_EQ(items.size(), 22);
157 }
158 
159 /**
160  * @tc.name: HtmlConvertComplex02
161  * @tc.desc: This test case checks the conversion of a span string with nested and complex styles like
162  *           font spans, letter spacing, background color, and image spans. It ensures that the nested
163  *           styles are applied correctly and that the correct number of span items is produced.
164  * @tc.level: 1
165  */
166 HWTEST_F(HtmlConvertTestNg, HtmlConvertComplex02, TestSize.Level1)
167 {
168     /**
169      * @tc.steps1: Initialize mutable SpanString and add various font, letter spacing, background color,
170      *             and image spans in a nested manner.
171      * @tc.expected: Nested and complex spans should be applied correctly.
172      */
173     auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption1);
174     auto spanString4 = AceType::MakeRefPtr<SpanString>(u"Complex Nested Styles Test: Begin");
175 
176     // Add some font spans with different styles
177     spanString4->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 7));
178     spanString4->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 8, 15));
179     spanString4->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 16, 21));
180 
181     // Add multiple letter spacing spans
182     spanString4->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 5, 10));
183     spanString4->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(2), 12, 18));
184 
185     // Add Background Color Span for a range
186     NG::BorderRadiusProperty borderRadius;
187     borderRadius.radiusTopLeft = Dimension(4, OHOS::Ace::DimensionUnit::FP);
188     borderRadius.radiusTopRight = Dimension(3, OHOS::Ace::DimensionUnit::FP);
189     borderRadius.radiusBottomLeft = Dimension(5, OHOS::Ace::DimensionUnit::FP);
190     borderRadius.radiusBottomRight = Dimension(7, OHOS::Ace::DimensionUnit::FP);
191     TextBackgroundStyle textBackgroundStyle;
192     textBackgroundStyle.backgroundColor = Color::RED;
193     textBackgroundStyle.backgroundRadius = borderRadius;
194     spanString4->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 5, 15));
195 
196     // Add Image Span at the end
197     auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption2);
198     spanString4->AddSpan(imageSpan);
199 
200     mutableStr->InsertSpanString(0, spanString4);
201 
202     /**
203      * @tc.steps2: Create another SpanString with more complex Chinese content,
204      *             add font spans, letter spacing, and text shadow, and insert it into mutable string.
205      * @tc.expected: The second span string with additional styles should be properly inserted and applied.
206      */
207     auto spanString5 = AceType::MakeRefPtr<SpanString>(u"进一步增加复杂性,测试多个样式的组合应用。");
208     spanString5->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 0, 4));
209     spanString5->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 5, 9));
210     spanString5->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(7), 9, 14));
211 
212     Shadow shadow1;
213     shadow1.SetBlurRadius(10.0);
214     shadow1.SetColor(Color::RED);
215     shadow1.SetOffsetX(-10.0);
216     shadow1.SetOffsetY(0.0);
217     spanString5->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 10, 20));
218 
219     mutableStr->InsertSpanString(10, spanString5);
220 
221     /**
222      * @tc.steps3: Call the conversion function to convert the mutable span string to HTML.
223      * @tc.expected: Ensure that the conversion correctly maintains all nested and complex span properties.
224      */
225     SpanToHtml convert;
226     auto out = convert.ToHtml(*mutableStr);
227 
228     /**
229      * @tc.steps4: Convert HTML back to SpanString and validate the number of span items.
230      * @tc.expected: The number of span items should match the total number of spans added.
231      */
232     HtmlToSpan toSpan;
233     auto dstSpan = toSpan.ToSpanString(out);
234     EXPECT_NE(dstSpan, nullptr);
235     auto items = dstSpan->GetSpanItems();
236     EXPECT_EQ(items.size(), 20);
237 }
238 
239 /**
240  * @tc.name: HtmlConvertComplex03
241  * @tc.desc: This test case verifies the conversion of a very large text block with multiple font spans,
242  *           letter spacing, background color, and text shadow applied in various iterations. It ensures
243  *           that the correct number of span items is produced and that the styles are applied consistently.
244  * @tc.level: 1
245  */
246 HWTEST_F(HtmlConvertTestNg, HtmlConvertComplex03, TestSize.Level1)
247 {
248     /**
249      * @tc.steps1: Initialize mutable SpanString with a large text block and apply various font,
250      *             letter spacing, and other styles.
251      * @tc.expected: Large text block with correct number of spans, properly applied styles, and correct span count.
252      */
253     auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption3);
254 
255     // Test with a very large text block, mimicking an article
256     std::u16string largeText = u"这是一段包含多个字体和样式的大段文本。我们将使用不同的样式组合来测试转换的效果。";
257     auto spanString6 = AceType::MakeRefPtr<SpanString>(largeText);
258 
259     // Apply multiple font spans with varied fonts
260     spanString6->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 5));
261     spanString6->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 6, 10));
262     spanString6->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 11, 15));
263 
264     // Add a large number of letter spacing spans
265     for (int i = 0; i < 20; ++i) {
266         spanString6->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(i), i * 2, i * 3));
267     }
268 
269     // Add a combination of other spans
270     Shadow shadow;
271     shadow.SetBlurRadius(2.0);
272     shadow.SetColor(Color::TRANSPARENT);
273     shadow.SetOffsetX(2.0);
274     shadow.SetOffsetY(2.0);
275     spanString6->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow}, 6, 12));
276 
277     NG::BorderRadiusProperty borderRadius;
278     borderRadius.radiusTopLeft = Dimension(1, OHOS::Ace::DimensionUnit::AUTO);
279     borderRadius.radiusTopRight = Dimension(2, OHOS::Ace::DimensionUnit::AUTO);
280     borderRadius.radiusBottomLeft = Dimension(3, OHOS::Ace::DimensionUnit::AUTO);
281     borderRadius.radiusBottomRight = Dimension(4, OHOS::Ace::DimensionUnit::AUTO);
282 
283     TextBackgroundStyle textBackgroundStyle;
284     textBackgroundStyle.backgroundColor = Color::RED;
285     textBackgroundStyle.backgroundRadius = borderRadius;
286     spanString6->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 10));
287 
288     mutableStr->InsertSpanString(0, spanString6);
289 
290     /**
291      * @tc.steps2: Convert the large mutable string to HTML format and validate the number of span items.
292      * @tc.expected: The conversion should result in a high number of span items due to the large amount of styling.
293      */
294     SpanToHtml convert;
295     auto out = convert.ToHtml(*mutableStr);
296 
297     HtmlToSpan toSpan;
298     auto dstSpan = toSpan.ToSpanString(out);
299     EXPECT_NE(dstSpan, nullptr);
300     auto items = dstSpan->GetSpanItems();
301     EXPECT_EQ(items.size(), 26);
302 }
303 
304 /**
305  * @tc.name: HtmlConvertComplex04
306  * @tc.desc: This test case checks the conversion of multiple text blocks with embedded images and various
307  *           styles such as font and letter spacing applied. It verifies the correct insertion of images and
308  *           the accurate number of span items after conversion.
309  * @tc.level: 3
310  */
311 HWTEST_F(HtmlConvertTestNg, HtmlConvertComplex04, TestSize.Level3)
312 {
313     /**
314      * @tc.steps1: Initialize mutable SpanString with imageOption1.
315      * @tc.expected: The mutable string should be ready for inserting span strings with various styles and images.
316      */
317     auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption1);
318 
319     // First text block with an image
320     /**
321      * @tc.steps2: Create the first text span string and apply font and letter spacing styles to it.
322      *             Insert an image (imageOption1) into the text span.
323      * @tc.expected: The first span string should be styled correctly and the image should be inserted
324      *                at the correct position.
325      */
326     std::u16string text1 = u"This is the first paragraph with an image display:";
327     auto spanString1 = AceType::MakeRefPtr<SpanString>(text1);
328     spanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10)); // "This is the first"
329     spanString1->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(4), 10, 20)); // "paragraph"
330 
331     // Insert image (using imageOption1)
332     auto imageSpan1 = AceType::MakeRefPtr<ImageSpan>(imageOption1);
333     spanString1->AddSpan(imageSpan1);
334 
335     mutableStr->InsertSpanString(0, spanString1);
336 
337     // Second text block with different image configurations
338     /**
339      * @tc.steps3: Create the second text span string and apply font and letter spacing styles.
340      *             Insert a different image (imageOption2) into this span string.
341      * @tc.expected: The second span string should have proper font styles, letter spacing, and image insertion.
342      */
343     std::u16string text2 = u"The second paragraph with different image configurations:";
344     auto spanString2 = AceType::MakeRefPtr<SpanString>(text2);
345     spanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 0, 10)); // "The second"
346     spanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 11, 18)); // "paragraph"
347     spanString2->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(6), 18, 25)); // "with different"
348 
349     // Insert image (using imageOption2)
350     auto imageSpan2 = AceType::MakeRefPtr<ImageSpan>(imageOption2);
351     spanString2->AddSpan(imageSpan2);
352 
353     mutableStr->InsertSpanString(30, spanString2);
354 
355     // Third text block with more images
356     /**
357      * @tc.steps4: Create the third text span string and apply font and letter spacing styles.
358      *             Insert an image (imageOption3) into this span string.
359      * @tc.expected: The third span string should have the correct styles and image insertion.
360      */
361     std::u16string text3 = u"The third paragraph showcasing another image configuration:";
362     auto spanString3 = AceType::MakeRefPtr<SpanString>(text3);
363     spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10)); // "The third"
364     spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 11, 15)); // "paragraph"
365     spanString3->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(3), 15, 20)); // "showcasing"
366 
367     // Insert image (using imageOption3)
368     auto imageSpan3 = AceType::MakeRefPtr<ImageSpan>(imageOption3);
369     spanString3->AddSpan(imageSpan3);
370 
371     mutableStr->InsertSpanString(50, spanString3);
372 
373     // Fourth text block with the final image
374     /**
375      * @tc.steps5: Create the fourth text span string and apply font and letter spacing styles.
376      *             Insert the final image (imageOption4) into this span string.
377      * @tc.expected: The fourth span string should be styled correctly and the image should
378      *               be inserted at the right position.
379      */
380     std::u16string text4 = u"The final paragraph showcasing the last image configuration:";
381     auto spanString4 = AceType::MakeRefPtr<SpanString>(text4);
382     spanString4->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 0, 10)); // "The final"
383     spanString4->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(4), 10, 18)); // "paragraph"
384 
385     // Insert image (using imageOption4)
386     auto imageSpan4 = AceType::MakeRefPtr<ImageSpan>(imageOption4);
387     spanString4->AddSpan(imageSpan4);
388 
389     mutableStr->InsertSpanString(70, spanString4);
390 
391     /**
392      * @tc.steps6: Convert the entire mutable string to HTML format and verify the result.
393      * @tc.expected: The conversion should result in the correct number of span items,
394      *               including those with images and different styles.
395      */
396     SpanToHtml convert;
397     auto out = convert.ToHtml(*mutableStr);
398 
399     HtmlToSpan toSpan;
400     auto dstSpan = toSpan.ToSpanString(out);
401     EXPECT_NE(dstSpan, nullptr);
402     auto items = dstSpan->GetSpanItems();
403 
404     EXPECT_EQ(items.size(), 24);
405 }
406 
407 /**
408  * @tc.name: HtmlConvert000
409  * @tc.desc: This test case verifies the conversion of a simple SpanString (without complex styles)
410  *           to TLV format, HTML format, and back to SpanString. It ensures the conversion
411  *           maintains the integrity of the content and results in identical HTML outputs after
412  *           multiple conversions.
413  * @tc.level: 1
414  */
415 HWTEST_F(HtmlConvertTestNg, HtmlConvert000, TestSize.Level1)
416 {
417     /**
418      * @tc.steps1: Create a simple SpanString with basic text content.
419      * @tc.expected: The SpanString should be successfully created without any errors.
420      */
421     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello");
422 
423     /**
424      * @tc.steps2: Convert the SpanString to TLV format and ensure the result is not empty.
425      * @tc.expected: TLV format conversion should produce a non-empty result.
426      */
427     std::vector<uint8_t> buff;
428     spanString->EncodeTlv(buff);
429     EXPECT_EQ(buff.size() > 0, true);
430 
431     /**
432      * @tc.steps3: Convert the TLV format back to HTML and compare it with the direct HTML conversion
433      *             of the SpanString.
434      * @tc.expected: The HTML results from both methods should be identical.
435      */
436     SpanToHtml toHtml;
437     auto htmlFromU8 = toHtml.ToHtml(buff);
438     auto htmlFromSpan = toHtml.ToHtml(*spanString);
439     EXPECT_EQ(htmlFromU8, htmlFromSpan);
440 
441     /**
442      * @tc.steps4: Convert the HTML back to SpanString and verify that the items match.
443      * @tc.expected: The SpanString items after conversion should be identical to the original.
444      */
445     HtmlToSpan toSpan;
446     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
447     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
448 
449     /**
450      * @tc.steps5: Convert the SpanString back to HTML and verify consistency.
451      * @tc.expected: The final HTML should match the HTML obtained earlier.
452      */
453     SpanToHtml toHtml1;
454     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
455     EXPECT_EQ(hmtlString, htmlFromSpan);
456 }
457 
458 /**
459  * @tc.name: HtmlConvert001
460  * @tc.desc: This test case checks the conversion of a SpanString with different font styles applied
461  *           to different parts of the text. The test ensures that font spans are correctly applied
462  *           during conversion to TLV, HTML, and back to SpanString.
463  * @tc.level: 1
464  */
465 HWTEST_F(HtmlConvertTestNg, HtmlConvert001, TestSize.Level1)
466 {
467     /**
468      * @tc.steps1: Create a SpanString with text and apply font styles to different ranges.
469      * @tc.expected: Font styles should be applied correctly to the specified ranges.
470      */
471     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World");
472     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 5));
473     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 6, 11));
474 
475     /**
476      * @tc.steps2: Convert the SpanString to TLV format and ensure the result is not empty.
477      * @tc.expected: TLV format conversion should produce a non-empty result.
478      */
479     std::vector<uint8_t> buff;
480     spanString->EncodeTlv(buff);
481     EXPECT_EQ(buff.size() > 0, true);
482 
483     /**
484      * @tc.steps3: Convert the TLV format back to HTML and compare it with the direct HTML conversion
485      *             of the SpanString.
486      * @tc.expected: The HTML results from both methods should be identical.
487      */
488     SpanToHtml toHtml;
489     auto htmlFromU8 = toHtml.ToHtml(buff);
490     auto htmlFromSpan = toHtml.ToHtml(*spanString);
491     EXPECT_EQ(htmlFromU8, htmlFromSpan);
492 
493     /**
494      * @tc.steps4: Convert the HTML back to SpanString and verify that the items match.
495      * @tc.expected: The SpanString items after conversion should be identical to the original.
496      */
497     HtmlToSpan toSpan;
498     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
499     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
500 
501     /**
502      * @tc.steps5: Convert the SpanString back to HTML and verify consistency.
503      * @tc.expected: The final HTML should match the HTML obtained earlier.
504      */
505     SpanToHtml toHtml1;
506     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
507     EXPECT_EQ(hmtlString, htmlFromSpan);
508 }
509 
510 /**
511  * @tc.name: HtmlConvert002
512  * @tc.desc: This test case checks the conversion of a SpanString with letter spacing applied to
513  *           different parts of the text. The test ensures that letter spacing is correctly applied
514  *           during conversion to TLV, HTML, and back to SpanString.
515  * @tc.level: 1
516  */
517 HWTEST_F(HtmlConvertTestNg, HtmlConvert002, TestSize.Level1)
518 {
519     /**
520      * @tc.steps1: Create a SpanString with text and apply letter spacing to different ranges.
521      * @tc.expected: Letter spacing should be applied correctly to the specified ranges.
522      */
523     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World");
524     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(2), 0, 5));
525     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(3), 6, 11));
526 
527     /**
528      * @tc.steps2: Convert the SpanString to TLV format and ensure the result is not empty.
529      * @tc.expected: TLV format conversion should produce a non-empty result.
530      */
531     std::vector<uint8_t> buff;
532     spanString->EncodeTlv(buff);
533     EXPECT_EQ(buff.size() > 0, true);
534 
535     /**
536      * @tc.steps3: Convert the TLV format back to HTML and compare it with the direct HTML conversion
537      *             of the SpanString.
538      * @tc.expected: The HTML results from both methods should be identical.
539      */
540     SpanToHtml toHtml;
541     auto htmlFromU8 = toHtml.ToHtml(buff);
542     auto htmlFromSpan = toHtml.ToHtml(*spanString);
543     EXPECT_EQ(htmlFromU8, htmlFromSpan);
544 
545     /**
546      * @tc.steps4: Convert the HTML back to SpanString and verify that the items match.
547      * @tc.expected: The SpanString items after conversion should be identical to the original.
548      */
549     HtmlToSpan toSpan;
550     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
551     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
552 
553     /**
554      * @tc.steps5: Convert the SpanString back to HTML and verify consistency.
555      * @tc.expected: The final HTML should match the HTML obtained earlier.
556      */
557     SpanToHtml toHtml1;
558     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
559     EXPECT_EQ(hmtlString, htmlFromSpan);
560 }
561 
562 /**
563  * @tc.name: HtmlConvert003
564  * @tc.desc: This test case checks the conversion of a SpanString with background color and text
565  *           shadow applied to different parts of the text. It ensures that background and shadow
566  *           styles are properly converted between TLV, HTML, and SpanString formats.
567  * @tc.level: 1
568  */
569 HWTEST_F(HtmlConvertTestNg, HtmlConvert003, TestSize.Level1)
570 {
571     /**
572      * @tc.steps1: Create a SpanString with text and apply background color and text shadow.
573      * @tc.expected: Background color and text shadow should be applied correctly.
574      */
575     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World");
576 
577     // Add background color
578     NG::BorderRadiusProperty borderRadius;
579     TextBackgroundStyle textBackgroundStyle;
580     textBackgroundStyle.backgroundColor = Color::BLUE;
581     textBackgroundStyle.backgroundRadius = borderRadius;
582     spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
583 
584     // Add text shadow
585     Shadow shadow1;
586     shadow1.SetBlurRadius(5.0);
587     shadow1.SetColor(Color::RED);
588     shadow1.SetOffsetX(2.0);
589     shadow1.SetOffsetY(2.0);
590     spanString->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 6, 11));
591 
592     /**
593      * @tc.steps2: Convert the SpanString to TLV format and ensure the result is not empty.
594      * @tc.expected: TLV format conversion should produce a non-empty result.
595      */
596     std::vector<uint8_t> buff;
597     spanString->EncodeTlv(buff);
598     EXPECT_EQ(buff.size() > 0, true);
599 
600     /**
601      * @tc.steps3: Convert the TLV format back to HTML and compare it with the direct HTML conversion
602      *             of the SpanString.
603      * @tc.expected: The HTML results from both methods should be identical.
604      */
605     SpanToHtml toHtml;
606     auto htmlFromU8 = toHtml.ToHtml(buff);
607     auto htmlFromSpan = toHtml.ToHtml(*spanString);
608     EXPECT_EQ(htmlFromU8, htmlFromSpan);
609 
610     /**
611      * @tc.steps4: Convert the HTML back to SpanString and verify that the items match.
612      * @tc.expected: The SpanString items after conversion should be identical to the original.
613      */
614     HtmlToSpan toSpan;
615     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
616     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
617 
618     /**
619      * @tc.steps5: Convert the SpanString back to HTML and verify consistency.
620      * @tc.expected: The final HTML should match the HTML obtained earlier.
621      */
622     SpanToHtml toHtml1;
623     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
624     EXPECT_EQ(hmtlString, htmlFromSpan);
625 }
626 
627 /**
628  * @tc.name: HtmlConvert004
629  * @tc.desc: This test case verifies the conversion of a SpanString with multiple complex styles
630  *           (font, letter spacing, background color, and text shadow) applied to different
631  *           parts of the text. It ensures the complex styles are applied correctly during conversion
632  *           to TLV, HTML, and back to SpanString.
633  * @tc.level: 1
634  */
635 HWTEST_F(HtmlConvertTestNg, HtmlConvert004, TestSize.Level1)
636 {
637     /**
638      * @tc.steps1: Create a SpanString with various complex styles applied (font, letter spacing,
639      *             background color, text shadow).
640      * @tc.expected: All styles should be applied correctly to the specified ranges.
641      */
642     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World Test with Styles");
643 
644     // Add fonts, letter spacing, background color, and text shadow
645     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 5));
646     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 6, 11));
647     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(2), 12, 17));
648 
649     NG::BorderRadiusProperty borderRadius;
650     TextBackgroundStyle textBackgroundStyle;
651     textBackgroundStyle.backgroundColor = Color::GREEN;
652     textBackgroundStyle.backgroundRadius = borderRadius;
653     spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
654 
655     Shadow shadow1;
656     shadow1.SetBlurRadius(5.0);
657     shadow1.SetColor(Color::BLACK);
658     shadow1.SetOffsetX(3.0);
659     shadow1.SetOffsetY(3.0);
660     spanString->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 6, 11));
661 
662     /**
663      * @tc.steps2: Convert the SpanString to TLV format and ensure the result is not empty.
664      * @tc.expected: TLV format conversion should produce a non-empty result.
665      */
666     std::vector<uint8_t> buff;
667     spanString->EncodeTlv(buff);
668     EXPECT_EQ(buff.size() > 0, true);
669 
670     /**
671      * @tc.steps3: Convert the TLV format back to HTML and compare it with the direct HTML conversion
672      *             of the SpanString.
673      * @tc.expected: The HTML results from both methods should be identical.
674      */
675     SpanToHtml toHtml;
676     auto htmlFromU8 = toHtml.ToHtml(buff);
677     auto htmlFromSpan = toHtml.ToHtml(*spanString);
678     EXPECT_EQ(htmlFromU8, htmlFromSpan);
679 
680     /**
681      * @tc.steps4: Convert the HTML back to SpanString and verify that the items match.
682      * @tc.expected: The SpanString items after conversion should be identical to the original.
683      */
684     HtmlToSpan toSpan;
685     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
686     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
687 
688     /**
689      * @tc.steps5: Convert the SpanString back to HTML and verify consistency.
690      * @tc.expected: The final HTML should match the HTML obtained earlier.
691      */
692     SpanToHtml toHtml1;
693     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
694     EXPECT_EQ(hmtlString, htmlFromSpan);
695 }
696 
697 /**
698  * @tc.name: HtmlConvert005
699  * @tc.desc: This test case checks the conversion of an empty SpanString. It ensures that an empty SpanString
700  *           correctly converts to TLV and HTML formats without issues.
701  * @tc.level: 1
702  */
703 HWTEST_F(HtmlConvertTestNg, HtmlConvert005, TestSize.Level1)
704 {
705     /**
706      * @tc.steps1: Create an empty SpanString.
707      * @tc.expected: The SpanString should remain empty and correctly handle conversion to TLV and HTML.
708      */
709     auto spanString = AceType::MakeRefPtr<SpanString>(u"");
710 
711     // Convert to TLV format
712     std::vector<uint8_t> buff;
713     spanString->EncodeTlv(buff);
714     EXPECT_EQ(buff.size(), 16);
715 
716     /**
717      * @tc.steps2: Convert the TLV buffer to HTML.
718      * @tc.expected: The HTML string should match the result of directly converting the SpanString to HTML.
719      */
720     SpanToHtml toHtml;
721     auto htmlFromU8 = toHtml.ToHtml(buff);
722     auto htmlFromSpan = toHtml.ToHtml(*spanString);
723     EXPECT_EQ(htmlFromU8, htmlFromSpan);
724 
725     /**
726      * @tc.steps3: Convert the HTML back to SpanString and verify if it matches the original SpanString.
727      * @tc.expected: The SpanString obtained from the HTML should match the original SpanString.
728      */
729     HtmlToSpan toSpan;
730     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
731     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
732 
733     /**
734      * @tc.steps4: Convert back to HTML and verify that it matches the initial HTML result.
735      * @tc.expected: The final HTML should match the HTML obtained earlier.
736      */
737     SpanToHtml toHtml1;
738     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
739     EXPECT_EQ(hmtlString, htmlFromSpan);
740 }
741 
742 /**
743  * @tc.name: HtmlConvert006
744  * @tc.desc: This test case checks the conversion of a SpanString with overlapping styles applied in different ranges.
745  *           It ensures that the overlapping styles are correctly maintained during the conversion process.
746  * @tc.level: 1
747  */
748 HWTEST_F(HtmlConvertTestNg, HtmlConvert006, TestSize.Level1)
749 {
750     /**
751      * @tc.steps1: Create a SpanString with overlapping styles (FontSpans).
752      * @tc.expected: The SpanString should correctly handle overlapping styles and preserve them during conversion.
753      */
754     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World");
755     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 5));
756     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 3, 8));
757 
758     // Convert to TLV format
759     std::vector<uint8_t> buff;
760     spanString->EncodeTlv(buff);
761     EXPECT_EQ(buff.size() > 0, true);
762 
763     /**
764      * @tc.steps2: Convert the TLV buffer to HTML and compare with direct SpanString to HTML conversion.
765      * @tc.expected: The converted HTML from TLV and direct SpanString should be identical.
766      */
767     SpanToHtml toHtml;
768     auto htmlFromU8 = toHtml.ToHtml(buff);
769     auto htmlFromSpan = toHtml.ToHtml(*spanString);
770     EXPECT_EQ(htmlFromU8, htmlFromSpan);
771 
772     /**
773      * @tc.steps3: Convert the HTML back to SpanString and validate that the spans are equivalent.
774      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
775      */
776     HtmlToSpan toSpan;
777     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
778     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
779 
780     /**
781      * @tc.steps4: Convert back to HTML and validate consistency with the initial HTML result.
782      * @tc.expected: The final HTML should match the initial HTML obtained from the SpanString.
783      */
784     SpanToHtml toHtml1;
785     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
786     EXPECT_EQ(hmtlString, htmlFromSpan);
787 }
788 
789 /**
790  * @tc.name: HtmlConvert007
791  * @tc.desc: This test case checks overlapping styles involving font spans and background color spans,
792  *           ensuring that both styles are applied correctly and do not interfere with each other.
793  * @tc.level: 1
794  */
795 HWTEST_F(HtmlConvertTestNg, HtmlConvert007, TestSize.Level1)
796 {
797     /**
798      * @tc.steps1: Add font spans and background color spans with overlapping ranges.
799      * @tc.expected: Both styles should be applied correctly without interference.
800      */
801     auto spanString = AceType::MakeRefPtr<SpanString>(u"Overlapping styles test");
802     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10));
803     TextBackgroundStyle bgStyle;
804     bgStyle.backgroundColor = Color::GREEN;
805     spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(bgStyle, 5, 15));
806 
807     /**
808      * @tc.steps2: Convert the SpanString to TLV format and check the result.
809      * @tc.expected: The TLV conversion should handle both font and background color styles correctly.
810      */
811     std::vector<uint8_t> buff;
812     spanString->EncodeTlv(buff);
813     EXPECT_GT(buff.size(), 0);
814 
815     /**
816      * @tc.steps3: Convert the SpanString to HTML format and validate the output.
817      * @tc.expected: The HTML conversion should match the expected HTML representation.
818      */
819     SpanToHtml toHtml;
820     auto htmlFromSpan = toHtml.ToHtml(*spanString);
821 
822     /**
823      * @tc.steps4: Convert the HTML back to SpanString and ensure consistency with the original SpanString.
824      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
825      */
826     HtmlToSpan toSpan;
827     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
828     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
829 }
830 
831 /**
832  * @tc.name: HtmlConvert008
833  * @tc.desc: This test case checks the behavior of overlapping letter spacing and text shadow spans in a `SpanString`.
834  *           It ensures that both styles work together without interfering with each other.
835  * @tc.level: 1
836  */
837 HWTEST_F(HtmlConvertTestNg, HtmlConvert008, TestSize.Level1)
838 {
839     /**
840      * @tc.steps1: Add letter spacing and text shadow spans with overlapping ranges.
841      * @tc.expected: Both letter spacing and shadow effects should be applied correctly and not interfere.
842      */
843     auto spanString = AceType::MakeRefPtr<SpanString>(u"Letter spacing and shadow test");
844     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 0, 10));
845 
846     Shadow shadow1;
847     shadow1.SetBlurRadius(5.0);
848     shadow1.SetColor(Color::BLUE);
849     shadow1.SetOffsetX(2.0);
850     shadow1.SetOffsetY(2.0);
851     spanString->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 5, 15));
852 
853     /**
854      * @tc.steps2: Convert the SpanString to TLV format and check the result.
855      * @tc.expected: The conversion should handle both letter spacing and shadow effects correctly.
856      */
857     std::vector<uint8_t> buff;
858     spanString->EncodeTlv(buff);
859     EXPECT_GT(buff.size(), 0);
860 
861     /**
862      * @tc.steps3: Convert the SpanString to HTML format and validate the result.
863      * @tc.expected: The HTML conversion should correctly apply both the letter spacing and text shadow.
864      */
865     SpanToHtml toHtml;
866     auto htmlFromSpan = toHtml.ToHtml(*spanString);
867 
868     /**
869      * @tc.steps4: Convert the HTML back to SpanString and validate if it matches the original SpanString.
870      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
871      */
872     HtmlToSpan toSpan;
873     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
874     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
875 }
876 
877 /**
878  * @tc.name: HtmlConvert009
879  * @tc.desc: This test case checks the overlapping of font spans and letter spacing spans in a `SpanString`.
880  *           It ensures that both styles are applied correctly and do not interfere with each other.
881  * @tc.level: 1
882  */
883 HWTEST_F(HtmlConvertTestNg, HtmlConvert009, TestSize.Level1)
884 {
885     /**
886      * @tc.steps1: Add font and letter spacing spans with overlapping ranges.
887      * @tc.expected: Both font and letter spacing should be applied correctly without any conflicts.
888      */
889     auto spanString = AceType::MakeRefPtr<SpanString>(u"Overlapping font and letter spacing");
890     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10));
891     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 5, 15));
892 
893     // Convert to TLV and HTML
894     std::vector<uint8_t> buff;
895     spanString->EncodeTlv(buff);
896     EXPECT_GT(buff.size(), 0);
897 
898     /**
899      * @tc.steps2: Convert the SpanString to HTML format and check for correctness.
900      * @tc.expected: The HTML conversion should apply both the font and letter spacing styles correctly.
901      */
902     SpanToHtml toHtml;
903     auto htmlFromSpan = toHtml.ToHtml(*spanString);
904 
905     /**
906      * @tc.steps3: Convert the HTML back to SpanString and verify if the spans are correctly restored.
907      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
908      */
909     HtmlToSpan toSpan;
910     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
911     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
912 }
913 
914 /**
915  * @tc.name: HtmlConvert010
916  * @tc.desc: This test case checks the overlapping of background color spans and text shadow spans in a `SpanString`.
917  *           It ensures that both styles are applied correctly without interference.
918  * @tc.level: 1
919  */
920 HWTEST_F(HtmlConvertTestNg, HtmlConvert010, TestSize.Level1)
921 {
922     /**
923      * @tc.steps1: Add background color and text shadow spans with overlapping ranges.
924      * @tc.expected: Both background color and text shadow should be applied correctly without any conflicts.
925      */
926     auto spanString = AceType::MakeRefPtr<SpanString>(u"Overlapping background and shadow styles");
927     NG::BorderRadiusProperty borderRadius;
928     TextBackgroundStyle textBackgroundStyle;
929     textBackgroundStyle.backgroundColor = Color::WHITE;
930     textBackgroundStyle.backgroundRadius = borderRadius;
931     spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 10));
932 
933     Shadow shadow1;
934     shadow1.SetBlurRadius(3.0);
935     shadow1.SetColor(Color::BLACK);
936     shadow1.SetOffsetX(1.0);
937     shadow1.SetOffsetY(1.0);
938     spanString->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(std::vector<Shadow>{shadow1}, 5, 15));
939 
940     // Convert to TLV and HTML
941     std::vector<uint8_t> buff;
942     spanString->EncodeTlv(buff);
943     EXPECT_GT(buff.size(), 0);
944 
945     /**
946      * @tc.steps2: Convert the SpanString to HTML and check for correctness.
947      * @tc.expected: The HTML conversion should correctly reflect both background color and text shadow styles.
948      */
949     SpanToHtml toHtml;
950     auto htmlFromSpan = toHtml.ToHtml(*spanString);
951 
952     /**
953      * @tc.steps3: Convert the HTML back to SpanString and validate if it matches the original SpanString.
954      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
955      */
956     HtmlToSpan toSpan;
957     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
958     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
959 }
960 
961 /**
962  * @tc.name: HtmlConvert011
963  * @tc.desc: This test case checks the overlapping of font spans, letter spacing spans, and background color spans.
964  *           It ensures that all styles are applied correctly without any conflicts between them.
965  * @tc.level: 1
966  */
967 HWTEST_F(HtmlConvertTestNg, HtmlConvert011, TestSize.Level1)
968 {
969     /**
970      * @tc.steps1: Add font, letter spacing, and background color spans with overlapping ranges.
971      * @tc.expected: All three styles (font, letter spacing, and background color) should be applied correctly.
972      */
973     auto spanString = AceType::MakeRefPtr<SpanString>(u"Overlapping font, letter spacing, and background styles");
974     spanString->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10));
975     spanString->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(4), 5, 15));
976 
977     NG::BorderRadiusProperty borderRadius;
978     TextBackgroundStyle textBackgroundStyle;
979     textBackgroundStyle.backgroundColor = Color::RED;
980     textBackgroundStyle.backgroundRadius = borderRadius;
981     spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 10));
982 
983     // Convert to TLV and HTML
984     std::vector<uint8_t> buff;
985     spanString->EncodeTlv(buff);
986     EXPECT_GT(buff.size(), 0);
987 
988     /**
989      * @tc.steps2: Convert the SpanString to HTML and verify the result.
990      * @tc.expected: The HTML conversion should correctly reflect all three styles
991      *               (font, letter spacing, and background).
992      */
993     SpanToHtml toHtml;
994     auto htmlFromSpan = toHtml.ToHtml(*spanString);
995 
996     /**
997      * @tc.steps3: Convert the HTML back to SpanString and validate if it matches the original SpanString.
998      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
999      */
1000     HtmlToSpan toSpan;
1001     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
1002     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1003 }
1004 
1005 /**
1006  * @tc.name: HtmlConvert012
1007  * @tc.desc: This test case checks the conversion of a SpanString containing English and Chinese.
1008  *           It ensures these characters are handled properly in both TLV and HTML conversions.
1009  * @tc.level: 1
1010  */
1011 HWTEST_F(HtmlConvertTestNg, HtmlConvert012, TestSize.Level1)
1012 {
1013     /**
1014      * @tc.steps1: Create a SpanString with English and Chinese.
1015      * @tc.expected: The SpanString should correctly preserve and handle these special characters during conversion.
1016      */
1017     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello World, Friends 你好,世界,朋友们。");
1018 
1019     // Convert to TLV format
1020     std::vector<uint8_t> buff;
1021     spanString->EncodeTlv(buff);
1022     EXPECT_EQ(buff.size() > 0, true);
1023 
1024     /**
1025      * @tc.steps2: Convert the TLV buffer to HTML and compare it with the result from SpanString conversion.
1026      * @tc.expected: The HTML string should match the result of directly converting the SpanString with
1027      *               English and Chinese.
1028      */
1029     SpanToHtml toHtml;
1030     auto htmlFromU8 = toHtml.ToHtml(buff);
1031     auto htmlFromSpan = toHtml.ToHtml(*spanString);
1032     EXPECT_EQ(htmlFromU8, htmlFromSpan);
1033 
1034     /**
1035      * @tc.steps3: Convert the HTML back to SpanString and check if it matches the original SpanString.
1036      * @tc.expected: The SpanString obtained from the HTML should match the original SpanString.
1037      */
1038     HtmlToSpan toSpan;
1039     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
1040     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1041 
1042     /**
1043      * @tc.steps4: Convert the final SpanString back to HTML and ensure consistency with the initial HTML.
1044      * @tc.expected: The final HTML should match the HTML obtained before the conversion to SpanString.
1045      */
1046     SpanToHtml toHtml1;
1047     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1048     EXPECT_EQ(hmtlString, htmlFromSpan);
1049 }
1050 
1051 /**
1052  * @tc.name: HtmlConvert013
1053  * @tc.desc: This test case ensures that containing English and Chinese in a `SpanString`
1054  *           are properly encoded and decoded during the conversion process.
1055  * @tc.level: 1
1056  */
1057 HWTEST_F(HtmlConvertTestNg, HtmlConvert013, TestSize.Level1)
1058 {
1059     /**
1060      * @tc.steps1: Create a SpanString with special characters and encode it.
1061      * @tc.expected: The special characters should be properly encoded and decoded in HTML.
1062      */
1063     auto spanString = AceType::MakeRefPtr<SpanString>(
1064         u"Hello World Friends!\n你好,世界,朋友们。\nTest!测试!SpanString");
1065 
1066     // Convert to TLV and HTML
1067     std::vector<uint8_t> buff;
1068     spanString->EncodeTlv(buff);
1069     EXPECT_GT(buff.size(), 0);
1070 
1071     /**
1072      * @tc.steps2: Convert the TLV buffer to HTML format and verify the result.
1073      * @tc.expected: The HTML conversion should correctly encode the special characters.
1074      */
1075     SpanToHtml toHtml;
1076     auto htmlFromSpan = toHtml.ToHtml(*spanString);
1077 
1078     /**
1079      * @tc.steps3: Convert the HTML back to SpanString and check for correctness.
1080      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
1081      */
1082     HtmlToSpan toSpan;
1083     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
1084     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1085 
1086     /**
1087      * @tc.steps4: Convert the final SpanString back to HTML and ensure it matches the initial HTML.
1088      * @tc.expected: The final HTML should match the original HTML obtained from the SpanString.
1089      */
1090     SpanToHtml toHtml1;
1091     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1092     EXPECT_EQ(hmtlString, htmlFromSpan);
1093 }
1094 
1095 /**
1096  * @tc.name: HtmlConvert014
1097  * @tc.desc: This test case ensures that newline and tab characters in a `SpanString` are
1098  *           correctly processed during conversion.
1099  * @tc.level: 1
1100  */
1101 HWTEST_F(HtmlConvertTestNg, HtmlConvert014, TestSize.Level1)
1102 {
1103     /**
1104      * @tc.steps1: Create a SpanString with newline and tab characters and verify proper conversion.
1105      * @tc.expected: Newline and tab characters should be retained correctly in the conversion process.
1106      */
1107     auto spanString = AceType::MakeRefPtr<SpanString>(u"Hello\tWorld!\nThis is a test.");
1108 
1109     // Convert to TLV and HTML
1110     std::vector<uint8_t> buff;
1111     spanString->EncodeTlv(buff);
1112     EXPECT_GT(buff.size(), 0);
1113 
1114     /**
1115      * @tc.steps2: Convert the TLV buffer to HTML format and verify the result.
1116      * @tc.expected: The HTML conversion should correctly encode the newline and tab characters.
1117      */
1118     SpanToHtml toHtml;
1119     auto htmlFromSpan = toHtml.ToHtml(*spanString);
1120 
1121     /**
1122      * @tc.steps3: Convert the HTML back to SpanString and check for correctness.
1123      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
1124      */
1125     HtmlToSpan toSpan;
1126     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
1127     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1128 
1129     /**
1130      * @tc.steps4: Convert the final SpanString back to HTML and ensure it matches the initial HTML.
1131      * @tc.expected: The final HTML should match the original HTML obtained from the SpanString.
1132      */
1133     SpanToHtml toHtml1;
1134     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1135     EXPECT_EQ(hmtlString, htmlFromSpan);
1136 }
1137 
1138 /**
1139  * @tc.name: HtmlConvert015
1140  * @tc.desc: This test case checks the conversion of a SpanString with long text content.
1141  *           It ensures that long text is correctly handled in both TLV and HTML conversions.
1142  * @tc.level: 1
1143  */
1144 HWTEST_F(HtmlConvertTestNg, HtmlConvert015, TestSize.Level1)
1145 {
1146     /**
1147      * @tc.steps1: Create a SpanString with a long text (over 1000 characters).
1148      * @tc.expected: The SpanString with long text should be handled properly during
1149      *               conversion to TLV and HTML formats.
1150      */
1151     std::u16string longText = u"Hello World! " + std::u16string(1000, u'X') + u" Test with long text.";
1152     auto spanString = AceType::MakeRefPtr<SpanString>(longText);
1153 
1154     // Convert to TLV format
1155     std::vector<uint8_t> buff;
1156     spanString->EncodeTlv(buff);
1157     EXPECT_EQ(buff.size() > 0, true);
1158 
1159     /**
1160      * @tc.steps2: Convert the TLV buffer to HTML and compare with the direct SpanString to HTML conversion.
1161      * @tc.expected: The HTML obtained from TLV and from SpanString should be identical.
1162      */
1163     SpanToHtml toHtml;
1164     auto htmlFromU8 = toHtml.ToHtml(buff);
1165     auto htmlFromSpan = toHtml.ToHtml(*spanString);
1166     EXPECT_EQ(htmlFromU8, htmlFromSpan);
1167 
1168     /**
1169      * @tc.steps3: Convert the HTML back to SpanString and verify consistency with the original SpanString.
1170      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
1171      */
1172     HtmlToSpan toSpan;
1173     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
1174     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1175 
1176     /**
1177      * @tc.steps4: Convert the final SpanString back to HTML and check for consistency with the original HTML.
1178      * @tc.expected: The final HTML should match the initial HTML result.
1179      */
1180     SpanToHtml toHtml1;
1181     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1182     EXPECT_EQ(hmtlString, htmlFromSpan);
1183 }
1184 
1185 /**
1186  * @tc.name: HtmlConvert016
1187  * @tc.desc: This test case checks how `SpanString` handles very long text inputs and ensures that the conversion
1188  *           process still works efficiently with long texts.
1189  * @tc.level: 1
1190  */
1191 HWTEST_F(HtmlConvertTestNg, HtmlConvert016, TestSize.Level1)
1192 {
1193     /**
1194      * @tc.steps1: Create a long text string and verify its conversion to TLV and HTML formats.
1195      * @tc.expected: Long text should be handled without errors, and conversion should retain all data.
1196      */
1197     std::u16string longText = u"Long text testing " + std::u16string(5000, u'X');
1198     auto spanString = AceType::MakeRefPtr<SpanString>(longText);
1199 
1200     // Convert to TLV and HTML
1201     std::vector<uint8_t> buff;
1202     spanString->EncodeTlv(buff);
1203     EXPECT_GT(buff.size(), 0);
1204 
1205     /**
1206      * @tc.steps2: Convert the TLV buffer to HTML format and verify the result.
1207      * @tc.expected: The HTML conversion should correctly handle long text.
1208      */
1209     SpanToHtml toHtml;
1210     auto htmlFromSpan = toHtml.ToHtml(*spanString);
1211 
1212     /**
1213      * @tc.steps3: Convert the HTML back to SpanString and check for correctness.
1214      * @tc.expected: The SpanString obtained from HTML should match the original SpanString.
1215      */
1216     HtmlToSpan toSpan;
1217     auto spanFromHtml = toSpan.ToSpanString(htmlFromSpan);
1218     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString->GetSpanItems()), true);
1219 
1220     /**
1221      * @tc.steps4: Convert the final SpanString back to HTML and ensure it matches the initial HTML.
1222      * @tc.expected: The final HTML should match the original HTML obtained from the SpanString.
1223      */
1224     SpanToHtml toHtml1;
1225     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1226     EXPECT_EQ(hmtlString, htmlFromSpan);
1227 }
1228 
1229 /**
1230  * @tc.name: HtmlConvert017
1231  * @tc.desc: This test case checks the conversion of a SpanString that includes nested SpanStrings.
1232  *           It ensures that nested spans are correctly handled and converted between formats.
1233  * @tc.level: 1
1234  */
1235 HWTEST_F(HtmlConvertTestNg, HtmlConvert017, TestSize.Level1)
1236 {
1237     /**
1238      * @tc.steps1: Create a SpanString that contains other SpanStrings (nested).
1239      * @tc.expected: The nested SpanStrings should be correctly handled and maintained during conversion.
1240      */
1241     auto spanString1 = AceType::MakeRefPtr<SpanString>(u"Hello");
1242 
1243     // Convert to TLV format
1244     std::vector<uint8_t> buff;
1245     spanString1->EncodeTlv(buff);
1246     EXPECT_EQ(buff.size() > 0, true);
1247 
1248     /**
1249      * @tc.steps2: Convert the TLV buffer to HTML and compare with the direct SpanString to HTML conversion.
1250      * @tc.expected: The HTML string should match the result of converting the nested SpanString directly to HTML.
1251      */
1252     SpanToHtml toHtml;
1253     auto htmlFromU8 = toHtml.ToHtml(buff);
1254     auto htmlFromSpan = toHtml.ToHtml(*spanString1);
1255     EXPECT_EQ(htmlFromU8, htmlFromSpan);
1256 
1257     /**
1258      * @tc.steps3: Convert the HTML back to SpanString and verify if it matches the original nested SpanString.
1259      * @tc.expected: The SpanString obtained from HTML should match the original nested SpanString.
1260      */
1261     HtmlToSpan toSpan;
1262     auto spanFromHtml = toSpan.ToSpanString(htmlFromU8);
1263     EXPECT_EQ(IsSpanItemSame(spanFromHtml->GetSpanItems(), spanString1->GetSpanItems()), true);
1264 
1265     /**
1266      * @tc.steps4: Convert the final SpanString back to HTML and check if it matches the initial HTML.
1267      * @tc.expected: The final HTML should match the initial HTML obtained from the nested SpanString.
1268      */
1269     SpanToHtml toHtml1;
1270     auto hmtlString = toHtml1.ToHtml(*spanFromHtml);
1271     EXPECT_EQ(hmtlString, htmlFromSpan);
1272 }
1273 
1274 /**
1275  * @tc.name: HtmlConvertPriorityText
1276  * @tc.desc: This test case checks the conversion priority of html text
1277  *           where inner attribute has the higher priority.
1278  * @tc.level: 1
1279  */
1280 HWTEST_F(HtmlConvertTestNg, HtmlConvertPriorityText, TestSize.Level1)
1281 {
1282     const std::string html = "<p style=\"font-size: 20px; color: blue\">\n"
1283         "test1\n<span style=\"color: red;\">test2</span>\ntest3\n<strong>strong1</strong>\ntest4\n</p>";
1284     HtmlToSpan toSpan;
1285     auto dstSpan = toSpan.ToSpanString(html);
1286     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1287     EXPECT_EQ(spans.size(), 9);
1288     auto it = spans.begin();
1289     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(20, DimensionUnit::VP));
1290     ++it;
1291     ++it;
1292     EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), Color::RED);
1293     ++it;
1294     ++it;
1295     ++it;
1296     EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), FontWeight::BOLD);
1297 }
1298 
1299 /**
1300  * @tc.name: HtmlConverter001
1301  * @tc.desc: This test case checks the conversion of a span string with a font-family property applied.
1302  *           It verifies that the font-family attribute is correctly parsed and converted into a SpanItem.
1303  * @tc.level: 1
1304  */
1305 HWTEST_F(HtmlConvertTestNg, HtmlConverter001, TestSize.Level1)
1306 {
1307     /**
1308      * @tc.steps1: Create a multiHtml string containing a <p> tag with a font-family property.
1309      *             Convert it to SpanString and retrieve the font-family from the span item.
1310      * @tc.expected: The font-family property should be correctly converted and retrieved.
1311      */
1312     const std::string multiHtml = "<html>"
1313                                   "<body>"
1314                                   "<p style=\"font-family:'Times New Roman', serif;\">Times New Roman 字体</p>"
1315                                   "</body>"
1316                                   "</html>";
1317     HtmlToSpan toSpan;
1318     auto dstSpan = toSpan.ToSpanString(multiHtml);
1319     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1320     EXPECT_EQ(spans.size(), 1);
1321 }
1322 
1323 /**
1324  * @tc.name: HtmlConverter002
1325  * @tc.desc: This test case checks the conversion of a span string with font-size and letter-spacing applied.
1326  *           It ensures that the font size and letter spacing are correctly converted into SpanItem properties.
1327  * @tc.level: 1
1328  */
1329 HWTEST_F(HtmlConvertTestNg, HtmlConverter002, TestSize.Level1)
1330 {
1331     /**
1332      * @tc.steps1: Create a multiHtml string containing a <p> tag with font-size and letter-spacing properties.
1333      *             Convert it to SpanString and retrieve the font size and letter spacing from the span item.
1334      * @tc.expected: The font-size and letter-spacing properties should be correctly converted and retrieved.
1335      */
1336     const std::string multiHtml = "<html>"
1337                                   "<body>"
1338                                   "<p style=\"font-size:18px;letter-spacing:2px;\">带字间距的文字</p>"
1339                                   "</body>"
1340                                   "</html>";
1341     HtmlToSpan toSpan;
1342     auto dstSpan = toSpan.ToSpanString(multiHtml);
1343     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1344     EXPECT_EQ(spans.size(), 1);
1345     auto it = spans.begin();
1346     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(18, DimensionUnit::VP));
1347     EXPECT_EQ((*it)->fontStyle->GetLetterSpacing().value(), Dimension(2, DimensionUnit::VP));
1348 }
1349 
1350 /**
1351  * @tc.name: HtmlConverter003
1352  * @tc.desc: This test case checks the conversion of a span string with text-decoration and color applied.
1353  *           It verifies that the text-decoration (line-through) and text color are correctly
1354  *           converted into SpanItem properties.
1355  * @tc.level: 1
1356  */
1357 HWTEST_F(HtmlConvertTestNg, HtmlConverter003, TestSize.Level1)
1358 {
1359     /**
1360      * @tc.steps1: Create a multiHtml string containing a <p> tag with text-decoration and color properties.
1361      *             Convert it to SpanString and retrieve the text-decoration and text color from the span item.
1362      * @tc.expected: The text-decoration (line-through) and text color (blue) properties should be
1363      *               correctly converted and retrieved.
1364      */
1365     const std::string multiHtml = "<html>"
1366                                   "<body>"
1367                                   "<p style=\"text-decoration:line-through;color:blue;\">带删除线的蓝色文字</p>"
1368                                   "</body>"
1369                                   "</html>";
1370     HtmlToSpan toSpan;
1371     auto dstSpan = toSpan.ToSpanString(multiHtml);
1372     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1373     EXPECT_EQ(spans.size(), 1);
1374     auto it = spans.begin();
1375     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::LINE_THROUGH);
1376 }
1377 
1378 /**
1379  * @tc.name: HtmlConverter004
1380  * @tc.desc: This test case checks the conversion of a span string with font-size, color,
1381  *           and text-decoration properties applied.
1382  *           It ensures that all three properties are correctly converted into SpanItem properties.
1383  * @tc.level: 1
1384  */
1385 HWTEST_F(HtmlConvertTestNg, HtmlConverter004, TestSize.Level1)
1386 {
1387     /**
1388      * @tc.steps1: Create a multiHtml string containing a <p> tag with font-size, color,
1389      *             and text-decoration properties. Convert it to SpanString and retrieve
1390      *             the font size, text color, and text-decoration from the span item.
1391      * @tc.expected: The font-size (16px), text color (red), and text-decoration (underline)
1392      *               properties should be correctly converted and retrieved.
1393      */
1394     const std::string multiHtml = "<html>"
1395                                   "<body>"
1396                                   "<p style=\"font-size:16px;color:red;text-decoration:underline;\">"
1397                                   "带下划线的红色小字体</p>"
1398                                   "</body>"
1399                                   "</html>";
1400     HtmlToSpan toSpan;
1401     auto dstSpan = toSpan.ToSpanString(multiHtml);
1402     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1403     EXPECT_EQ(spans.size(), 1);
1404     auto it = spans.begin();
1405     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(16, DimensionUnit::VP));
1406     EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), OHOS::Ace::Color::RED);
1407 }
1408 
1409 /**
1410  * @tc.name: HtmlConverter005
1411  * @tc.desc: This test case checks the conversion of a span string with font-weight and font-style properties applied.
1412  *           It ensures that both the font-weight (bold) and font-style (italic) are correctly converted into SpanItem.
1413  * @tc.level: 1
1414  */
1415 HWTEST_F(HtmlConvertTestNg, HtmlConverter005, TestSize.Level1)
1416 {
1417     /**
1418      * @tc.steps1: Create a multiHtml string containing a <p> tag with font-weight (bold) and font-style (italic).
1419      *             Convert it to SpanString and retrieve the font-weight and font-style from the span item.
1420      * @tc.expected: The font-weight (bold) and font-style (italic) should be correctly converted and retrieved.
1421      */
1422     const std::string multiHtml = "<html>"
1423                                   "<body>"
1424                                   "<p style=\"font-weight:bold;font-style:italic;\">加粗斜体文字</p>"
1425                                   "</body>"
1426                                   "</html>";
1427     HtmlToSpan toSpan;
1428     auto dstSpan = toSpan.ToSpanString(multiHtml);
1429     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1430     EXPECT_EQ(spans.size(), 1);
1431     auto it = spans.begin();
1432     EXPECT_TRUE((*it)->fontStyle->GetFontWeight().has_value());
1433     EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), FontWeight::BOLD);
1434     EXPECT_TRUE((*it)->fontStyle->GetItalicFontStyle().has_value());
1435 }
1436 
1437 /**
1438  * @tc.name: HtmlConverter006
1439  * @tc.desc: This test case checks the conversion of a span string with nested font-size properties.
1440  *           It ensures that the correct font-size is applied for each nested span element.
1441  * @tc.level: 1
1442  */
1443 HWTEST_F(HtmlConvertTestNg, HtmlConverter006, TestSize.Level1)
1444 {
1445     /**
1446      * @tc.steps1: Create a multiHtml string containing a <p> tag with nested <span> tags have different font-size.
1447      *             Convert it to SpanString and retrieve the font-size for each span item.
1448      * @tc.expected: The nested <span> tags should correctly apply the respective font-size (100px and 50px).
1449      */
1450     const std::string multiHtml = "<html>"
1451                                   "<body>"
1452                                   "<p style=\"font-size:50px\"><span style=\"font-size:100px\">100px</span>50px</p>"
1453                                   "</body>"
1454                                   "</html>";
1455     HtmlToSpan toSpan;
1456     auto dstSpan = toSpan.ToSpanString(multiHtml);
1457     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1458     EXPECT_EQ(spans.size(), 2);
1459     auto it = spans.begin();
1460     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(100, DimensionUnit::VP));
1461 }
1462 
1463 /**
1464  * @tc.name: HtmlConverter007
1465  * @tc.desc: This test case checks the conversion of a span string with font-size and text-shadow properties applied.
1466  *           It ensures that both the font-size and text-shadow are correctly converted into SpanItem properties.
1467  * @tc.level: 1
1468  */
1469 HWTEST_F(HtmlConvertTestNg, HtmlConverter007, TestSize.Level1)
1470 {
1471     /**
1472      * @tc.steps1: Create a multiHtml string containing a <p> tag with font-size and text-shadow properties.
1473      *             Convert it to SpanString and retrieve the font-size and text-shadow from the span item.
1474      * @tc.expected: The font-size (50px) and text-shadow (red and green shadows) should be correctly converted.
1475      */
1476     const std::string multiHtml = "<html>"
1477                                   "<body>"
1478                                   "<p style=\"font-size:50px;text-shadow:0 0 3px red, green 0 0;\">"
1479                                   "带有字体大小和阴影的文字</p>"
1480                                   "</body>"
1481                                   "</html>";
1482     HtmlToSpan toSpan;
1483     auto dstSpan = toSpan.ToSpanString(multiHtml);
1484     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1485     EXPECT_EQ(spans.size(), 1);
1486     auto it = spans.begin();
1487     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(50, DimensionUnit::VP));
1488     EXPECT_EQ((*it)->fontStyle->GetTextShadow().value()[0].GetColor(), OHOS::Ace::Color::RED);
1489 }
1490 
1491 /**
1492  * @tc.name: HtmlConverter008
1493  * @tc.desc: This test case checks the conversion of HTML with multiple inline styles
1494  *           applied to various elements like `span`, `strong`, and `em`, ensuring correct styling.
1495  * @tc.level: 1
1496  */
1497 HWTEST_F(HtmlConvertTestNg, HtmlConverter008, TestSize.Level1)
1498 {
1499     /**
1500      * @tc.steps1: Create a complex HTML with multiple inline styles, such as `em`, and `span`,
1501      *             to check the proper conversion to span strings.
1502      * @tc.expected: All inline styles such as font weight, font style, and color should be applied correctly.
1503      */
1504     const std::string multiHtml = "<html>"
1505                                   "<body>"
1506                                   "<p><strong>Text</strong> and "
1507                                   "<em style=\"font-style:italic; color:blue;\">Italic Blue</em> and "
1508                                   "<span style=\"font-size:14px; color:green;\">Green 14px</span></p>"
1509                                   "</body>"
1510                                   "</html>";
1511     HtmlToSpan toSpan;
1512     auto dstSpan = toSpan.ToSpanString(multiHtml);
1513 
1514     /**
1515      * @tc.steps2: Verify the size of the converted `SpanString`. It should have 5 span items.
1516      * @tc.expected: The size of the spans list should be 5.
1517      */
1518     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1519     EXPECT_EQ(spans.size(), 5);
1520 
1521     /**
1522      * @tc.steps3: Verify the first span item, which should have a bold font weight.
1523      * @tc.expected: The first span item should have font weight set to bold.
1524      */
1525     auto it = spans.begin();
1526     EXPECT_TRUE((*it)->fontStyle->GetFontWeight().has_value());
1527     EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), FontWeight::BOLD);
1528 
1529     /**
1530      * @tc.steps4: Verify the third span item, which should have an italic font style and blue color.
1531      * @tc.expected: The third span item should have italic font style and color set to blue.
1532      */
1533     ++it;
1534     ++it;
1535     EXPECT_TRUE((*it)->fontStyle->GetTextColor().has_value());
1536     EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), Color::BLUE);
1537     EXPECT_TRUE((*it)->fontStyle->GetItalicFontStyle().has_value());
1538     EXPECT_EQ((*it)->fontStyle->GetItalicFontStyle().value(), Ace::FontStyle::ITALIC);
1539 
1540     /**
1541      * @tc.steps5: Verify the fifth span item, which should have a font size of 14px and green color.
1542      * @tc.expected: The fifth span item should have font size set to 14px and color set to green.
1543      */
1544     ++it;
1545     ++it;
1546     EXPECT_TRUE((*it)->fontStyle->GetTextColor().has_value());
1547     EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), Color::GREEN);
1548     EXPECT_TRUE((*it)->fontStyle->GetFontSize().has_value());
1549     EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(14, DimensionUnit::VP));
1550 }
1551 
1552 /**
1553  * @tc.name: HtmlConverter009
1554  * @tc.desc: This test case checks the conversion of HTML with nested `span` tags with
1555  *           varying `text-shadow` and `background-color`.
1556  * @tc.level: 1
1557  */
1558 HWTEST_F(HtmlConvertTestNg, HtmlConverter009, TestSize.Level1)
1559 {
1560     /**
1561      * @tc.steps1: Create a nested HTML structure with `span` elements having `text-shadow` and `background-color`.
1562      * @tc.expected: Nested `span` tags should preserve both text-shadow and background color styles correctly.
1563      */
1564     const std::string multiHtml = "<html>"
1565                                   "<body>"
1566                                   "<p>"
1567                                   "<span style=\"text-shadow:2px 2px 4px #000000; background-color:#ffcc00;\">"
1568                                   "Shadowed and Colored Text</span></p>"
1569                                   "</body>"
1570                                   "</html>";
1571     HtmlToSpan toSpan;
1572     auto dstSpan = toSpan.ToSpanString(multiHtml);
1573 
1574     /**
1575      * @tc.steps2: Verify the size of the converted `SpanString`. It have 1 span item for the single `span` tag.
1576      * @tc.expected: The size of the spans list should be 1.
1577      */
1578     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1579     EXPECT_EQ(spans.size(), 1);
1580 
1581     /**
1582      * @tc.steps3: Verify the text shadow applied to the span. It should have a shadow with the specified parameters.
1583      * @tc.expected: The text-shadow should have a 2px offset, 4px blur, and black color.
1584      */
1585     auto it = spans.begin();
1586     EXPECT_EQ((*it)->fontStyle->GetTextShadow().value()[0].GetColor(), OHOS::Ace::Color::BLACK);
1587 }
1588 
1589 /**
1590  * @tc.name: HtmlConverter010
1591  * @tc.desc: This test case checks the conversion of HTML with `div` elements having
1592  *           padding, margin, and background color.
1593  * @tc.level: 1
1594  */
1595 HWTEST_F(HtmlConvertTestNg, HtmlConverter010, TestSize.Level1)
1596 {
1597     /**
1598      * @tc.steps1: Create a `div` element with padding, margin, and background color.
1599      * @tc.expected: Padding, margin, and background color styles should be correctly applied to the div content.
1600      */
1601     const std::string multiHtml = "<html>"
1602                                   "<body>"
1603                                   "<div style=\"padding:10px; margin:5px; background-color:#f4f4f4;\">"
1604                                   "Styled Div Content</div>"
1605                                   "</body>"
1606                                   "</html>";
1607     HtmlToSpan toSpan;
1608     auto dstSpan = toSpan.ToSpanString(multiHtml);
1609 
1610     /**
1611      * @tc.steps2: Verify the size of the converted `SpanString`. It should have 1 span item for the `div` tag.
1612      * @tc.expected: The size of the spans list should be 1.
1613      */
1614     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1615     EXPECT_EQ(spans.size(), 1);
1616 }
1617 
1618 
1619 /**
1620  * @tc.name: HtmlConverter011
1621  * @tc.desc: This test case checks the conversion of HTML containing a paragraph with a red text color.
1622  *           It ensures that the correct color is applied to the text in the resulting SpanItem.
1623  * @tc.level: 1
1624  */
1625 HWTEST_F(HtmlConvertTestNg, HtmlConverter011, TestSize.Level1)
1626 {
1627     /**
1628      * @tc.steps1: Initialize a multi-line HTML string with a paragraph containing red text color.
1629      *             Convert the HTML to SpanString and verify the text color.
1630      * @tc.expected: The text color of the span should be red.
1631      */
1632     const std::string multiHtml = "<html>"
1633                                   "<body>"
1634                                   "<p style=\"color:red;\">dddd当地经的123456</p>"
1635                                   "</body>"
1636                                   "</html>";
1637     HtmlToSpan toSpan;
1638     auto dstSpan = toSpan.ToSpanString(multiHtml);
1639     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1640     EXPECT_EQ(spans.size(), 1);
1641     auto it = spans.begin();
1642     EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), OHOS::Ace::Color::RED);
1643 }
1644 
1645 
1646 /**
1647  * @tc.name: HtmlConverter012
1648  * @tc.desc: This test case checks the conversion of a SpanString with basic spanParagraphStyle.
1649  *           It ensures that the span string is correctly converted to HTML with the specified styles.
1650  * @tc.level: 1
1651  */
1652 HWTEST_F(HtmlConvertTestNg, HtmlConverter012, TestSize.Level1)
1653 {
1654     auto spanString = AceType::MakeRefPtr<SpanString>(u"段落标题\n正文第一段开始");
1655     SpanParagraphStyle spanParagraphStyle;
1656     spanParagraphStyle.align = TextAlign::CENTER;
1657 
1658     // default max lines 4
1659     spanParagraphStyle.maxLines = 4;
1660     spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1661     spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1662 
1663     // defalut textIndent 23
1664     spanParagraphStyle.textIndent = Dimension(23.0_vp);
1665     spanParagraphStyle.leadingMargin = LeadingMargin();
1666 
1667     // default width 25.0 height 26.0
1668     spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0_vp), Dimension(26.0));
1669     auto paragraphStyle = AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 5);
1670     spanString->AddSpan(paragraphStyle);
1671 
1672     SpanToHtml convert;
1673     auto out = convert.ToHtml(*spanString);
1674     std::string result =
1675         "<div ><p style=\"text-align: center;text-indent: 23.00px;word-break: break_all;text-overflow: ellipsis;\">"
1676         "<span style=\"font-size: 16.00px;font-style: normal;font-weight: normal;color: #000000FF;font-family: "
1677         "HarmonyOS Sans;stroke-width: 0.00px;stroke-color: #000000FF;font-superscript: normal;\">段落标题</span>"
1678         "</p><span style=\"font-size: 16.00px;font-style: normal;font-weight: normal;color: #000000FF;"
1679         "font-family: HarmonyOS Sans;stroke-width: 0.00px;stroke-color: #000000FF;font-superscript: normal;\">"
1680         "正文第一段开始</span></div>";
1681     EXPECT_EQ(out, result);
1682 }
1683 
1684 /**
1685  * @tc.name: HtmlConverter013
1686  * @tc.desc: This test case checks the conversion of a SpanString with spanString.
1687  *           It ensures that the span string is correctly converted to HTML with the specified styles.
1688  * @tc.level: 1
1689  */
1690 HWTEST_F(HtmlConvertTestNg, HtmlConverter013, TestSize.Level1)
1691 {
1692     auto spanString = AceType::MakeRefPtr<SpanString>(u"向上到顶适中向下到底");
1693     spanString->AddSpan(AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(20.0_vp), 0, 4));
1694     spanString->AddSpan(AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(10.0_vp), 4, 6));
1695 
1696     SpanToHtml convert;
1697     auto out = convert.ToHtml(*spanString);
1698     std::string result =
1699         "<div ><span style=\"font-size: 16.00px;font-style: normal;font-weight: normal;color: #000000FF;font-family: "
1700         "HarmonyOS Sans;stroke-width: 0.00px;stroke-color: #000000FF;font-superscript: normal;vertical-align: "
1701         "20.00px;\">向上到顶</span><span style=\"font-size: 16.00px;font-style: normal;font-weight: normal;color: "
1702         "#000000FF;font-family: HarmonyOS Sans;stroke-width: 0.00px;stroke-color: #000000FF;font-superscript: "
1703         "normal;vertical-align: 10.00px;\">适中</span><span style=\"font-size: 16.00px;font-style: normal;"
1704         "font-weight: normal;color: #000000FF;font-family: HarmonyOS Sans;stroke-width: 0.00px;"
1705         "stroke-color: #000000FF;font-superscript: normal;\">向下到底</span></div>";
1706     EXPECT_EQ(out, result);
1707 }
1708 
1709 /**
1710  * @tc.name: HtmlConverter014
1711  * @tc.desc: This test case checks the conversion of a string that includes some style.
1712  * @tc.level: 1
1713  */
1714 HWTEST_F(HtmlConvertTestNg, HtmlConverter014, TestSize.Level1)
1715 {
1716     const std::string multiHtml =
1717         "<html>"
1718         "<body>"
1719         "<p style=\"font-size:50px\"><span style=\"font-size:100px\">100fontsize</span>dddd当地经的123456<span "
1720         "style=\"font-size:30px\">30fontsize</span>1232132</p>"
1721         "</body>"
1722         "</html>";
1723     HtmlToSpan toSpan;
1724     auto dstSpan = toSpan.ToSpanString(multiHtml);
1725     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1726     EXPECT_EQ(spans.size(), 4);
1727 
1728     SpanToHtml convert;
1729     auto dstHtml = convert.ToHtml(*dstSpan);
1730     HtmlToSpan toSpan1;
1731     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1732     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1733     auto secondHtml = convert.ToHtml(*dstSpan1);
1734     EXPECT_EQ(secondHtml, dstHtml);
1735 }
1736 
1737 /**
1738  * @tc.name: HtmlConverter015
1739  * @tc.desc: This test case checks the conversion of a string that includes more style.
1740  * @tc.level: 1
1741  */
1742 HWTEST_F(HtmlConvertTestNg, HtmlConverter015, TestSize.Level1)
1743 {
1744     const std::string multiHtml =
1745         "<html>"
1746         "<head>"
1747         "</head>"
1748         "<body>"
1749         "<p style=\"font-size:50px;text-shadow: 0 0 3px red, green 0 0;\">"
1750         "<span style=\"font-size:100px\">100fontsize</span>dddd当地经的123456<span "
1751         "style=\"font-size:30px\">30fontsize</span>1232132</p>"
1752         "</body>"
1753         "</html>";
1754     HtmlToSpan toSpan;
1755     auto dstSpan = toSpan.ToSpanString(multiHtml);
1756     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
1757     EXPECT_EQ(spans.size(), 4);
1758     auto it = spans.begin();
1759     EXPECT_EQ((*it)->fontStyle->GetTextShadow().value()[0].GetColor(), OHOS::Ace::Color::RED);
1760     EXPECT_EQ((*it)->fontStyle->GetTextShadow().value()[1].GetColor(), OHOS::Ace::Color::GREEN);
1761 }
1762 
1763 /**
1764  * @tc.name: HtmlConvertExam001
1765  * @tc.desc: This test case checks the conversion of a SpanString with basic text color and font size.
1766  *           It ensures that the HTML conversion correctly applies the font size and text color.
1767  * @tc.level: 1
1768  */
1769 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam001, TestSize.Level1)
1770 {
1771     /**
1772      * @tc.steps1: Create a SpanString with the text and apply the basic paragraph style with
1773      *             font-size (50px) and text color (red).
1774      * @tc.expected: The generated HTML should include basic font size and text color styles.
1775      */
1776     const std::string multiHtml =
1777         "<html>"
1778         "<head>"
1779         "</head>"
1780         "<body>"
1781         "<p style=\"font-weight:bold;letter-spacing:5px;\">"
1782         "这是一个测试,检查字体为粗体,字符间距为5px的文本。"
1783         "</p>"
1784         "</body>"
1785         "</html>";
1786 
1787     /**
1788      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
1789      *             The result should match the original input HTML.
1790      * @tc.expected: The generated SpanString should match the original input HTML.
1791      */
1792     HtmlToSpan toSpan;
1793     auto dstSpan = toSpan.ToSpanString(multiHtml);
1794     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
1795     SpanToHtml convert;
1796 
1797     auto dstHtml = convert.ToHtml(*dstSpan);
1798     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
1799     HtmlToSpan toSpan1;
1800     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1801     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1802     auto secondHtml = convert.ToHtml(*dstSpan1);
1803     EXPECT_EQ(secondHtml, dstHtml);
1804 }
1805 
1806 /**
1807  * @tc.name: HtmlConvertExam002
1808  * @tc.desc: This test case checks the conversion of a SpanString with basic text color and font size.
1809  *           It ensures that the HTML conversion correctly applies the font size and text color.
1810  * @tc.level: 1
1811  */
1812 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam002, TestSize.Level1)
1813 {
1814     /**
1815      * @tc.steps1: Create a SpanString with the text and apply the basic paragraph style with
1816      *             font-size (50px) and text color (red).
1817      * @tc.expected: The generated SpanString should include basic font size and text color styles.
1818      */
1819     const std::string multiHtml =
1820         "<html>"
1821         "<head>"
1822         "</head>"
1823         "<body>"
1824         "<p style=\"font-size:50px;color:red;\">"
1825         "这是一个测试,检查字体颜色为红色,字体大小为50px的文本转换。"
1826         "</p>"
1827         "</body>"
1828         "</html>";
1829 
1830     /**
1831      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
1832      *             The result should match the original input HTML.
1833      * @tc.expected: The generated SpanString should match the original input HTML.
1834      */
1835     HtmlToSpan toSpan;
1836     auto dstSpan = toSpan.ToSpanString(multiHtml);
1837     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
1838     SpanToHtml convert;
1839 
1840     auto dstHtml = convert.ToHtml(*dstSpan);
1841     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
1842     HtmlToSpan toSpan1;
1843     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1844     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1845     auto secondHtml = convert.ToHtml(*dstSpan1);
1846     EXPECT_EQ(secondHtml, dstHtml);
1847 }
1848 
1849 /**
1850  * @tc.name: HtmlConvertExam003
1851  * @tc.desc: This test case checks the conversion of a SpanString with mixed font sizes and text shadow.
1852  *           It ensures that the HTML correctly applies different font sizes and text shadow effects.
1853  * @tc.level: 1
1854  */
1855 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam003, TestSize.Level1)
1856 {
1857     /**
1858      * @tc.steps1: Create a SpanString and apply the paragraph style with font-size (50px) and text shadow (red).
1859      * @tc.expected: The generated HTML should include the correct font size and shadow effect.
1860      */
1861     const std::string multiHtml =
1862         "<html>"
1863         "<head>"
1864         "</head>"
1865         "<body>"
1866         "<p style=\"font-size:50px;text-shadow:0px 0px 5px red;\">"
1867         "这段文本具有红色阴影效果,字体大小为50px,用于测试阴影和字体大小的转换。"
1868         "</p>"
1869         "</body>"
1870         "</html>";
1871 
1872     /**
1873      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
1874      *             The result should match the original input HTML.
1875      * @tc.expected: The generated SpanString should match the original input HTML.
1876      */
1877     HtmlToSpan toSpan;
1878     auto dstSpan = toSpan.ToSpanString(multiHtml);
1879     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
1880     SpanToHtml convert;
1881     auto dstHtml = convert.ToHtml(*dstSpan);
1882 
1883     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
1884     HtmlToSpan toSpan1;
1885     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1886     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1887     auto secondHtml = convert.ToHtml(*dstSpan1);
1888     EXPECT_EQ(secondHtml, dstHtml);
1889 }
1890 
1891 /**
1892  * @tc.name: HtmlConvertExam004
1893  * @tc.desc: This test case checks the conversion of a SpanString with bold and italic font styles.
1894  *           It ensures that the HTML applies the font styles correctly.
1895  * @tc.level: 1
1896  */
1897 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam004, TestSize.Level1)
1898 {
1899     /**
1900      * @tc.steps1: Create a SpanString with the text and apply the paragraph style with font-weight (bold)
1901      *             and font-style (italic).
1902      * @tc.expected: The generated HTML should include bold and italic font styles.
1903      */
1904     const std::string multiHtml =
1905         "<html>"
1906         "<head>"
1907         "</head>"
1908         "<body>"
1909         "<p style=\"font-size:50px;font-weight:bold;font-style:italic;\">"
1910         "这是加粗且斜体的文本,用于测试段落中的加粗和斜体字体样式。"
1911         "</p>"
1912         "</body>"
1913         "</html>";
1914 
1915     /**
1916      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
1917      *             The result should match the original input HTML.
1918      * @tc.expected: The generated SpanString should match the original input HTML.
1919      */
1920     HtmlToSpan toSpan;
1921     auto dstSpan = toSpan.ToSpanString(multiHtml);
1922     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
1923 
1924     SpanToHtml convert;
1925     auto dstHtml = convert.ToHtml(*dstSpan);
1926     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
1927     HtmlToSpan toSpan1;
1928     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1929     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1930     auto secondHtml = convert.ToHtml(*dstSpan1);
1931     EXPECT_EQ(secondHtml, dstHtml);
1932 }
1933 
1934 /**
1935  * @tc.name: HtmlConvertExam005
1936  * @tc.desc: This test case checks the conversion of a SpanString with mixed font sizes and colors.
1937  *           It ensures that different parts of the text have the correct font size and color.
1938  * @tc.level: 1
1939  */
1940 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam005, TestSize.Level1)
1941 {
1942     /**
1943      * @tc.steps1: Create a SpanString with the text and apply the paragraph style with font-size (50px) and
1944      *             color (red), and a span with font-size (30px) and color (blue).
1945      */
1946     const std::string multiHtml =
1947         "<html>"
1948         "<head>"
1949         "</head>"
1950         "<body>"
1951         "<p style=\"font-size:50px;color:red;\">"
1952         "这一部分为红色,字体大小50px,后面是<span style=\"font-size:30px;color:blue;\">蓝色30px字体</span>。"
1953         "</p>"
1954         "</body>"
1955         "</html>";
1956 
1957     /**
1958      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
1959      *             The result should match the original input HTML.
1960      * @tc.expected: The generated SpanString should match the original input HTML.
1961      */
1962     HtmlToSpan toSpan;
1963     auto dstSpan = toSpan.ToSpanString(multiHtml);
1964     EXPECT_EQ(dstSpan->GetSpanItems().size(), 3);
1965 
1966     SpanToHtml convert;
1967     auto dstHtml = convert.ToHtml(*dstSpan);
1968     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
1969     HtmlToSpan toSpan1;
1970     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
1971     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
1972     auto secondHtml = convert.ToHtml(*dstSpan1);
1973     EXPECT_EQ(secondHtml, dstHtml);
1974 }
1975 
1976 /**
1977  * @tc.name: HtmlConvertExam006
1978  * @tc.desc: This test case checks the conversion of a SpanString with underline and strikethrough.
1979  *           It ensures the HTML conversion applies the text decoration correctly.
1980  * @tc.level: 1
1981  */
1982 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam006, TestSize.Level1)
1983 {
1984     /**
1985      * @tc.steps1: Create a SpanString with the text and apply text-decoration (underline).
1986      *             Add a span with text-decoration (line-through).
1987      * @tc.expected: The generated SpanString should include the underline and strikethrough decoration.
1988      */
1989     const std::string multiHtml =
1990         "<html>"
1991         "<head>"
1992         "</head>"
1993         "<body>"
1994         "<p style=\"font-size:50px;text-decoration:underline;\">"
1995         "这段文本带有下划线效果,用于测试下划线装饰功能。"
1996         "<span style=\"text-decoration:line-through;\"> 这一部分有删除线效果。</span>"
1997         "</p>"
1998         "</body>"
1999         "</html>";
2000 
2001     /**
2002      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
2003      *             The result should match the original input HTML.
2004      * @tc.expected: The generated SpanString should match the original input HTML.
2005      */
2006     HtmlToSpan toSpan;
2007     auto dstSpan = toSpan.ToSpanString(multiHtml);
2008     EXPECT_EQ(dstSpan->GetSpanItems().size(), 2);
2009     SpanToHtml convert;
2010 
2011     auto dstHtml = convert.ToHtml(*dstSpan);
2012     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
2013     HtmlToSpan toSpan1;
2014     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
2015     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
2016     auto secondHtml = convert.ToHtml(*dstSpan1);
2017     EXPECT_EQ(secondHtml, dstHtml);
2018 }
2019 
2020 /**
2021  * @tc.name: HtmlConvertExam007
2022  * @tc.desc: This test case checks the conversion of a SpanString with font size and background color.
2023  *           It ensures the HTML correctly applies the background color and font size.
2024  * @tc.level: 1
2025  */
2026 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam007, TestSize.Level1)
2027 {
2028     /**
2029      * @tc.steps1: Create a SpanString with the text "这段文本有黄色背景,字体大小为50px,用于测试背景颜色转换。"
2030      *             and apply paragraph styles with font-size (50px) and background-color (yellow).
2031      * @tc.expected: The generated HTML should include the font size and background color styles.
2032      */
2033     const std::string multiHtml =
2034         "<html>"
2035         "<head>"
2036         "</head>"
2037         "<body>"
2038         "<p style=\"font-size:50px;background-color:yellow;\">"
2039         "这段文本有黄色背景,字体大小为50px,用于测试背景颜色转换。"
2040         "</p>"
2041         "</body>"
2042         "</html>";
2043 
2044     /**
2045      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
2046      *             The result should match the original input HTML.
2047      * @tc.expected: The generated SpanString should match the original input HTML.
2048      */
2049     HtmlToSpan toSpan;
2050     auto dstSpan = toSpan.ToSpanString(multiHtml);
2051     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
2052     SpanToHtml convert;
2053 
2054     auto dstHtml = convert.ToHtml(*dstSpan);
2055     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
2056     HtmlToSpan toSpan1;
2057     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
2058     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
2059     auto secondHtml = convert.ToHtml(*dstSpan1);
2060     EXPECT_EQ(secondHtml, dstHtml);
2061 }
2062 
2063 /**
2064  * @tc.name: HtmlConvertExam008
2065  * @tc.desc: This test case checks the conversion of a SpanString with different font sizes and letter spacing.
2066  *           It ensures the HTML correctly reflects the application of font size and letter spacing.
2067  * @tc.level: 1
2068  */
2069 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam008, TestSize.Level1)
2070 {
2071     /**
2072      * @tc.steps1: Create a SpanString with the text "这段文字有5px的字母间距,字体大小为50px。"
2073      *             and apply paragraph styles with font-size (50px) and letter-spacing (5px).
2074      *             Add a span with font-size (30px) and letter-spacing (2px).
2075      * @tc.expected: The generated HTML should include correct font sizes and letter spacing.
2076      */
2077     const std::string multiHtml =
2078         "<html>"
2079         "<head>"
2080         "</head>"
2081         "<body>"
2082         "<p style=\"font-size:50px;letter-spacing:5px;\">"
2083         "这段文字有5px的字母间距,字体大小为50px。<span style=\"font-size:30px;letter-spacing:2px;\">"
2084         "这一部分有2px字母间距和30px字体大小。</span>"
2085         "</p>"
2086         "</body>"
2087         "</html>";
2088 
2089     /**
2090      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
2091      *             The result should match the original input HTML.
2092      * @tc.expected: The generated SpanString should match the original input HTML.
2093      */
2094     HtmlToSpan toSpan;
2095     auto dstSpan = toSpan.ToSpanString(multiHtml);
2096     EXPECT_EQ(dstSpan->GetSpanItems().size(), 2);
2097     SpanToHtml convert;
2098 
2099     auto dstHtml = convert.ToHtml(*dstSpan);
2100     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
2101     HtmlToSpan toSpan1;
2102     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
2103     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
2104     auto secondHtml = convert.ToHtml(*dstSpan1);
2105     EXPECT_EQ(secondHtml, dstHtml);
2106 }
2107 
2108 /**
2109  * @tc.name: HtmlConvertExam009
2110  * @tc.desc: This test case checks the conversion of a SpanString with text color and multiple shadows.
2111  *           It ensures the HTML correctly applies text color and shadow effects.
2112  * @tc.level: 1
2113  */
2114 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam009, TestSize.Level1)
2115 {
2116     /**
2117      * @tc.steps1: Create a SpanString with the text "这段文本具有红色文本颜色和两个阴影效果(蓝色和绿色)。"
2118      *             and apply the paragraph styles with text color (red) and multiple text shadows (blue and green).
2119      * @tc.expected: The generated HTML should include the correct text color and shadow effects.
2120      */
2121     const std::string multiHtml =
2122         "<html>"
2123         "<head>"
2124         "</head>"
2125         "<body>"
2126         "<p style=\"font-size:50px;color:red;text-shadow:0px 0px 5px blue, 2px 2px 3px green;\">"
2127         "这段文本具有红色文本颜色和两个阴影效果(蓝色和绿色)。"
2128         "</p>"
2129         "</body>"
2130         "</html>";
2131 
2132     /**
2133      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
2134      *             The result should match the original input HTML.
2135      * @tc.expected: The generated HTML should match the original input HTML.
2136      */
2137     HtmlToSpan toSpan;
2138     auto dstSpan = toSpan.ToSpanString(multiHtml);
2139     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
2140     SpanToHtml convert;
2141 
2142     auto dstHtml = convert.ToHtml(*dstSpan);
2143     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
2144     HtmlToSpan toSpan1;
2145     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
2146     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
2147     auto secondHtml = convert.ToHtml(*dstSpan1);
2148     EXPECT_EQ(secondHtml, dstHtml);
2149 }
2150 
2151 /**
2152  * @tc.name: HtmlConvertExam010
2153  * @tc.desc: This test case checks the conversion of a SpanString with font size, text color,
2154  *           text decoration, and text shadow. It ensures all styles are correctly applied in the generated SpanString.
2155  * @tc.level: 1
2156  */
2157 HWTEST_F(HtmlConvertTestNg, HtmlConvertExam010, TestSize.Level1)
2158 {
2159     /**
2160      * @tc.steps1: Create a SpanString with the text and apply the paragraph styles with font-size (50px),
2161                    color (red), text-decoration (underline), and text-shadow (blue).
2162      * @tc.expected: The generated HTML should include all styles: font size, color, text decoration, and shadow.
2163      */
2164     const std::string multiHtml =
2165         "<html>"
2166         "<head>"
2167         "</head>"
2168         "<body>"
2169         "<p style=\"font-size:50px;color:red;text-decoration:underline;text-shadow:0px 0px 5px blue;\">"
2170         "这段文本为红色,有下划线,并且有一个蓝色阴影效果,字体大小为50px。"
2171         "</p>"
2172         "</body>"
2173         "</html>";
2174 
2175     /**
2176      * @tc.steps2: Convert the HTML string to SpanString and then back to HTML.
2177      *             The result should match the original input HTML.
2178      * @tc.expected: The generated HTML should match the original input HTML.
2179      */
2180     HtmlToSpan toSpan;
2181     auto dstSpan = toSpan.ToSpanString(multiHtml);
2182     EXPECT_EQ(dstSpan->GetSpanItems().size(), 1);
2183     SpanToHtml convert;
2184 
2185     auto dstHtml = convert.ToHtml(*dstSpan);
2186     EXPECT_GT(dstHtml.size(), 0);  // dstHtml is converted
2187     HtmlToSpan toSpan1;
2188     auto dstSpan1 = toSpan1.ToSpanString(dstHtml);
2189     EXPECT_EQ(IsSpanItemSame(dstSpan->GetSpanItems(), dstSpan1->GetSpanItems()), true);
2190     auto secondHtml = convert.ToHtml(*dstSpan1);
2191     EXPECT_EQ(secondHtml, dstHtml);
2192 }
2193 
2194 /**
2195  * @tc.name: MultiHtmlConvert
2196  * @tc.desc: This test case checks the conversion of HTML with different text-decoration styles
2197  *           (underline, strike-through, overline).
2198  * @tc.level: 1
2199  */
2200 HWTEST_F(HtmlConvertTestNg, MultiHtmlConvert, TestSize.Level1)
2201 {
2202     /**
2203      * @tc.steps1: Test conversion with `text-decoration` values: `underline`, `line-through`, and `overline`.
2204      * @tc.expected: Each text-decoration style should be correctly applied to the resulting `SpanString`.
2205      */
2206     const std::string multiHtml = "<html>"
2207                                   "<body>"
2208                                   "<p style=\"text-decoration:underline;\">Underlined Text</p>"
2209                                   "<p style=\"text-decoration:line-through;\">Strikethrough Text</p>"
2210                                   "<p style=\"text-decoration:overline;\">Overlined Text</p>"
2211                                   "</body>"
2212                                   "</html>";
2213     HtmlToSpan toSpan;
2214     auto dstSpan = toSpan.ToSpanString(multiHtml);
2215 
2216     /**
2217      * @tc.steps2: Verify the size of the converted `SpanString`.
2218      *             It should have 3 span items for the 3 different text-decoration styles.
2219      * @tc.expected: The size of the spans list should be 3.
2220      */
2221     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
2222     EXPECT_EQ(spans.size(), 3);
2223 
2224     /**
2225      * @tc.steps3: Verify that the first span item has the `underline` text-decoration.
2226      * @tc.expected: The first span item should have the `underline` text-decoration.
2227      */
2228     auto it = spans.begin();
2229     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::UNDERLINE);
2230 
2231     /**
2232      * @tc.steps4: Verify that the second span item has the `line-through` text-decoration.
2233      * @tc.expected: The second span item should have the `line-through` text-decoration.
2234      */
2235     ++it;
2236     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::LINE_THROUGH);
2237 
2238     /**
2239      * @tc.steps5: Verify that the third span item has the `overline` text-decoration.
2240      * @tc.expected: The third span item should have the `overline` text-decoration.
2241      */
2242     ++it;
2243     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::OVERLINE);
2244 }
2245 /**
2246  * @tc.name: HtmlConvertTestSubscriptText
2247  * @tc.desc: Test the conversion of subscript text (<sub>labels)
2248  * @tc.level: 1
2249  */
2250 HWTEST_F(HtmlConvertTestNg, HtmlConvertTestSubscriptText, TestSize.Level1)
2251 {
2252     const std::string html = "<html><body><p>This is <sub>sub</sub> text</p></body></html>";
2253     HtmlToSpan toSpan;
2254     auto dstSpan = toSpan.ToSpanString(html);
2255     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
2256     EXPECT_EQ(spans.size(), 3);
2257     auto it = spans.begin();
2258     ++it;
2259     EXPECT_TRUE((*it)->fontStyle->GetSuperscript().has_value());
2260     EXPECT_EQ((*it)->fontStyle->GetSuperscript().value(), OHOS::Ace::SuperscriptStyle::SUBSCRIPT);
2261 }
2262 
2263 /**
2264  * @tc.name: HtmlConvertTestSuperscriptText
2265  * @tc.desc: Test the conversion of superscript text (<sup>labels)
2266  * @tc.level: 1
2267  */
2268 HWTEST_F(HtmlConvertTestNg, HtmlConvertTestSuperscriptText, TestSize.Level1)
2269 {
2270     const std::string html = "<html><body><p>This is <sup>sup</sup> text</p></body></html>";
2271     HtmlToSpan toSpan;
2272     auto dstSpan = toSpan.ToSpanString(html);
2273     std::list<RefPtr<NG::SpanItem>> spans = dstSpan->GetSpanItems();
2274     EXPECT_EQ(spans.size(), 3);
2275     auto it = spans.begin();
2276     ++it;
2277     EXPECT_TRUE((*it)->fontStyle->GetSuperscript().has_value());
2278     EXPECT_EQ((*it)->fontStyle->GetSuperscript().value(), OHOS::Ace::SuperscriptStyle::SUPERSCRIPT);
2279 }
2280 
2281 /**
2282  * @tc.name: HtmlTagsConversionTest
2283  * @tc.desc: Verify the conversion of HTML tags <a>, <b>, <i>, <u>, <del>, <br>, <strong>, <s>, and <em> to SpanItems.
2284  * @tc.level: 1
2285  */
2286 HWTEST_F(HtmlConvertTestNg, HtmlTagsConversionTest, TestSize.Level1)
2287 {
2288     /**
2289      * @tc.steps1: Create an HTML string with various tags and convert it to SpanString.
2290      * @tc.expected: The tags should be correctly converted to SpanItems with appropriate styles.
2291      */
2292     const std::string html = "<html>"
2293                              "<body>"
2294                              "<a href=\"https://example.com\">Link</a>"
2295                              "<b>Bold Text</b>"
2296                              "<i>Italic Text</i>"
2297                              "<u>Underlined Text</u>"
2298                              "<del>Deleted Text</del>"
2299                              "<br>"
2300                              "<strong>Strong Text</strong>"
2301                              "<s>Strikethrough Text</s>"
2302                              "<em>Emphasized Text</em>"
2303                              "</body>"
2304                              "</html>";
2305 
2306     HtmlToSpan toSpan;
2307     auto dstSpan = toSpan.ToSpanString(html);
2308     EXPECT_NE(dstSpan, nullptr);
2309 
2310     std::list<RefPtr<NG::SpanItem>> items = dstSpan->GetSpanItems();
2311     EXPECT_EQ(items.size(), 9);
2312 
2313     auto it = items.begin();
2314 
2315     // Verify <b> tag
2316     ++it;
2317     EXPECT_TRUE((*it)->fontStyle->GetFontWeight().has_value());
2318     EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), FontWeight::BOLD);
2319 
2320     // Verify <i> tag
2321     ++it;
2322     EXPECT_EQ((*it)->fontStyle->GetItalicFontStyle().value(), Ace::FontStyle::ITALIC);
2323 
2324     // Verify <u> tag
2325     ++it;
2326     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::UNDERLINE);
2327 
2328     // Verify <del> tag
2329     ++it;
2330     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::LINE_THROUGH);
2331 
2332     // Verify <br> tag (no specific style to check)
2333     ++it;
2334 
2335     // Verify <strong> tag
2336     ++it;
2337     EXPECT_TRUE((*it)->fontStyle->GetFontWeight().has_value());
2338     EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), FontWeight::BOLD);
2339 
2340     // Verify <s> tag
2341     ++it;
2342     EXPECT_EQ((*it)->fontStyle->GetTextDecorationFirst(), TextDecoration::LINE_THROUGH);
2343 
2344     // Verify <em> tag
2345     ++it;
2346     EXPECT_EQ((*it)->fontStyle->GetItalicFontStyle().value(), Ace::FontStyle::ITALIC);
2347 }
2348 
2349 } // namespace OHOS::Ace::NG