1 /*
2 * Copyright (c) 2024 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/mock/core/common/mock_theme_manager.h"
17 #include "test/mock/core/pipeline/mock_pipeline_context.h"
18
19 #include "core/components_ng/pattern/text/text_pattern.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS::Ace::NG {
24 namespace {
25 const uint32_t GESTURE_INDEX1 = 1;
ConstructGestureStyle(GestureStyle & gestureInfo)26 void ConstructGestureStyle(GestureStyle& gestureInfo)
27 {
28 auto onClick = [](const BaseEventInfo* info) {};
29 auto tmpClickFunc = [func = std::move(onClick)](GestureEvent& info) { func(&info); };
30 gestureInfo.onClick = std::move(tmpClickFunc);
31
32 auto onLongPress = [](const BaseEventInfo* info) {};
33 auto tmpLongPressFunc = [func = std::move(onLongPress)](GestureEvent& info) { func(&info); };
34 gestureInfo.onLongPress = std::move(tmpLongPressFunc);
35 }
36 const double NUMBER_TEN = 10.0;
37 const double NUMBER_FIVE = 10.0;
38 } // namespace
39
40 class SpanStringTestNg : public testing::Test {
41 public:
42 static void SetUpTestSuite();
43 static void TearDownTestSuite();
44 static ImageSpanOptions GetImageOption(const std::string& src);
45 static ImageSpanOptions GetColorFilterImageOption(const std::string& src);
46 };
47
SetUpTestSuite()48 void SpanStringTestNg::SetUpTestSuite()
49 {
50 MockPipelineContext::SetUp();
51 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
52 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
53 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<TextTheme>()));
54 RefPtr<FrameNode> stageNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
55 auto stageManager = AceType::MakeRefPtr<StageManager>(stageNode);
56 MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
57 }
58
TearDownTestSuite()59 void SpanStringTestNg::TearDownTestSuite()
60 {
61 MockPipelineContext::TearDown();
62 }
63
GetImageOption(const std::string & src)64 ImageSpanOptions SpanStringTestNg::GetImageOption(const std::string& src)
65 {
66 ImageSpanSize size { .width = 50.0_vp, .height = 50.0_vp };
67 BorderRadiusProperty borderRadius;
68 borderRadius.SetRadius(2.0_vp);
69 MarginProperty margins;
70 margins.SetEdges(CalcLength(NUMBER_TEN));
71 PaddingProperty paddings;
72 paddings.SetEdges(CalcLength(NUMBER_FIVE));
73 ImageSpanAttribute attr { .paddingProp = paddings,
74 .marginProp = margins,
75 .borderRadius = borderRadius,
76 .objectFit = ImageFit::COVER,
77 .verticalAlign = VerticalAlign::BOTTOM };
78 ImageSpanOptions option { .image = src, .imageAttribute = attr };
79 return option;
80 }
81
GetColorFilterImageOption(const std::string & src)82 ImageSpanOptions SpanStringTestNg::GetColorFilterImageOption(const std::string& src)
83 {
84 ImageSpanSize size { .width = 50.0_vp, .height = 50.0_vp };
85 BorderRadiusProperty borderRadius;
86 borderRadius.SetRadius(2.0_vp);
87 MarginProperty margins;
88 margins.SetEdges(CalcLength(NUMBER_TEN));
89 PaddingProperty paddings;
90 paddings.SetEdges(CalcLength(NUMBER_FIVE));
91 std::vector<float> colorFilterMat {1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0};
92 ImageSpanAttribute attr { .paddingProp = paddings,
93 .marginProp = margins,
94 .borderRadius = borderRadius,
95 .objectFit = ImageFit::COVER,
96 .verticalAlign = VerticalAlign::BOTTOM,
97 .colorFilterMatrix = colorFilterMat };
98 ImageSpanOptions option { .image = src, .imageAttribute = attr };
99 return option;
100 }
101
102 class TestNode : public UINode {
103 DECLARE_ACE_TYPE(TestNode, UINode);
104
105 public:
CreateTestNode(int32_t nodeId)106 static RefPtr<TestNode> CreateTestNode(int32_t nodeId)
107 {
108 auto spanNode = MakeRefPtr<TestNode>(nodeId);
109 return spanNode;
110 };
111
IsAtomicNode() const112 bool IsAtomicNode() const override
113 {
114 return true;
115 }
116
TestNode(int32_t nodeId)117 explicit TestNode(int32_t nodeId) : UINode("TestNode", nodeId) {}
118 ~TestNode() override = default;
119 };
120 std::string test_str[] = { "hello", "world", "this", "find", "gank", "pink", "that", "when", "how", "cpp" };
121 Font testFont1 { OHOS::Ace::FontWeight::BOLD, Dimension(29.0, DimensionUnit::PX), OHOS::Ace::FontStyle::ITALIC,
122 std::vector<std::string>(test_str, test_str + 10), OHOS::Ace::Color::RED };
123 Font testFont2 { OHOS::Ace::FontWeight::LIGHTER, Dimension(19.0, DimensionUnit::PX), OHOS::Ace::FontStyle::ITALIC,
124 std::vector<std::string>(test_str, test_str + 10), OHOS::Ace::Color::WHITE };
125 Font testEmptyFont {};
126 /**
127 * @tc.name: SpanStringTest001
128 * @tc.desc: Test basic function of GetString/GetLength/GetIndex
129 * @tc.type: FUNC
130 */
131 HWTEST_F(SpanStringTestNg, SpanString001, TestSize.Level1)
132 {
133 auto spanString = AceType::MakeRefPtr<SpanString>(u"0123456789");
134 EXPECT_EQ(spanString->GetString(), "0123456789");
135 EXPECT_EQ(spanString->GetLength(), 10);
136
137 auto spanString1 = AceType::MakeRefPtr<SpanString>(u"中0123456789");
138 EXPECT_EQ(spanString1->GetString(), "中0123456789");
139 EXPECT_EQ(spanString1->GetLength(), 11);
140
141 auto spanString2 = AceType::MakeRefPtr<SpanString>(u"0123456");
142 EXPECT_EQ(spanString2->GetString(), "0123456");
143 EXPECT_EQ(spanString2->GetLength(), 7);
144
145 auto spanString3 = AceType::MakeRefPtr<SpanString>(u"你好");
146 EXPECT_EQ(spanString3->GetString(), "你好");
147 EXPECT_EQ(spanString3->GetLength(), 2);
148 }
149 /**
150 * @tc.name: SpanStringTest002
151 * @tc.desc: Test basic function of IsEqualToSpanString/GetSubSpanString
152 * @tc.type: FUNC
153 */
154 HWTEST_F(SpanStringTestNg, SpanString002, TestSize.Level1)
155 {
156 auto spanString1 = AceType::MakeRefPtr<SpanString>(u"01234中56789");
157 auto spanString2 = AceType::MakeRefPtr<SpanString>(u"01234中56789");
158 auto spanString3 = AceType::MakeRefPtr<SpanString>(u"01234567891");
159 EXPECT_TRUE(spanString1->IsEqualToSpanString(spanString2));
160 EXPECT_FALSE(spanString1->IsEqualToSpanString(spanString3));
161 std::vector<RefPtr<SpanBase>> spans;
162 spans.push_back(AceType::MakeRefPtr<FontSpan>(testFont2, 0, 3));
163 spans.push_back(AceType::MakeRefPtr<FontSpan>(testEmptyFont, 5, 8));
164 auto spanStringWithSpans1 = AceType::MakeRefPtr<SpanString>(u"01234567891");
165 spanStringWithSpans1->BindWithSpans(spans);
166 auto spanStringWithSpans2 = AceType::MakeRefPtr<SpanString>(u"01234567891");
167 spanStringWithSpans2->BindWithSpans(spans);
168 EXPECT_TRUE(spanStringWithSpans1->IsEqualToSpanString(spanStringWithSpans2));
169 std::vector<RefPtr<SpanBase>> spans1;
170 spans1.push_back(AceType::MakeRefPtr<FontSpan>(testFont2, 0, 3));
171 spans1.push_back(AceType::MakeRefPtr<FontSpan>(testEmptyFont, 5, 7));
172 auto spanStringWithSpans3 = AceType::MakeRefPtr<SpanString>(u"01234567891");
173 spanStringWithSpans3->BindWithSpans(spans1);
174 EXPECT_FALSE(spanStringWithSpans3->IsEqualToSpanString(spanStringWithSpans2));
175 auto subSpanStringWithSpans2 = spanStringWithSpans2->GetSubSpanString(0, 7);
176 auto subSpanStringWithSpans3 = spanStringWithSpans3->GetSubSpanString(0, 7);
177 auto map2 = subSpanStringWithSpans2->GetSpansMap();
178 EXPECT_TRUE(subSpanStringWithSpans2->IsEqualToSpanString(subSpanStringWithSpans3));
179 auto emptySpanString = spanStringWithSpans2->GetSubSpanString(1, 0);
180 EXPECT_TRUE(emptySpanString->IsEqualToSpanString(AceType::MakeRefPtr<SpanString>(u"")));
181 }
182
183 /**
184 * @tc.name: SpanStringTest003
185 * @tc.desc: Test basic function of GetSpans/GetFontColor/GetFontSize/GetFontWeight/GetFontFamily/GetFontStyle
186 * @tc.type: FUNC
187 */
188 HWTEST_F(SpanStringTestNg, SpanString003, TestSize.Level1)
189 {
190 auto spanString3 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
191 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 3));
192 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 3, 5));
193 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testEmptyFont, 5, 8));
194 auto firstSpans = spanString3->GetSpans(5, 2);
195 EXPECT_EQ(firstSpans.size(), 1);
196 auto firstFontSpan = AceType::DynamicCast<FontSpan>(firstSpans[0]);
197 EXPECT_NE(firstFontSpan, nullptr);
198 EXPECT_EQ(firstFontSpan->GetStartIndex(), 5);
199 EXPECT_EQ(firstFontSpan->GetEndIndex(), 7);
200 EXPECT_EQ(firstFontSpan->GetFont().GetFontColor(), "");
201
202 auto secondString3 = spanString3->GetSpans(0, 3);
203 EXPECT_EQ(secondString3.size(), 1);
204 auto secondFontSpan = AceType::DynamicCast<FontSpan>(secondString3[0]);
205 EXPECT_NE(secondFontSpan, nullptr);
206 EXPECT_EQ(secondFontSpan->GetStartIndex(), 0);
207 EXPECT_EQ(secondFontSpan->GetEndIndex(), 3);
208 EXPECT_EQ(secondFontSpan->GetFont().GetFontColor(), OHOS::Ace::Color::RED.ColorToString());
209
210 auto thirdString3 = spanString3->GetSpans(3, 1);
211 EXPECT_EQ(thirdString3.size(), 1);
212 auto thirdFontSpan = AceType::DynamicCast<FontSpan>(thirdString3[0]);
213 EXPECT_NE(thirdFontSpan, nullptr);
214 EXPECT_EQ(thirdFontSpan->GetStartIndex(), 3);
215 EXPECT_EQ(thirdFontSpan->GetEndIndex(), 4);
216 EXPECT_EQ(thirdFontSpan->GetFont().GetFontColor(), OHOS::Ace::Color::WHITE.ColorToString());
217 }
218 /**
219 * @tc.name: SpanStringTest004
220 * @tc.desc: Test basic function of GetString/GetLength/GetIndex
221 * @tc.type: FUNC
222 */
223 HWTEST_F(SpanStringTestNg, SpanString004, TestSize.Level1)
224 {
225 auto spanString3 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
226 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testEmptyFont, 0, 3));
227 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 3, 5));
228 spanString3->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 5, 8));
229 auto spans = spanString3->GetSpans(1, 7);
230 EXPECT_EQ(spans.size(), 3);
231 auto firstFontSpan = AceType::DynamicCast<FontSpan>(spans[0]);
232 EXPECT_NE(firstFontSpan, nullptr);
233 EXPECT_EQ(firstFontSpan->GetStartIndex(), 1);
234 EXPECT_EQ(firstFontSpan->GetEndIndex(), 3);
235 EXPECT_EQ(firstFontSpan->GetFont().GetFontColor(), "");
236
237 auto secondFontSpan = AceType::DynamicCast<FontSpan>(spans[1]);
238 EXPECT_NE(secondFontSpan, nullptr);
239 EXPECT_EQ(secondFontSpan->GetStartIndex(), 3);
240 EXPECT_EQ(secondFontSpan->GetEndIndex(), 5);
241 EXPECT_EQ(secondFontSpan->GetFont().GetFontColor(), OHOS::Ace::Color::RED.ColorToString());
242
243 auto thirdFontSpan = AceType::DynamicCast<FontSpan>(spans[2]);
244 EXPECT_NE(thirdFontSpan, nullptr);
245 EXPECT_EQ(thirdFontSpan->GetStartIndex(), 5);
246 EXPECT_EQ(thirdFontSpan->GetEndIndex(), 8);
247 EXPECT_EQ(thirdFontSpan->GetFont().GetFontColor(), OHOS::Ace::Color::WHITE.ColorToString());
248 }
249
250 /**
251 * @tc.name: SpanStringTest005
252 * @tc.desc: Test basic function of DecorationSpan/BaselineOffsetSpan/LetterSpacingSpan/TextShadowSpan
253 * @tc.type: FUNC
254 */
255 HWTEST_F(SpanStringTestNg, SpanString005, TestSize.Level1)
256 {
257 auto spanString3 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
258 spanString3->AddSpan(
259 AceType::MakeRefPtr<DecorationSpan>(TextDecoration::OVERLINE, Color::RED, TextDecorationStyle::WAVY, 0, 1));
260 spanString3->AddSpan(AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(4), 0, 2));
261 spanString3->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 0, 3));
262 Shadow textShadow;
263 textShadow.SetBlurRadius(0.0);
264 textShadow.SetColor(Color::BLUE);
265 textShadow.SetOffsetX(5.0);
266 textShadow.SetOffsetY(5.0);
267 vector<Shadow> textShadows { textShadow };
268 spanString3->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(textShadows, 7, 9));
269
270 auto firstSpans = spanString3->GetSpans(2, 1);
271 EXPECT_EQ(firstSpans.size(), 1);
272 auto letterSpacingSpan = AceType::DynamicCast<LetterSpacingSpan>(firstSpans[0]);
273 EXPECT_NE(letterSpacingSpan, nullptr);
274 EXPECT_EQ(letterSpacingSpan->GetStartIndex(), 2);
275 EXPECT_EQ(letterSpacingSpan->GetEndIndex(), 3);
276 EXPECT_TRUE(letterSpacingSpan->GetLetterSpacing() == Dimension(5));
277
278 auto secondSpans = spanString3->GetSpans(1, 1);
279 EXPECT_EQ(secondSpans.size(), 2);
280
281 auto thirdSpans = spanString3->GetSpans(0, 1);
282 EXPECT_EQ(thirdSpans.size(), 3);
283
284 auto fourthSpans = spanString3->GetSpans(3, 1);
285 EXPECT_EQ(fourthSpans.size(), 0);
286
287 auto fifthSpans = spanString3->GetSpans(0, 9);
288 EXPECT_EQ(fifthSpans.size(), 4);
289 }
290
291 /**
292 * @tc.name: SpanStringTest006
293 * @tc.desc: Test basic function of DecorationSpan/BaselineOffsetSpan/LetterSpacingSpan/TextShadowSpan
294 * @tc.type: FUNC
295 */
296 HWTEST_F(SpanStringTestNg, SpanString006, TestSize.Level1)
297 {
298 auto spanString3 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
299 spanString3->AddSpan(
300 AceType::MakeRefPtr<DecorationSpan>(TextDecoration::OVERLINE, Color::RED, TextDecorationStyle::WAVY, 0, 1));
301 spanString3->AddSpan(AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(4), 0, 2));
302 spanString3->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 5, 8));
303 Shadow textShadow;
304 textShadow.SetBlurRadius(0.0);
305 textShadow.SetColor(Color::BLUE);
306 textShadow.SetOffsetX(5.0);
307 textShadow.SetOffsetY(5.0);
308 vector<Shadow> textShadows { textShadow };
309 spanString3->AddSpan(AceType::MakeRefPtr<TextShadowSpan>(textShadows, 8, 10));
310 auto subSpanString = spanString3->GetSubSpanString(0, 10);
311 EXPECT_TRUE(subSpanString->IsEqualToSpanString(spanString3));
312 auto firstSpans = spanString3->GetSpans(5, 1);
313 auto letterSpacingSpan = AceType::DynamicCast<LetterSpacingSpan>(firstSpans[0]);
314 EXPECT_NE(letterSpacingSpan, nullptr);
315 EXPECT_EQ(letterSpacingSpan->GetStartIndex(), 5);
316 EXPECT_EQ(letterSpacingSpan->GetEndIndex(), 6);
317 EXPECT_TRUE(letterSpacingSpan->GetLetterSpacing() == Dimension(5));
318
319 auto secondSpans = spanString3->GetSpans(1, 2);
320 EXPECT_EQ(secondSpans.size(), 1);
321 auto baselineOffsetSpan = AceType::DynamicCast<BaselineOffsetSpan>(secondSpans[0]);
322 EXPECT_NE(baselineOffsetSpan, nullptr);
323 EXPECT_EQ(baselineOffsetSpan->GetStartIndex(), 1);
324 EXPECT_EQ(baselineOffsetSpan->GetEndIndex(), 2);
325 EXPECT_TRUE(baselineOffsetSpan->GetBaselineOffset() == Dimension(4));
326
327 auto thirdSpans = spanString3->GetSpans(8, 1);
328 EXPECT_EQ(thirdSpans.size(), 1);
329 auto textShadowSpan = AceType::DynamicCast<TextShadowSpan>(thirdSpans[0]);
330 EXPECT_NE(textShadowSpan, nullptr);
331 EXPECT_EQ(textShadowSpan->GetStartIndex(), 8);
332 EXPECT_EQ(textShadowSpan->GetEndIndex(), 9);
333 EXPECT_TRUE(textShadowSpan->GetTextShadow()[0] == textShadow);
334 }
335
336 /**
337 * @tc.name: SpanStringTest007
338 * @tc.desc: Test basic function of CustomSpan
339 * @tc.type: FUNC
340 */
341 HWTEST_F(SpanStringTestNg, SpanString007, TestSize.Level1)
342 {
343 auto customSpan = AceType::MakeRefPtr<CustomSpan>();
344 auto spanString = AceType::MakeRefPtr<MutableSpanString>(customSpan);
345 auto spans = spanString->GetSpans(0, spanString->GetLength());
346 EXPECT_EQ(spans.size(), 1);
347 auto span = AceType::DynamicCast<CustomSpan>(spans[0]);
348 EXPECT_EQ(span->GetStartIndex(), 0);
349 EXPECT_EQ(span->GetEndIndex(), 1);
350 EXPECT_EQ(span->GetOnMeasure(), std::nullopt);
351 EXPECT_EQ(span->GetOnDraw(), std::nullopt);
352
353 spanString->AppendSpanString(spanString);
354 spans = spanString->GetSpans(0, spanString->GetLength());
355 EXPECT_EQ(spans.size(), 2);
356 auto span0 = AceType::DynamicCast<CustomSpan>(spans[0]);
357 EXPECT_EQ(span0->GetStartIndex(), 0);
358 EXPECT_EQ(span0->GetEndIndex(), 1);
359 EXPECT_EQ(span0->GetOnMeasure(), std::nullopt);
360 EXPECT_EQ(span0->GetOnDraw(), std::nullopt);
361 auto span1 = AceType::DynamicCast<CustomSpan>(spans[1]);
362 EXPECT_EQ(span1->GetStartIndex(), 1);
363 EXPECT_EQ(span1->GetEndIndex(), 2);
364 EXPECT_EQ(span1->GetOnMeasure(), std::nullopt);
365 EXPECT_EQ(span1->GetOnDraw(), std::nullopt);
366 EXPECT_FALSE(span0->IsAttributesEqual(span1));
367 spanString->RemoveSpans(0, spanString->GetLength());
368 EXPECT_EQ(spanString->GetLength(), 0);
369 }
370
371 /**
372 * @tc.name: SpanStringTest008
373 * @tc.desc: Test basic function of CustomSpan/Image
374 * @tc.type: FUNC
375 */
376 HWTEST_F(SpanStringTestNg, SpanString008, TestSize.Level1)
377 {
378 auto imageOption = SpanStringTestNg::GetImageOption("src/icon-1.png");
379 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
380 mutableStr->InsertString(0, u"123");
381 mutableStr->InsertString(4, u"456");
382 auto imageOption1 = SpanStringTestNg::GetImageOption("src/icon-2.png");
383 auto imageSpan1 = AceType::MakeRefPtr<SpanString>(imageOption1);
384 mutableStr->AppendSpanString(imageSpan1);
385 auto customSpan = AceType::MakeRefPtr<CustomSpan>();
386 auto spanString = AceType::MakeRefPtr<MutableSpanString>(customSpan);
387 spanString->AppendSpanString(mutableStr);
388 auto spans = spanString->GetSpans(0, spanString->GetLength());
389 EXPECT_EQ(spans.size(), 3);
390 spanString->AppendSpanString(spanString);
391 spans = spanString->GetSpans(0, spanString->GetLength());
392 EXPECT_EQ(spans.size(), 6);
393 }
394
395 /**
396 * @tc.name: SpanStringTest001
397 * @tc.desc: Test basic function of ReplaceString/InsertString/RemoveString
398 * @tc.type: FUNC
399 */
400 HWTEST_F(SpanStringTestNg, MutableSpanString001, TestSize.Level1)
401 {
402 auto a = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
403 EXPECT_EQ(a->GetString(), "0123456789");
404 a->ReplaceString(0, 1, u"abcd");
405 EXPECT_EQ(a->GetString(), "abcd123456789");
406 a->InsertString(0, u"abcd");
407 EXPECT_EQ(a->GetString(), "abcdabcd123456789");
408 a->RemoveString(3, 3);
409 EXPECT_EQ(a->GetString(), "abccd123456789");
410 a->InsertString(4, u"中文插入测试");
411 EXPECT_EQ(a->GetString(), "abcc中文插入测试d123456789");
412 a->RemoveString(4, 6);
413 EXPECT_EQ(a->GetString(), "abccd123456789");
414 a->ReplaceString(5, 9, u"中文替换测试");
415 EXPECT_EQ(a->GetString(), "abccd中文替换测试");
416 }
417
CompareSpanList(const std::list<RefPtr<SpanBase>> & a,const std::list<RefPtr<SpanBase>> & b)418 bool CompareSpanList(const std::list<RefPtr<SpanBase>>& a, const std::list<RefPtr<SpanBase>>& b)
419 {
420 if (a.size() != b.size()) {
421 std::cout << "size not match" << a.size() << " " << b.size() << std::endl;
422 return false;
423 }
424 auto ita = a.begin();
425 auto itb = b.begin();
426 while (ita != a.end()) {
427 if (!(*ita)->IsAttributesEqual(*itb)) {
428 std::cout << (*ita)->ToString() << " " << (*itb)->ToString() << std::endl;
429 return false;
430 }
431 ++ita;
432 ++itb;
433 }
434 return true;
435 }
436
437 /**
438 * @tc.name: SpanStringTest001
439 * @tc.desc: Test if span is right after addSpan/replaceSpan/removeSpan
440 * @tc.type: FUNC
441 */
442 HWTEST_F(SpanStringTestNg, MutableSpanString002, TestSize.Level1)
443 {
444 auto a = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
445
446 std::string test_str[] = { "hello", "world", "this", "find", "gank", "pink", "that", "when", "how", "cpp" };
447 a->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10));
448 EXPECT_EQ(a->GetString(), "0123456789");
449 std::list<RefPtr<SpanBase>> resultList1 = { AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10) };
450 auto aSpansMap = a->GetSpansMap();
451 EXPECT_TRUE(CompareSpanList(aSpansMap[SpanType::Font], resultList1));
452 std::list<RefPtr<SpanBase>> resultList2 = { AceType::MakeRefPtr<FontSpan>(testFont2, 0, 3),
453 AceType::MakeRefPtr<FontSpan>(testFont1, 3, 10) };
454 a->ReplaceSpan(0, 3, AceType::MakeRefPtr<FontSpan>(testFont2, 0, 10));
455 aSpansMap = a->GetSpansMap();
456 EXPECT_EQ(a->GetString(), "0123456789");
457 EXPECT_TRUE(CompareSpanList(aSpansMap[SpanType::Font], resultList2));
458 std::list<RefPtr<SpanBase>> resultList3 = { AceType::MakeRefPtr<FontSpan>(testFont1, 3, 10) };
459 a->RemoveSpan(0, 3, SpanType::Font);
460 aSpansMap = a->GetSpansMap();
461 EXPECT_EQ(a->GetString(), "0123456789");
462 EXPECT_TRUE(CompareSpanList(aSpansMap[SpanType::Font], resultList3));
463
464 // 用中文再测一次
465 auto b = MutableSpanString(u"零一二三四五六七八九");
466 b.AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10));
467 EXPECT_EQ(b.GetString(), "零一二三四五六七八九");
468 std::list<RefPtr<SpanBase>> resultList4 = { AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10) };
469 auto bSpansMap = b.GetSpansMap();
470 EXPECT_TRUE(CompareSpanList(bSpansMap[SpanType::Font], resultList4));
471 std::list<RefPtr<SpanBase>> resultList5 = { AceType::MakeRefPtr<FontSpan>(testFont2, 0, 3),
472 AceType::MakeRefPtr<FontSpan>(testFont1, 3, 10) };
473 b.ReplaceSpan(0, 3, AceType::MakeRefPtr<FontSpan>(testFont2, 0, 10));
474 bSpansMap = b.GetSpansMap();
475 EXPECT_EQ(b.GetString(), "零一二三四五六七八九");
476 EXPECT_TRUE(CompareSpanList(bSpansMap[SpanType::Font], resultList5));
477 std::list<RefPtr<SpanBase>> resultList6 = { AceType::MakeRefPtr<FontSpan>(testFont1, 3, 10) };
478 b.RemoveSpan(0, 3, SpanType::Font);
479 bSpansMap = b.GetSpansMap();
480 EXPECT_EQ(b.GetString(), "零一二三四五六七八九");
481 EXPECT_TRUE(CompareSpanList(bSpansMap[SpanType::Font], resultList6));
482 }
483
484 /**
485 * @tc.name: MutableSpanString003
486 * @tc.desc: Test if span is right after addSpan
487 * @tc.type: FUNC
488 */
489 HWTEST_F(SpanStringTestNg, MutableSpanString003, TestSize.Level1)
490 {
491 auto mutableSpan = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
492
493 Font fontOne { .fontColor = OHOS::Ace::Color::RED };
494 Font fontTwo { .fontColor = OHOS::Ace::Color::WHITE };
495 Font fontThree { .fontColor = OHOS::Ace::Color::BLACK };
496
497 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 10));
498 auto spansMap = mutableSpan->GetSpansMap();
499 auto spanItems = mutableSpan->GetSpanItems();
500 EXPECT_EQ(spansMap.size(), 1);
501 EXPECT_EQ(spanItems.size(), 1);
502
503 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontTwo, 3, 7));
504 spansMap = mutableSpan->GetSpansMap();
505 auto fontSpans = spansMap[SpanType::Font];
506 spanItems = mutableSpan->GetSpanItems();
507 EXPECT_EQ(fontSpans.size(), 3);
508 EXPECT_EQ(spanItems.size(), 3);
509 std::list<RefPtr<SpanBase>> resultList = { AceType::MakeRefPtr<FontSpan>(fontOne, 0, 3),
510 AceType::MakeRefPtr<FontSpan>(fontTwo, 3, 7), AceType::MakeRefPtr<FontSpan>(fontOne, 7, 10) };
511 EXPECT_EQ(CompareSpanList(fontSpans, resultList), true);
512
513 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontThree, 2, 5));
514 spansMap = mutableSpan->GetSpansMap();
515 fontSpans = spansMap[SpanType::Font];
516 spanItems = mutableSpan->GetSpanItems();
517 EXPECT_EQ(fontSpans.size(), 4);
518 EXPECT_EQ(spanItems.size(), 5);
519 resultList = { AceType::MakeRefPtr<FontSpan>(fontOne, 0, 2), AceType::MakeRefPtr<FontSpan>(fontThree, 2, 5),
520 AceType::MakeRefPtr<FontSpan>(fontTwo, 5, 7), AceType::MakeRefPtr<FontSpan>(fontOne, 7, 10) };
521 EXPECT_EQ(CompareSpanList(fontSpans, resultList), true);
522 }
523
524 /**
525 * @tc.name: MutableSpanString004
526 * @tc.desc: Test if span is right after removeSpan
527 * @tc.type: FUNC
528 */
529 HWTEST_F(SpanStringTestNg, MutableSpanString004, TestSize.Level1)
530 {
531 auto mutableSpan = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
532
533 Font fontOne { .fontColor = OHOS::Ace::Color::RED };
534 Font fontTwo { .fontColor = OHOS::Ace::Color::WHITE };
535 Font fontThree { .fontColor = OHOS::Ace::Color::BLACK };
536
537 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 10));
538 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontTwo, 3, 7));
539 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontThree, 2, 5));
540
541 mutableSpan->RemoveSpan(2, 3, SpanType::Font);
542 auto spansMap = mutableSpan->GetSpansMap();
543 auto fontSpans = spansMap[SpanType::Font];
544 EXPECT_EQ(fontSpans.size(), 3);
545 std::list<RefPtr<SpanBase>> resultList = { AceType::MakeRefPtr<FontSpan>(fontOne, 0, 2),
546 AceType::MakeRefPtr<FontSpan>(fontTwo, 5, 7), AceType::MakeRefPtr<FontSpan>(fontOne, 7, 10) };
547 EXPECT_EQ(CompareSpanList(fontSpans, resultList), true);
548
549 mutableSpan->RemoveSpan(2, 5, SpanType::Font);
550 spansMap = mutableSpan->GetSpansMap();
551 fontSpans = spansMap[SpanType::Font];
552 EXPECT_EQ(fontSpans.size(), 2);
553 resultList = { AceType::MakeRefPtr<FontSpan>(fontOne, 0, 2), AceType::MakeRefPtr<FontSpan>(fontOne, 7, 10) };
554 EXPECT_EQ(CompareSpanList(fontSpans, resultList), true);
555
556 mutableSpan->RemoveSpan(0, 10, SpanType::Font);
557 spansMap = mutableSpan->GetSpansMap();
558 fontSpans = spansMap[SpanType::Font];
559 EXPECT_EQ(fontSpans.size(), 0);
560 }
561
562 /**
563 * @tc.name: MutableSpanString005
564 * @tc.desc: Test for outliers
565 * @tc.type: FUNC
566 */
567 HWTEST_F(SpanStringTestNg, MutableSpanString005, TestSize.Level1)
568 {
569 auto mutableSpan = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
570
571 Font fontOne { .fontColor = OHOS::Ace::Color::RED };
572 Font fontTwo { .fontColor = OHOS::Ace::Color::WHITE };
573 Font fontThree { .fontColor = OHOS::Ace::Color::BLACK };
574
575 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, -1, 10));
576 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontTwo, 3, 100));
577 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontThree, -100, 100));
578
579 auto spansMap = mutableSpan->GetSpansMap();
580 EXPECT_EQ(spansMap.size(), 0);
581
582 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 10));
583 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontTwo, 3, 7));
584 mutableSpan->AddSpan(AceType::MakeRefPtr<FontSpan>(fontThree, 2, 5));
585 spansMap = mutableSpan->GetSpansMap();
586 auto fontSpans = spansMap[SpanType::Font];
587 EXPECT_EQ(fontSpans.size(), 4);
588 mutableSpan->RemoveSpan(-1, 10, SpanType::Font);
589 mutableSpan->RemoveSpan(3, 100, SpanType::Font);
590 mutableSpan->RemoveSpan(-100, 100, SpanType::Font);
591 spansMap = mutableSpan->GetSpansMap();
592 fontSpans = spansMap[SpanType::Font];
593 EXPECT_EQ(fontSpans.size(), 4);
594 }
595
596 /**
597 * @tc.name: MutableSpanString006
598 * @tc.desc: Test combination of IsEqualToSpanString/GetSubSpanString/GetSpans/GetSpan
599 * @tc.type: FUNC
600 */
601 HWTEST_F(SpanStringTestNg, MutableSpanString006, TestSize.Level1)
602 {
603 Font fontOne { .fontColor = OHOS::Ace::Color::RED };
604 Font fontTwo { .fontColor = OHOS::Ace::Color::WHITE };
605 auto spanString1 = AceType::MakeRefPtr<SpanString>(u"0123456789");
606 spanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 3));
607 auto mutableSpanString1 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
608 EXPECT_FALSE(spanString1->IsEqualToSpanString(mutableSpanString1));
609 mutableSpanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 3));
610 EXPECT_TRUE(spanString1->IsEqualToSpanString(mutableSpanString1));
611 mutableSpanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 3, 7));
612 auto mutableSpanString2 = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
613 mutableSpanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 0, 7));
614 EXPECT_TRUE(mutableSpanString2->IsEqualToSpanString(mutableSpanString1));
615 EXPECT_TRUE(spanString1->GetSubSpanString(0, 3)->IsEqualToSpanString(mutableSpanString2->GetSubSpanString(0, 3)));
616 mutableSpanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(fontTwo, 7, 8));
617 mutableSpanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(fontOne, 8, 9));
618 auto spanArr = mutableSpanString2->GetSpans(0, 9);
619 EXPECT_EQ(spanArr.size(), 3);
620 }
621
622 /**
623 * @tc.name: MutableSpanString007
624 * @tc.desc: Test some edge case of InsertString/ReplaceString/RemoveString
625 * @tc.type: FUNC
626 */
627 HWTEST_F(SpanStringTestNg, MutableSpanString007, TestSize.Level1)
628 {
629 vector<OHOS::Ace::Color> colors = { Color::RED, Color::BLACK, Color::GREEN, Color::GRAY, Color::BLUE };
630 vector<Font> fonts;
631 auto spanString1 = AceType::MakeRefPtr<MutableSpanString>(u"01234");
632 for (int i = 0; i < colors.size(); i++) {
633 Font f;
634 f.fontColor = colors[i];
635 fonts.emplace_back(f);
636 spanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(f, i, i + 1));
637 }
638 auto spanArr = spanString1->GetSpans(0, spanString1->GetLength());
639 EXPECT_EQ(spanArr.size(), colors.size());
640
641 auto spanString2 = spanString1->GetSubSpanString(0, spanString1->GetLength());
642 EXPECT_TRUE(spanString2->IsEqualToSpanString(spanString1));
643 std::list<RefPtr<SpanBase>> resultList1 = { AceType::MakeRefPtr<FontSpan>(fonts[0], 0, 6),
644 AceType::MakeRefPtr<FontSpan>(fonts[1], 6, 7), AceType::MakeRefPtr<FontSpan>(fonts[2], 7, 8),
645 AceType::MakeRefPtr<FontSpan>(fonts[3], 8, 9), AceType::MakeRefPtr<FontSpan>(fonts[4], 9, 10) };
646 spanString1->InsertString(0, u"一二三四五");
647 auto spanMap = spanString1->GetSpansMap();
648 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList1));
649 spanString1->InsertString(6, u"红红火火");
650 std::list<RefPtr<SpanBase>> resultList2 = { AceType::MakeRefPtr<FontSpan>(fonts[0], 0, 10),
651 AceType::MakeRefPtr<FontSpan>(fonts[1], 10, 11), AceType::MakeRefPtr<FontSpan>(fonts[2], 11, 12),
652 AceType::MakeRefPtr<FontSpan>(fonts[3], 12, 13), AceType::MakeRefPtr<FontSpan>(fonts[4], 13, 14) };
653 spanMap = spanString1->GetSpansMap();
654 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList2));
655 spanString1->InsertString(11, u"abcdefg");
656 spanString1->ReplaceString(8, 8, u"A");
657 std::list<RefPtr<SpanBase>> resultList3 = { AceType::MakeRefPtr<FontSpan>(fonts[0], 0, 9),
658 AceType::MakeRefPtr<FontSpan>(fonts[1], 9, 11), AceType::MakeRefPtr<FontSpan>(fonts[2], 11, 12),
659 AceType::MakeRefPtr<FontSpan>(fonts[3], 12, 13), AceType::MakeRefPtr<FontSpan>(fonts[4], 13, 14) };
660 spanMap = spanString1->GetSpansMap();
661 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList3));
662 EXPECT_EQ(spanString1->GetString(), "一二三四五0红红Afg234");
663 spanString1->RemoveString(1, 10);
664 std::list<RefPtr<SpanBase>> resultList4 = { AceType::MakeRefPtr<FontSpan>(fonts[0], 0, 1),
665 AceType::MakeRefPtr<FontSpan>(fonts[2], 1, 2), AceType::MakeRefPtr<FontSpan>(fonts[3], 2, 3),
666 AceType::MakeRefPtr<FontSpan>(fonts[4], 3, 4) };
667 spanMap = spanString1->GetSpansMap();
668 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList4));
669 }
670
671 /**
672 * @tc.name: MutableSpanString008
673 * @tc.desc: Test some edge case of InsertSpanString/ReplaceSpanString/AppendSpanString
674 * @tc.type: FUNC
675 */
676 HWTEST_F(SpanStringTestNg, MutableSpanString008, TestSize.Level1)
677 {
678 vector<OHOS::Ace::Color> colors = { Color::RED, Color::BLACK, Color::GREEN, Color::GRAY, Color::BLUE };
679 vector<Font> fonts;
680 auto spanString1 = AceType::MakeRefPtr<MutableSpanString>(u"0123");
681 for (int i = 0; i < 5; i++) {
682 Font f;
683 f.fontColor = colors[i];
684 fonts.emplace_back(f);
685 if (i != 4) {
686 spanString1->AddSpan(AceType::MakeRefPtr<FontSpan>(f, i, i + 1));
687 }
688 }
689 auto spanArr = spanString1->GetSpans(0, spanString1->GetLength());
690 auto spanString2 = AceType::MakeRefPtr<MutableSpanString>(u"abc");
691 Font f;
692 f.fontColor = colors[4];
693 spanString2->AddSpan(AceType::MakeRefPtr<FontSpan>(f, 0, 3));
694 spanString1->InsertSpanString(1, spanString2);
695 std::list<RefPtr<SpanBase>> resultList1 = { AceType::MakeRefPtr<FontSpan>(fonts[0], 0, 1),
696 AceType::MakeRefPtr<FontSpan>(fonts[4], 1, 4), AceType::MakeRefPtr<FontSpan>(fonts[1], 4, 5),
697 AceType::MakeRefPtr<FontSpan>(fonts[2], 5, 6), AceType::MakeRefPtr<FontSpan>(fonts[3], 6, 7) };
698 auto spanMap = spanString1->GetSpansMap();
699 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList1));
700
701 spanString1->InsertSpanString(0, spanString2);
702 std::list<RefPtr<SpanBase>> resultList2 = { AceType::MakeRefPtr<FontSpan>(fonts[4], 0, 3),
703 AceType::MakeRefPtr<FontSpan>(fonts[0], 3, 4), AceType::MakeRefPtr<FontSpan>(fonts[4], 4, 7),
704 AceType::MakeRefPtr<FontSpan>(fonts[1], 7, 8), AceType::MakeRefPtr<FontSpan>(fonts[2], 8, 9),
705 AceType::MakeRefPtr<FontSpan>(fonts[3], 9, 10) };
706 spanMap = spanString1->GetSpansMap();
707 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList2));
708
709 spanString1->ReplaceSpanString(0, 7, spanString2);
710 std::list<RefPtr<SpanBase>> resultList3 = { AceType::MakeRefPtr<FontSpan>(fonts[4], 0, 3),
711 AceType::MakeRefPtr<FontSpan>(fonts[1], 3, 4), AceType::MakeRefPtr<FontSpan>(fonts[2], 4, 5),
712 AceType::MakeRefPtr<FontSpan>(fonts[3], 5, 6) };
713 spanMap = spanString1->GetSpansMap();
714 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList3));
715
716 spanString1->AppendSpanString(spanString2);
717 std::list<RefPtr<SpanBase>> resultList4 = { AceType::MakeRefPtr<FontSpan>(fonts[4], 0, 3),
718 AceType::MakeRefPtr<FontSpan>(fonts[1], 3, 4), AceType::MakeRefPtr<FontSpan>(fonts[2], 4, 5),
719 AceType::MakeRefPtr<FontSpan>(fonts[3], 5, 6), AceType::MakeRefPtr<FontSpan>(fonts[4], 6, 9) };
720 spanMap = spanString1->GetSpansMap();
721 EXPECT_TRUE(CompareSpanList(spanMap[SpanType::Font], resultList4));
722 }
723
724 /**
725 * @tc.name: GestureSpanString001
726 * @tc.desc: Test the construction of the gesture type in spanString
727 * @tc.type: FUNC
728 */
729 HWTEST_F(SpanStringTestNg, GestureSpanString001, TestSize.Level1)
730 {
731 /**
732 * @tc.steps: step1. Create spanBases and gestureInfo
733 */
734 std::vector<RefPtr<SpanBase>> spanBases;
735 GestureStyle gestureInfo;
736 ConstructGestureStyle(gestureInfo);
737 spanBases.emplace_back(AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3));
738 auto spanStringWithSpans = AceType::MakeRefPtr<SpanString>(u"01234567891");
739 spanStringWithSpans->BindWithSpans(spanBases);
740
741 /**
742 * @tc.steps: step2. compare SpansMap and gestureInfo
743 * @tc.expect: The number of spanItems in the spanString is 2
744 */
745 auto spanMap = spanStringWithSpans->GetSpansMap();
746 std::list<RefPtr<SpanBase>> resultList = { AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3) };
747 EXPECT_FALSE(CompareSpanList(spanMap[SpanType::Gesture], resultList));
748 EXPECT_EQ(spanStringWithSpans->GetSpanItems().size(), 2);
749 }
750
751 /**
752 * @tc.name: GestureSpanString002
753 * @tc.desc: Test the manifestations of the gesture type in the textPattern after it is constructed in spanString
754 * @tc.type: FUNC
755 */
756 HWTEST_F(SpanStringTestNg, GestureSpanString002, TestSize.Level1)
757 {
758 /**
759 * @tc.steps: step1. Create spanBases and gestureInfo
760 */
761 std::vector<RefPtr<SpanBase>> spanBases;
762 GestureStyle gestureInfo;
763 ConstructGestureStyle(gestureInfo);
764 spanBases.emplace_back(AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3));
765 spanBases.emplace_back(AceType::MakeRefPtr<GestureSpan>(gestureInfo, 8, 11));
766 auto spanStringWithSpans = AceType::MakeRefPtr<SpanString>(u"01234567891");
767 spanStringWithSpans->BindWithSpans(spanBases);
768
769 std::list<RefPtr<SpanBase>> resultList = { AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3),
770 AceType::MakeRefPtr<GestureSpan>(gestureInfo, 8, 3) };
771 auto spanMap = spanStringWithSpans->GetSpansMap();
772
773 EXPECT_FALSE(CompareSpanList(spanMap[SpanType::Gesture], resultList));
774
775 /**
776 * @tc.steps: step2. Create textPattern and construct property string scene for textPattern
777 */
778 auto textPattern = AceType::MakeRefPtr<TextPattern>();
779 auto frameNode = FrameNode::CreateFrameNode("Test", 1, textPattern);
780 textPattern->SetTextController(AceType::MakeRefPtr<TextController>());
781 textPattern->GetTextController()->SetPattern(AceType::WeakClaim(AceType::RawPtr(textPattern)));
782 auto textController = textPattern->GetTextController();
783 textController->SetStyledString(spanStringWithSpans);
784
785 auto spans = spanStringWithSpans->GetSpanItems();
786 textPattern->SetSpanItemChildren(spans);
787 textPattern->SetSpanStringMode(true);
788
789 /**
790 * @tc.steps: step2. Call the BeforeCreateLayoutWrapper function
791 * @tc.expect: The click and long press event of the textPattern is initialized
792 * and the number of spanItems in the spanString is 2
793 */
794 textPattern->BeforeCreateLayoutWrapper();
795 EXPECT_EQ(textPattern->GetSpanItemChildren().size(), 3);
796 EXPECT_TRUE(textPattern->clickEventInitialized_);
797 EXPECT_NE(textPattern->longPressEvent_, nullptr);
798 }
799
800 /**
801 * @tc.name: GestureSpanString003
802 * @tc.desc: Test some edge case of AddSpan
803 * @tc.type: FUNC
804 */
805 HWTEST_F(SpanStringTestNg, GestureSpanString03, TestSize.Level1)
806 {
807 /**
808 * @tc.steps: step1. Create spanString and textPattern
809 */
810 auto spanStringWithSpans = AceType::MakeRefPtr<SpanString>(u"01234567891");
811 auto textPattern = AceType::MakeRefPtr<TextPattern>();
812 auto frameNode = FrameNode::CreateFrameNode("Test", 1, textPattern);
813
814 /**
815 * @tc.steps: step2. Call the AddSpan function
816 * @tc.expect: The number of spanBases for gesture types is 1
817 */
818 GestureStyle gestureInfo;
819 ConstructGestureStyle(gestureInfo);
820 auto spanBase = AceType::MakeRefPtr<GestureSpan>(gestureInfo, 8, 10);
821 spanStringWithSpans->AddSpan(spanBase);
822 auto spanMap = spanStringWithSpans->GetSpansMap();
823 EXPECT_EQ(spanMap[SpanType::Gesture].size(), 1);
824
825 /**
826 * @tc.steps: step3. Call the BeforeCreateLayoutWrapper function of textPattern
827 * @tc.expect: The number of spans for text is 3 and second span has event
828 */
829 textPattern->SetTextController(AceType::MakeRefPtr<TextController>());
830 textPattern->GetTextController()->SetPattern(AceType::WeakClaim(AceType::RawPtr(textPattern)));
831 auto textController = textPattern->GetTextController();
832 textController->SetStyledString(spanStringWithSpans);
833 textPattern->SetSpanStringMode(true);
834 textPattern->BeforeCreateLayoutWrapper();
835
836 auto spanItems = textPattern->GetSpanItemChildren();
837 EXPECT_EQ(spanItems.size(), 3);
838 EXPECT_TRUE(textPattern->clickEventInitialized_);
839 EXPECT_NE(textPattern->longPressEvent_, nullptr);
840 auto iter = spanItems.begin();
841 std::advance(iter, GESTURE_INDEX1);
842 EXPECT_NE((*iter)->onClick, nullptr);
843 EXPECT_NE((*iter)->onLongPress, nullptr);
844 }
845
846 /**
847 * @tc.name: GestureSpanString004
848 * @tc.desc: Test some edge case of ReplaceString/RemoveString
849 * @tc.type: FUNC
850 */
851 HWTEST_F(SpanStringTestNg, GestureSpanString004, TestSize.Level1)
852 {
853 /**
854 * @tc.steps: step1. Create MutableSpanString and textPattern
855 */
856 GestureStyle gestureInfo;
857 ConstructGestureStyle(gestureInfo);
858 std::vector<RefPtr<SpanBase>> spanBases;
859 spanBases.emplace_back(AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3));
860 spanBases.emplace_back(AceType::MakeRefPtr<GestureSpan>(gestureInfo, 8, 11));
861 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"01234567891");
862 spanString->BindWithSpans(spanBases);
863 auto textPattern = AceType::MakeRefPtr<TextPattern>();
864 auto frameNode = FrameNode::CreateFrameNode("Test", 1, textPattern);
865 textPattern->SetTextController(AceType::MakeRefPtr<TextController>());
866 textPattern->GetTextController()->SetPattern(AceType::WeakClaim(AceType::RawPtr(textPattern)));
867 auto textController = textPattern->GetTextController();
868 textController->SetStyledString(spanString);
869
870 auto spans = spanString->GetSpanItems();
871 textPattern->SetSpanItemChildren(spans);
872
873 auto spanItems = textPattern->GetSpanItemChildren();
874 EXPECT_EQ(spanItems.size(), 3);
875 EXPECT_NE(spanItems.front()->onClick, nullptr);
876 EXPECT_NE(spanItems.front()->onLongPress, nullptr);
877
878 /**
879 * @tc.steps: step2. Call the ReplaceString function
880 * @tc.expect: The number of spanItems for textPattern is 4 and the events for each span were as expected
881 */
882 spanString->ReplaceString(0, 2, u"a");
883 spanItems = textPattern->GetSpanItemChildren();
884 EXPECT_EQ(spanItems.size(), 3);
885
886 auto iter = spanItems.begin();
887 EXPECT_NE((*iter)->onClick, nullptr);
888 EXPECT_NE((*iter)->onLongPress, nullptr);
889 iter++;
890 EXPECT_EQ((*iter)->onClick, nullptr);
891 EXPECT_EQ((*iter)->onLongPress, nullptr);
892 iter++;
893 EXPECT_NE((*iter)->onClick, nullptr);
894 EXPECT_NE((*iter)->onLongPress, nullptr);
895
896 /**
897 * @tc.steps: step3. Call the RemoveString function
898 * @tc.expect: The number of spanItems for textPattern is 3
899 */
900 spanString->RemoveString(7, 3);
901 textController->SetStyledString(spanString);
902 spanItems = textPattern->GetSpanItemChildren();
903 EXPECT_EQ(spanItems.size(), 2);
904 iter = spanItems.begin();
905 EXPECT_NE((*iter)->onClick, nullptr);
906 EXPECT_NE((*iter)->onLongPress, nullptr);
907 iter++;
908 EXPECT_EQ((*iter)->onClick, nullptr);
909 EXPECT_EQ((*iter)->onLongPress, nullptr);
910 }
911
912 /**
913 * @tc.name: MutableSpanString009
914 * @tc.desc: Test imageSpan
915 * @tc.type: FUNC
916 */
917 HWTEST_F(SpanStringTestNg, MutableSpanString009, TestSize.Level1)
918 {
919 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
920 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
921
922 auto spans = mutableStr->GetSpans(0, 2);
923 EXPECT_TRUE(spans.size() == 0);
924
925 spans = mutableStr->GetSpans(-1, 1);
926 EXPECT_TRUE(spans.size() == 0);
927
928 spans = mutableStr->GetSpans(0, 1);
929 EXPECT_TRUE(spans.size() == 1);
930 auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption);
931 EXPECT_TRUE(spans[0]->IsAttributesEqual(imageSpan));
932 }
933
934 /**
935 * @tc.name: MutableSpanString010
936 * @tc.desc: Test the insertString in the case of imageSpan
937 * @tc.type: FUNC
938 */
939 HWTEST_F(SpanStringTestNg, MutableSpanString010, TestSize.Level1)
940 {
941 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
942 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
943
944 mutableStr->InsertString(0, u"123");
945 auto text = mutableStr->GetString();
946 EXPECT_TRUE(text == "123 ");
947 auto length = mutableStr->GetLength();
948 EXPECT_TRUE(length == 4);
949
950 mutableStr->InsertString(4, u"456");
951 text = mutableStr->GetString();
952 EXPECT_TRUE(text == "123 456");
953 length = mutableStr->GetLength();
954 EXPECT_TRUE(length == 7);
955
956 auto spans = mutableStr->GetSpans(0, 7);
957 EXPECT_TRUE(spans.size() == 1);
958
959 auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption);
960 EXPECT_TRUE(spans[0]->IsAttributesEqual(imageSpan));
961 }
962
963 /**
964 * @tc.name: MutableSpanString011
965 * @tc.desc: Test the insertSpanString in the case of imageSpan
966 * @tc.type: FUNC
967 */
968 HWTEST_F(SpanStringTestNg, MutableSpanString011, TestSize.Level1)
969 {
970 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
971 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
972
973 auto spanStr = AceType::MakeRefPtr<SpanString>(u"123");
974 spanStr->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 3));
975 mutableStr->InsertSpanString(0, spanStr);
976 auto text = mutableStr->GetString();
977 EXPECT_EQ(text, "123 ");
978 auto length = mutableStr->GetLength();
979 EXPECT_EQ(length, 4);
980
981 spanStr = AceType::MakeRefPtr<SpanString>(u"456");
982 spanStr->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont1, 0, 3));
983 mutableStr->InsertSpanString(4, spanStr);
984 text = mutableStr->GetString();
985 EXPECT_EQ(text, "123 456");
986 length = mutableStr->GetLength();
987 EXPECT_EQ(length, 7);
988 auto spans = mutableStr->GetSpans(0, 7);
989 EXPECT_EQ(spans.size(), 3);
990 }
991
992 /**
993 * @tc.name: MutableSpanString012
994 * @tc.desc: Test the replaceSpan/addSpan in the case of imageSpan
995 * @tc.type: FUNC
996 */
997 HWTEST_F(SpanStringTestNg, MutableSpanString012, TestSize.Level1)
998 {
999 auto imageOption = SpanStringTestNg::GetImageOption("src/icon-1.png");
1000 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1001 mutableStr->InsertString(0, u"123");
1002 mutableStr->InsertString(4, u"456");
1003
1004 auto imageOption1 = SpanStringTestNg::GetImageOption("src/icon-2.png");
1005 auto imageSpan1 = AceType::MakeRefPtr<ImageSpan>(imageOption1);
1006 mutableStr->ReplaceSpan(3, 1, imageSpan1);
1007 auto length = mutableStr->GetLength();
1008 EXPECT_TRUE(length == 7);
1009 auto spans = mutableStr->GetSpans(0, 7);
1010 EXPECT_TRUE(spans[0]->IsAttributesEqual(imageSpan1));
1011
1012 auto imageOption2 = SpanStringTestNg::GetImageOption("src/icon-3.png");
1013 auto imageSpan2 = AceType::MakeRefPtr<ImageSpan>(imageOption2);
1014 imageSpan2->UpdateStartIndex(3);
1015 imageSpan2->UpdateEndIndex(4);
1016 mutableStr->AddSpan(imageSpan2);
1017 spans = mutableStr->GetSpans(0, 7);
1018 EXPECT_TRUE(spans[0]->IsAttributesEqual(imageSpan2));
1019 }
1020
1021 /**
1022 * @tc.name: MutableSpanString013
1023 * @tc.desc: Test the appendSpan/removeSpan in the case of imageSpan
1024 * @tc.type: FUNC
1025 */
1026 HWTEST_F(SpanStringTestNg, MutableSpanString013, TestSize.Level1)
1027 {
1028 auto imageOption = SpanStringTestNg::GetImageOption("src/icon-1.png");
1029 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1030 mutableStr->InsertString(0, u"123");
1031 mutableStr->InsertString(4, u"456");
1032 auto imageOption1 = SpanStringTestNg::GetImageOption("src/icon-2.png");
1033 auto imageSpan1 = AceType::MakeRefPtr<SpanString>(imageOption1);
1034 mutableStr->AppendSpanString(imageSpan1);
1035 auto spans = mutableStr->GetSpans(0, 7);
1036 EXPECT_EQ(spans.size(), 1);
1037 mutableStr->RemoveSpan(0, 7, SpanType::Image);
1038 spans = mutableStr->GetSpans(0, 6);
1039 EXPECT_EQ(spans.size(), 0);
1040 spans = mutableStr->GetSpans(0, 7);
1041 EXPECT_EQ(spans.size(), 1);
1042 mutableStr->RemoveSpans(0, 7);
1043 spans = mutableStr->GetSpans(0, 7);
1044 EXPECT_EQ(spans.size(), 0);
1045 }
1046
1047 /**
1048 * @tc.name: MutableSpanString014
1049 * @tc.desc: Test basic function of LineHeightSpan/ParagraphStyleSpan
1050 * @tc.type: FUNC
1051 */
1052 HWTEST_F(SpanStringTestNg, MutableSpanString014, TestSize.Level1)
1053 {
1054 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1055 SpanParagraphStyle spanParagraphStyle;
1056 spanParagraphStyle.align = TextAlign::END;
1057 spanParagraphStyle.maxLines = 4;
1058 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1059 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1060 spanParagraphStyle.textIndent = Dimension(23);
1061 spanParagraphStyle.leadingMargin = LeadingMargin();
1062 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0), Dimension(26.0));
1063 spanString->AddSpan(AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 1));
1064 spanString->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3));
1065 spanString->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(10), 0, 2));
1066
1067 auto firstSpans = spanString->GetSpans(2, 1);
1068 EXPECT_EQ(firstSpans.size(), 1);
1069 auto lineHeightSpan = AceType::DynamicCast<LineHeightSpan>(firstSpans[0]);
1070 EXPECT_NE(lineHeightSpan, nullptr);
1071 EXPECT_EQ(lineHeightSpan->GetStartIndex(), 2);
1072 EXPECT_EQ(lineHeightSpan->GetEndIndex(), 3);
1073 EXPECT_EQ(lineHeightSpan->GetLineHeight(), Dimension(30));
1074
1075 auto paraSpans = spanString->GetSpans(0, 2, SpanType::ParagraphStyle);
1076 EXPECT_EQ(paraSpans.size(), 1);
1077 auto paraSpan = AceType::DynamicCast<ParagraphStyleSpan>(paraSpans[0]);
1078 EXPECT_NE(paraSpan, nullptr);
1079 EXPECT_EQ(paraSpan->GetStartIndex(), 0);
1080 EXPECT_EQ(paraSpan->GetEndIndex(), 1);
1081 EXPECT_EQ(paraSpan->GetParagraphStyle().align, TextAlign::END);
1082 EXPECT_EQ(paraSpan->GetParagraphStyle().maxLines, 4);
1083 EXPECT_EQ(paraSpan->GetParagraphStyle().wordBreak, WordBreak::BREAK_ALL);
1084 EXPECT_EQ(paraSpan->GetParagraphStyle().textOverflow, TextOverflow::ELLIPSIS);
1085 EXPECT_EQ(paraSpan->GetParagraphStyle().textIndent, Dimension(23));
1086 EXPECT_EQ(paraSpan->GetParagraphStyle().leadingMargin.value().size.Width().ConvertToVp(), 25);
1087 EXPECT_EQ(paraSpan->GetParagraphStyle().leadingMargin.value().size.Height().ConvertToVp(), 26);
1088 auto secondSpans = spanString->GetSpans(0, 3);
1089 EXPECT_EQ(secondSpans.size(), 3);
1090 auto thirdSpans = spanString->GetSpans(0, 1);
1091 EXPECT_EQ(thirdSpans.size(), 2);
1092 auto fourthSpans = spanString->GetSpans(3, 1);
1093 EXPECT_EQ(fourthSpans.size(), 0);
1094 auto fifthSpans = spanString->GetSpans(0, 9);
1095 EXPECT_EQ(fifthSpans.size(), 3);
1096 }
1097
1098 /**
1099 * @tc.name: MutableSpanString015
1100 * @tc.desc: Test isAttributesEqual of LineHeightSpan/ParagraphStyleSpan
1101 * @tc.type: FUNC
1102 */
1103 HWTEST_F(SpanStringTestNg, MutableSpanString015, TestSize.Level1)
1104 {
1105 SpanParagraphStyle spanParagraphStyle;
1106 spanParagraphStyle.align = TextAlign::END;
1107 spanParagraphStyle.maxLines = 4;
1108 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1109 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1110 spanParagraphStyle.textIndent = Dimension(23);
1111 spanParagraphStyle.leadingMargin = LeadingMargin();
1112 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0), Dimension(26.0));
1113 auto paraSpan = AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 1);
1114 auto paraSpan2 = AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 1);
1115 EXPECT_TRUE(paraSpan->IsAttributesEqual(paraSpan2));
1116
1117 auto lineHeightSpan = AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3);
1118 auto lineHeightSpan2 = AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3);
1119 auto lineHeightSpan3 = AceType::MakeRefPtr<LineHeightSpan>(Dimension(25), 0, 3);
1120 EXPECT_TRUE(lineHeightSpan->IsAttributesEqual(lineHeightSpan2));
1121 EXPECT_FALSE(lineHeightSpan->IsAttributesEqual(lineHeightSpan3));
1122 }
1123
1124 /**
1125 * @tc.name: MutableSpanString016
1126 * @tc.desc: Test AppendSpanString/ReplaceSpanString of LineHeightSpan/ParagraphStyleSpan
1127 * @tc.type: FUNC
1128 */
1129 HWTEST_F(SpanStringTestNg, MutableSpanString016, TestSize.Level1)
1130 {
1131 SpanParagraphStyle spanParagraphStyle;
1132 spanParagraphStyle.align = TextAlign::END;
1133 spanParagraphStyle.maxLines = 4;
1134 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1135 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1136 spanParagraphStyle.textIndent = Dimension(23);
1137 spanParagraphStyle.leadingMargin = LeadingMargin();
1138 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0), Dimension(26.0));
1139 auto paraSpan = AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 1);
1140 auto lineHeightSpan = AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3);
1141
1142 auto imageOption = SpanStringTestNg::GetImageOption("src/icon-1.png");
1143 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1144 auto mutableStr2 = AceType::MakeRefPtr<MutableSpanString>(u"123456");
1145 mutableStr->AddSpan(paraSpan);
1146 mutableStr2->AddSpan(lineHeightSpan);
1147 mutableStr->AppendSpanString(mutableStr2);
1148 EXPECT_EQ(mutableStr->GetString(), " 123456");
1149 auto spans = mutableStr->GetSpans(0, 7);
1150 EXPECT_EQ(spans.size(), 3);
1151 mutableStr->ReplaceSpanString(1, 1, mutableStr2);
1152 EXPECT_EQ(mutableStr->GetString(), " 12345623456");
1153 }
1154
1155 /**
1156 * @tc.name: MutableSpanString017
1157 * @tc.desc: Test InsertSpanString of LineHeightSpan/ParagraphStyleSpan
1158 * @tc.type: FUNC
1159 */
1160 HWTEST_F(SpanStringTestNg, MutableSpanString017, TestSize.Level1)
1161 {
1162 SpanParagraphStyle spanParagraphStyle;
1163 spanParagraphStyle.align = TextAlign::END;
1164 spanParagraphStyle.maxLines = 4;
1165 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1166 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1167 spanParagraphStyle.textIndent = Dimension(23);
1168 spanParagraphStyle.leadingMargin = LeadingMargin();
1169 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0), Dimension(26.0));
1170 auto paraSpan = AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 0, 1);
1171
1172 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
1173 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1174
1175 auto spanStr = AceType::MakeRefPtr<SpanString>(u"123");
1176 spanStr->AddSpan(paraSpan);
1177 mutableStr->InsertSpanString(0, spanStr);
1178 auto text = mutableStr->GetString();
1179 EXPECT_EQ(text, "123 ");
1180 auto length = mutableStr->GetLength();
1181 EXPECT_EQ(length, 4);
1182
1183 spanStr = AceType::MakeRefPtr<SpanString>(u"456");
1184 spanStr->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3));
1185 mutableStr->InsertSpanString(4, spanStr);
1186 text = mutableStr->GetString();
1187 EXPECT_EQ(text, "123 456");
1188 length = mutableStr->GetLength();
1189 EXPECT_EQ(length, 7);
1190 auto spans = mutableStr->GetSpans(0, 7);
1191 EXPECT_EQ(spans.size(), 3);
1192 }
1193
1194 /**
1195 * @tc.name: MutableSpanString018
1196 * @tc.desc: Test serialization and unserialization of SpanString
1197 * @tc.type: FUNC
1198 */
1199 HWTEST_F(SpanStringTestNg, MutableSpanString018, TestSize.Level1)
1200 {
1201 std::vector<uint8_t> buff;
1202 Font testFont { OHOS::Ace::FontWeight::BOLD, Dimension(29.0, DimensionUnit::PX), OHOS::Ace::FontStyle::ITALIC,
1203 std::vector<std::string>(test_str, test_str + 10), OHOS::Ace::Color::RED };
1204 Font testFont2 { OHOS::Ace::FontWeight::W300, Dimension(49.0, DimensionUnit::VP), OHOS::Ace::FontStyle::ITALIC,
1205 std::vector<std::string>(test_str, test_str + 5), OHOS::Ace::Color::BLUE };
1206 auto spanStr = AceType::MakeRefPtr<SpanString>(u"dddd当地经的123456");
1207 spanStr->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(30), 0, 3));
1208 spanStr->AddSpan(AceType::MakeRefPtr<LineHeightSpan>(Dimension(10), 0, 2));
1209 spanStr->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont, 1, 2));
1210 spanStr->AddSpan(AceType::MakeRefPtr<FontSpan>(testFont2, 4, 5));
1211 spanStr->AddSpan(AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(15), 8, 9));
1212 spanStr->AddSpan(AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(16), 9, 10));
1213 SpanParagraphStyle spanParagraphStyle;
1214 spanParagraphStyle.align = TextAlign::END;
1215 spanParagraphStyle.maxLines = 4;
1216 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
1217 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
1218 spanParagraphStyle.textIndent = Dimension(23);
1219 spanParagraphStyle.leadingMargin = LeadingMargin();
1220 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0), Dimension(26.0));
1221 spanStr->AddSpan(AceType::MakeRefPtr<ParagraphStyleSpan>(spanParagraphStyle, 10, 11));
1222 spanStr->EncodeTlv(buff);
1223 auto spanString2 = SpanString::DecodeTlv(buff);
1224 std::list<RefPtr<NG::SpanItem>> spans = spanString2->GetSpanItems();
1225
1226 EXPECT_EQ(spans.size(), 10);
1227 EXPECT_EQ(spanStr->GetString(), "dddd当地经的123456");
1228 auto it = spans.begin();
1229 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "d");
1230 EXPECT_EQ((*it)->interval.first, 0);
1231 EXPECT_EQ((*it)->interval.second, 1);
1232 EXPECT_EQ((*it)->textLineStyle->GetLineHeight().value(), Dimension(10));
1233 ++it;
1234 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "d");
1235 EXPECT_EQ((*it)->interval.first, 1);
1236 EXPECT_EQ((*it)->interval.second, 2);
1237 EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(29));
1238 EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), OHOS::Ace::Color::RED);
1239 EXPECT_EQ((*it)->fontStyle->GetItalicFontStyle().value(), OHOS::Ace::FontStyle::ITALIC);
1240 EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), OHOS::Ace::FontWeight::BOLD);
1241 EXPECT_EQ((*it)->textLineStyle->GetLineHeight().value(), Dimension(10));
1242 ++it;
1243 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "d");
1244 EXPECT_EQ((*it)->interval.first, 2);
1245 EXPECT_EQ((*it)->interval.second, 3);
1246 EXPECT_EQ((*it)->textLineStyle->GetLineHeight().value(), Dimension(30));
1247 ++it;
1248 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "d");
1249 EXPECT_EQ((*it)->interval.first, 3);
1250 EXPECT_EQ((*it)->interval.second, 4);
1251 ++it;
1252 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "当");
1253 EXPECT_EQ((*it)->interval.first, 4);
1254 EXPECT_EQ((*it)->interval.second, 5);
1255 EXPECT_EQ((*it)->fontStyle->GetFontSize().value(), Dimension(49, OHOS::Ace::DimensionUnit::VP));
1256 EXPECT_EQ((*it)->fontStyle->GetTextColor().value(), OHOS::Ace::Color::BLUE);
1257 EXPECT_EQ((*it)->fontStyle->GetItalicFontStyle().value(), OHOS::Ace::FontStyle::ITALIC);
1258 EXPECT_EQ((*it)->fontStyle->GetFontWeight().value(), OHOS::Ace::FontWeight::W300);
1259 ++it;
1260 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "地经的");
1261 EXPECT_EQ((*it)->interval.first, 5);
1262 EXPECT_EQ((*it)->interval.second, 8);
1263 ++it;
1264 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "1");
1265 EXPECT_EQ((*it)->interval.first, 8);
1266 EXPECT_EQ((*it)->interval.second, 9);
1267 EXPECT_EQ((*it)->fontStyle->GetLetterSpacing().value(), Dimension(15));
1268 ++it;
1269 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "2");
1270 EXPECT_EQ((*it)->interval.first, 9);
1271 EXPECT_EQ((*it)->interval.second, 10);
1272 EXPECT_EQ((*it)->textLineStyle->GetBaselineOffset().value(), Dimension(16));
1273 ++it;
1274 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "3");
1275 EXPECT_EQ((*it)->interval.first, 10);
1276 EXPECT_EQ((*it)->interval.second, 11);
1277 EXPECT_EQ((*it)->textLineStyle->GetTextOverflow().value(), TextOverflow::ELLIPSIS);
1278 EXPECT_EQ((*it)->textLineStyle->GetTextAlign().value(), TextAlign::END);
1279 EXPECT_EQ((*it)->textLineStyle->GetMaxLines().value(), 4);
1280 EXPECT_EQ((*it)->textLineStyle->GetTextIndent().value(), Dimension(23));
1281 EXPECT_EQ((*it)->textLineStyle->GetWordBreak().value(), WordBreak::BREAK_ALL);
1282 ++it;
1283 EXPECT_EQ(StringUtils::Str16ToStr8((*it)->content), "456");
1284 EXPECT_EQ((*it)->interval.first, 11);
1285 EXPECT_EQ((*it)->interval.second, 14);
1286 }
1287
1288 /**
1289 * @tc.name: MutableSpanString019
1290 * @tc.desc: Test InsertSpanString of ExtSpan
1291 * @tc.type: FUNC
1292 */
1293 HWTEST_F(SpanStringTestNg, MutableSpanString019, TestSize.Level1)
1294 {
1295 auto extSpan = AceType::MakeRefPtr<ExtSpan>(1, 2);
1296 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
1297 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1298 auto spanStr = AceType::MakeRefPtr<SpanString>(u"12345");
1299 spanStr->AddSpan(extSpan);
1300 mutableStr->InsertSpanString(0, spanStr);
1301 auto text = mutableStr->GetString();
1302 EXPECT_EQ(text, "12345 ");
1303 auto length = mutableStr->GetLength();
1304 EXPECT_EQ(length, 6);
1305 auto spans = mutableStr->GetSpans(0, 6);
1306 EXPECT_EQ(spans.size(), 2);
1307 spans = mutableStr->GetSpans(1, 3);
1308 EXPECT_EQ(spans.size(), 1);
1309 for (auto span : spans) {
1310 EXPECT_EQ(span->GetStartIndex(), 1);
1311 EXPECT_EQ(span->GetEndIndex(), 2);
1312 }
1313 }
1314
1315 /**
1316 * @tc.name: SpanStringTest009
1317 * @tc.desc: Test basic function of span object
1318 * @tc.type: FUNC
1319 */
1320 HWTEST_F(SpanStringTestNg, SpanString009, TestSize.Level1)
1321 {
1322 std::string buffer;
1323 RefPtr<FontSpan> fontSpan = AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10);
1324 buffer = fontSpan->ToString();
1325 EXPECT_FALSE(buffer.empty());
1326 EXPECT_EQ(buffer.find("FontSpan"), 0);
1327
1328 auto spanItem = AceType::MakeRefPtr<NG::SpanItem>();
1329 auto decorationSpan =
1330 AceType::MakeRefPtr<DecorationSpan>(TextDecoration::OVERLINE, Color::RED, TextDecorationStyle::WAVY, 0, 1);
1331 EXPECT_FALSE(fontSpan->IsAttributesEqual(decorationSpan));
1332 decorationSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
1333 buffer.clear();
1334 buffer = decorationSpan->ToString();
1335 EXPECT_FALSE(buffer.empty());
1336 EXPECT_EQ(buffer.find("DecorationSpan"), 0);
1337 EXPECT_FALSE(decorationSpan->IsAttributesEqual(fontSpan));
1338
1339 auto baselineOffsetSpan = AceType::MakeRefPtr<BaselineOffsetSpan>(Dimension(4), 0, 2);
1340 EXPECT_FALSE(baselineOffsetSpan->IsAttributesEqual(decorationSpan));
1341 baselineOffsetSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
1342 buffer.clear();
1343 buffer = baselineOffsetSpan->ToString();
1344 EXPECT_FALSE(buffer.empty());
1345 EXPECT_EQ(buffer.find("BaselineOffsetSpan"), 0);
1346
1347 auto letterSpacingSpan = AceType::MakeRefPtr<LetterSpacingSpan>(Dimension(5), 0, 3);
1348 EXPECT_FALSE(letterSpacingSpan->IsAttributesEqual(decorationSpan));
1349 letterSpacingSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
1350 buffer.clear();
1351 buffer = letterSpacingSpan->ToString();
1352 EXPECT_FALSE(buffer.empty());
1353 EXPECT_EQ(buffer.find("LetterSpacingSpan"), 0);
1354
1355 Shadow textShadow;
1356 textShadow.SetBlurRadius(1.0);
1357 textShadow.SetColor(Color::BLACK);
1358 textShadow.SetOffsetX(6.0);
1359 textShadow.SetOffsetY(6.0);
1360 vector<Shadow> textShadows { textShadow };
1361 vector<Shadow> textShadows2;
1362 textShadow.SetColor(Color::RED);
1363 vector<Shadow> textShadows3 {textShadow};
1364 auto textShadowSpan = AceType::MakeRefPtr<TextShadowSpan>(textShadows, 7, 9);
1365 auto textShadowSpan2 = AceType::MakeRefPtr<TextShadowSpan>(textShadows2, 7, 9);
1366 auto textShadowSpan3 = AceType::MakeRefPtr<TextShadowSpan>(textShadows3, 7, 9);
1367 EXPECT_FALSE(textShadowSpan->IsAttributesEqual(decorationSpan));
1368 EXPECT_FALSE(textShadowSpan->IsAttributesEqual(textShadowSpan2));
1369 EXPECT_FALSE(textShadowSpan->IsAttributesEqual(textShadowSpan3));
1370 textShadowSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
1371 buffer = textShadowSpan->ToString();
1372 EXPECT_FALSE(buffer.empty());
1373 EXPECT_EQ(buffer.find("TextShadowSpan"), 0);
1374 }
1375
1376 /**
1377 * @tc.name: SpanStringTest010
1378 * @tc.desc: Test basic function of span object
1379 * @tc.type: FUNC
1380 */
1381 HWTEST_F(SpanStringTestNg, SpanString010, TestSize.Level1)
1382 {
1383 std::string buffer;
1384 auto spanItem = AceType::MakeRefPtr<NG::SpanItem>();
1385 auto imageSpanItem = AceType::MakeRefPtr<NG::ImageSpanItem>();
1386 auto imageOption = SpanStringTestNg::GetImageOption("src/icon.png");
1387 auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption);
1388 imageSpan->ApplyToSpanItem(spanItem, SpanOperation::ADD);
1389 imageSpan->ApplyToSpanItem(imageSpanItem, SpanOperation::ADD);
1390 imageSpan->ApplyToSpanItem(imageSpanItem, SpanOperation::REMOVE);
1391 imageSpan->GetSubSpan(0, 3);
1392 buffer = imageSpan->ToString();
1393 EXPECT_FALSE(buffer.empty());
1394 EXPECT_EQ(buffer.find("ImageSpan"), 0);
1395
1396 auto customSpan = AceType::MakeRefPtr<CustomSpan>();
1397 auto customSpanItem = AceType::MakeRefPtr<NG::CustomSpanItem>();
1398 customSpan->ApplyToSpanItem(spanItem, SpanOperation::ADD);
1399 customSpan->ApplyToSpanItem(customSpanItem, SpanOperation::ADD);
1400 customSpan->ApplyToSpanItem(customSpanItem, SpanOperation::REMOVE);
1401 buffer = customSpan->ToString();
1402 EXPECT_FALSE(buffer.empty());
1403 EXPECT_EQ(buffer.find("CustomSpan"), 0);
1404
1405 RefPtr<FontSpan> fontSpan = AceType::MakeRefPtr<FontSpan>(testFont1, 0, 10);
1406 auto paragraphStyleSpan = AceType::MakeRefPtr<ParagraphStyleSpan>();
1407 paragraphStyleSpan->ApplyToSpanItem(spanItem, SpanOperation::REMOVE);
1408 EXPECT_FALSE(paragraphStyleSpan->IsAttributesEqual(fontSpan));
1409 buffer = paragraphStyleSpan->ToString();
1410 EXPECT_FALSE(buffer.empty());
1411 EXPECT_EQ(buffer.find("ParagraphStyleSpan"), 0);
1412
1413 auto lineHeightSpan = AceType::MakeRefPtr<LineHeightSpan>();
1414 EXPECT_FALSE(lineHeightSpan->IsAttributesEqual(fontSpan));
1415 buffer = lineHeightSpan->ToString();
1416 EXPECT_FALSE(buffer.empty());
1417 EXPECT_EQ(buffer.find("LineHeightSpan"), 0);
1418
1419 GestureStyle gestureInfo;
1420 auto gestureSpan = AceType::MakeRefPtr<GestureSpan>(gestureInfo, 0, 3);
1421 EXPECT_FALSE(gestureSpan->IsAttributesEqual(lineHeightSpan));
1422 gestureSpan->AddSpanStyle(spanItem);
__anon3ea853ca0602(const BaseEventInfo* info) 1423 auto onClick = [](const BaseEventInfo* info) {};
__anon3ea853ca0702(GestureEvent& info) 1424 auto tmpClickFunc = [func = std::move(onClick)](GestureEvent& info) { func(&info); };
1425 gestureInfo.onClick = std::move(tmpClickFunc);
1426 gestureSpan->AddSpanStyle(spanItem);
1427 }
1428
1429 /**
1430 * @tc.name: SpanStringTest011
1431 * @tc.desc: Test basic function of BackgroundColorSpan
1432 * @tc.type: FUNC
1433 */
1434 HWTEST_F(SpanStringTestNg, SpanString011, TestSize.Level1)
1435 {
1436 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1437
1438 TextBackgroundStyle textBackgroundStyle;
1439 NG::BorderRadiusProperty borderRadius;
1440 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1441 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1442 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1443 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1444 textBackgroundStyle.backgroundColor = Color::RED;;
1445 textBackgroundStyle.backgroundRadius = borderRadius;
1446
1447 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 7, 9));
1448 auto firstSpans = spanString->GetSpans(2, 1);
1449 EXPECT_EQ(firstSpans.size(), 0);
1450 auto backgroundColorSpan = AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle);
1451 EXPECT_NE(backgroundColorSpan, nullptr);
1452 EXPECT_EQ(backgroundColorSpan->GetStartIndex(), 0);
1453 EXPECT_EQ(backgroundColorSpan->GetEndIndex(), 0);
1454
1455 auto secondSpans = spanString->GetSpans(1, 1);
1456 EXPECT_EQ(secondSpans.size(), 0);
1457
1458 auto thirdSpans = spanString->GetSpans(0, 1);
1459 EXPECT_EQ(thirdSpans.size(), 0);
1460
1461 auto fourthSpans = spanString->GetSpans(3, 1);
1462 EXPECT_EQ(fourthSpans.size(), 0);
1463
1464 auto fifthSpans = spanString->GetSpans(0, 9);
1465 EXPECT_EQ(fifthSpans.size(), 1);
1466 }
1467
1468 /**
1469 * @tc.name: SpanStringTest012
1470 * @tc.desc: Test basic function of BackgroundColorSpan
1471 * @tc.type: FUNC
1472 */
1473 HWTEST_F(SpanStringTestNg, SpanString012, TestSize.Level1)
1474 {
1475 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1476
1477 TextBackgroundStyle textBackgroundStyle;
1478 NG::BorderRadiusProperty borderRadius;
1479 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1480 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1481 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1482 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1483
1484 textBackgroundStyle.backgroundColor = Color::RED;;
1485 textBackgroundStyle.backgroundRadius = borderRadius;
1486
1487 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 8, 10));
1488 auto subSpanString = spanString->GetSubSpanString(0, 10);
1489 EXPECT_TRUE(subSpanString->IsEqualToSpanString(spanString));
1490
1491 auto firstSpans = spanString->GetSpans(8, 1);
1492 EXPECT_EQ(firstSpans.size(), 1);
1493 auto backgroundColorSpan = AceType::DynamicCast<BackgroundColorSpan>(firstSpans[0]);
1494 EXPECT_NE(backgroundColorSpan, nullptr);
1495 EXPECT_EQ(backgroundColorSpan->GetStartIndex(), 8);
1496 EXPECT_EQ(backgroundColorSpan->GetEndIndex(), 9);
1497 EXPECT_TRUE(backgroundColorSpan->GetBackgroundColor() == textBackgroundStyle);
1498 }
1499
1500 /**
1501 * @tc.name: SpanString013
1502 * @tc.desc: Test insert spanstring between BackgroundColorSpan
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(SpanStringTestNg, SpanString013, TestSize.Level1)
1506 {
1507 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1508 auto insertString = AceType::MakeRefPtr<MutableSpanString>(u"abc");
1509
1510 TextBackgroundStyle textBackgroundStyle;
1511 NG::BorderRadiusProperty borderRadius;
1512 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1513 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1514 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1515 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1516
1517 textBackgroundStyle.backgroundColor = Color::RED;;
1518 textBackgroundStyle.backgroundRadius = borderRadius;
1519
1520 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 8));
1521 // insert span string
1522 spanString->InsertSpanString(2, insertString);
1523
1524 // check range start->end [0, 13]
1525 auto backgroundSpans = spanString->GetSpans(0, 13);
1526 EXPECT_EQ(backgroundSpans.size(), 2);
1527 auto firstBackgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1528 EXPECT_NE(firstBackgroundSpan, nullptr);
1529 EXPECT_EQ(firstBackgroundSpan->GetStartIndex(), 0);
1530 EXPECT_EQ(firstBackgroundSpan->GetEndIndex(), 2);
1531 EXPECT_TRUE(firstBackgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1532
1533 auto secondBackgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[1]);
1534 EXPECT_NE(secondBackgroundSpan, nullptr);
1535 EXPECT_EQ(secondBackgroundSpan->GetStartIndex(), 5);
1536 EXPECT_EQ(secondBackgroundSpan->GetEndIndex(), 11);
1537 EXPECT_TRUE(secondBackgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1538
1539 // check range [0, 10]
1540 backgroundSpans = spanString->GetSpans(0, 10);
1541 EXPECT_EQ(backgroundSpans.size(), 2);
1542
1543 auto secondBackgroundSpan2 = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[1]);
1544 EXPECT_NE(secondBackgroundSpan2, nullptr);
1545 EXPECT_EQ(secondBackgroundSpan2->GetStartIndex(), 5);
1546 EXPECT_EQ(secondBackgroundSpan2->GetEndIndex(), 10);
1547 EXPECT_TRUE(secondBackgroundSpan2->GetBackgroundColor() == textBackgroundStyle);
1548 }
1549
1550 /**
1551 * @tc.name: SpanString014
1552 * @tc.desc: Test append spanstring after BackgroundColorSpan
1553 * @tc.type: FUNC
1554 */
1555 HWTEST_F(SpanStringTestNg, SpanString014, TestSize.Level1)
1556 {
1557 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1558 auto appendString = AceType::MakeRefPtr<MutableSpanString>(u"abc");
1559
1560 TextBackgroundStyle textBackgroundStyle;
1561 NG::BorderRadiusProperty borderRadius;
1562 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1563 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1564 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1565 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1566
1567 textBackgroundStyle.backgroundColor = Color::RED;;
1568 textBackgroundStyle.backgroundRadius = borderRadius;
1569
1570 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 10));
1571 // append span string
1572 spanString->AppendSpanString(appendString);
1573
1574 // check range
1575 auto backgroundSpans = spanString->GetSpans(0, 13);
1576 EXPECT_EQ(backgroundSpans.size(), 1);
1577 auto firstBackgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1578 EXPECT_NE(firstBackgroundSpan, nullptr);
1579 EXPECT_EQ(firstBackgroundSpan->GetStartIndex(), 0);
1580 EXPECT_EQ(firstBackgroundSpan->GetEndIndex(), 10);
1581 EXPECT_TRUE(firstBackgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1582 }
1583
1584 /**
1585 * @tc.name: SpanString015
1586 * @tc.desc: Test insert string between BackgroundColorSpan
1587 * @tc.type: FUNC
1588 */
1589 HWTEST_F(SpanStringTestNg, SpanString015, TestSize.Level1)
1590 {
1591 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1592
1593 TextBackgroundStyle textBackgroundStyle;
1594 NG::BorderRadiusProperty borderRadius;
1595 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1596 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1597 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1598 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1599
1600 textBackgroundStyle.backgroundColor = Color::BLUE;;
1601 textBackgroundStyle.backgroundRadius = borderRadius;
1602 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1603
1604 // insert value
1605 spanString->InsertString(2, u"abc");
1606
1607 // check range of span
1608 auto backgroundSpans = spanString->GetSpans(0, 10);
1609 EXPECT_EQ(backgroundSpans.size(), 1);
1610 auto backgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1611 EXPECT_NE(backgroundSpan, nullptr);
1612 EXPECT_EQ(backgroundSpan->GetStartIndex(), 0);
1613 EXPECT_EQ(backgroundSpan->GetEndIndex(), 8);
1614 EXPECT_TRUE(backgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1615 }
1616
1617 /**
1618 * @tc.name: SpanString016
1619 * @tc.desc: Test remove string between BackgroundColorSpan
1620 * @tc.type: FUNC
1621 */
1622 HWTEST_F(SpanStringTestNg, SpanString016, TestSize.Level1)
1623 {
1624 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1625
1626 TextBackgroundStyle textBackgroundStyle;
1627 NG::BorderRadiusProperty borderRadius;
1628 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1629 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1630 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1631 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1632
1633 textBackgroundStyle.backgroundColor = Color::BLUE;;
1634 textBackgroundStyle.backgroundRadius = borderRadius;
1635
1636 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1637 // remove string
1638 spanString->RemoveString(2, 1);
1639
1640 // check range of span
1641 auto backgroundSpans = spanString->GetSpans(0, 7);
1642 EXPECT_EQ(backgroundSpans.size(), 1);
1643 auto backgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1644 EXPECT_NE(backgroundSpan, nullptr);
1645 EXPECT_EQ(backgroundSpan->GetStartIndex(), 0);
1646 EXPECT_EQ(backgroundSpan->GetEndIndex(), 4);
1647 EXPECT_TRUE(backgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1648
1649 // remove multi times
1650 spanString->RemoveString(2, 2);
1651 backgroundSpans = spanString->GetSpans(0, 7);
1652 EXPECT_EQ(backgroundSpans.size(), 1);
1653 backgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1654 EXPECT_NE(backgroundSpan, nullptr);
1655 EXPECT_EQ(backgroundSpan->GetStartIndex(), 0);
1656 EXPECT_EQ(backgroundSpan->GetEndIndex(), 2);
1657 EXPECT_TRUE(backgroundSpan->GetBackgroundColor() == textBackgroundStyle);
1658 }
1659
1660 /**
1661 * @tc.name: SpanString017
1662 * @tc.desc: Test remove span of BackgroundColorSpan
1663 * @tc.type: FUNC
1664 */
1665 HWTEST_F(SpanStringTestNg, SpanString017, TestSize.Level1)
1666 {
1667 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1668
1669 TextBackgroundStyle textBackgroundStyle;
1670 NG::BorderRadiusProperty borderRadius;
1671 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1672 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1673 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1674 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1675
1676 textBackgroundStyle.backgroundColor = Color::BLUE;;
1677 textBackgroundStyle.backgroundRadius = borderRadius;
1678
1679 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1680 // remove string
1681 spanString->RemoveSpan(0, 5, SpanType::BackgroundColor);
1682
1683 // check span count
1684 auto backgroundSpans = spanString->GetSpans(0, 10);
1685 EXPECT_EQ(backgroundSpans.size(), 0);
1686
1687 // add again
1688 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1689 backgroundSpans = spanString->GetSpans(0, 10);
1690 EXPECT_EQ(backgroundSpans.size(), 1);
1691
1692 auto backgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(backgroundSpans[0]);
1693 EXPECT_NE(backgroundSpan, nullptr);
1694 EXPECT_EQ(backgroundSpan->GetStartIndex(), 0);
1695 EXPECT_EQ(backgroundSpan->GetEndIndex(), 5);
1696 }
1697
1698 /**
1699 * @tc.name: SpanString018
1700 * @tc.desc: Test remove span of BackgroundColorSpan
1701 * @tc.type: FUNC
1702 */
1703 HWTEST_F(SpanStringTestNg, SpanString018, TestSize.Level1)
1704 {
1705 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
1706
1707 TextBackgroundStyle textBackgroundStyle;
1708 NG::BorderRadiusProperty borderRadius;
1709 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1710 borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1711 borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1712 borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1713
1714 textBackgroundStyle.backgroundColor = Color::BLUE;;
1715 textBackgroundStyle.backgroundRadius = borderRadius;
1716
1717 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1718 // remove string
1719 spanString->RemoveSpan(0, 5, SpanType::BackgroundColor);
1720
1721 // check span count
1722 auto spans = spanString->GetSpans(0, 10);
1723 EXPECT_EQ(spans.size(), 0);
1724
1725 // add again
1726 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 0, 5));
1727 spans = spanString->GetSpans(0, 10);
1728 EXPECT_EQ(spans.size(), 1);
1729
1730 auto backgroundSpan = AceType::DynamicCast<BackgroundColorSpan>(spans[0]);
1731 EXPECT_NE(backgroundSpan, nullptr);
1732 EXPECT_EQ(backgroundSpan->GetStartIndex(), 0);
1733 EXPECT_EQ(backgroundSpan->GetEndIndex(), 5);
1734
1735 // remove all spans
1736 spanString->ClearAllSpans();
1737 spans = spanString->GetSpans(0, 10);
1738 EXPECT_EQ(spans.size(), 0);
1739 }
1740
1741 /**
1742 * @tc.name: SpanStringTest019
1743 * @tc.desc: Test basic function of ImageAttachment setting color filter
1744 * @tc.type: FUNC
1745 */
1746 HWTEST_F(SpanStringTestNg, SpanString019, TestSize.Level1)
1747 {
1748 auto imageOption = SpanStringTestNg::GetColorFilterImageOption("src/icon-1.png");
1749 auto mutableStr = AceType::MakeRefPtr<MutableSpanString>(imageOption);
1750 auto imageSpan = AceType::MakeRefPtr<ImageSpan>(imageOption);
1751 EXPECT_EQ(imageSpan->GetImageSpanOptions().imageAttribute, imageOption.imageAttribute);
1752 mutableStr->InsertString(0, u"123");
1753 mutableStr->InsertString(4, u"456");
1754 auto imageOption1 = SpanStringTestNg::GetColorFilterImageOption("src/icon-2.png");
1755 auto imageSpan1 = AceType::MakeRefPtr<SpanString>(imageOption1);
1756 mutableStr->AppendSpanString(imageSpan1);
1757 auto customSpan = AceType::MakeRefPtr<CustomSpan>();
1758 auto spanString = AceType::MakeRefPtr<MutableSpanString>(customSpan);
1759 spanString->AppendSpanString(mutableStr);
1760 auto spans = spanString->GetSpans(0, spanString->GetLength());
1761 EXPECT_EQ(spans.size(), 3);
1762 spanString->AppendSpanString(spanString);
1763 spans = spanString->GetSpans(0, spanString->GetLength());
1764 EXPECT_EQ(spans.size(), 6);
1765 }
1766
1767 /*
1768 * @tc.name: SpanStringTest020
1769 * @tc.desc: Test InsertString method adjusts span positions correctly
1770 * @tc.type: FUNC
1771 */
1772 HWTEST_F(SpanStringTestNg, SpanString020, TestSize.Level1)
1773 {
1774 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1775 TextBackgroundStyle textBackgroundStyle;
1776 NG::BorderRadiusProperty borderRadius;
1777 borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
1778 textBackgroundStyle.backgroundColor = Color::RED;
1779 textBackgroundStyle.backgroundRadius = borderRadius;
1780
1781 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 7, 9));
1782 spanString->InsertString(3, u"ab"); // 在位置3插入2字符
1783
1784 auto spans = spanString->GetSpans(9, 2); // 原span范围7-9变为7-11
1785 EXPECT_EQ(spans.size(), 1);
1786 if (!spans.empty()) {
1787 auto span = AceType::DynamicCast<BackgroundColorSpan>(spans.front());
1788 EXPECT_NE(span, nullptr);
1789 EXPECT_EQ(span->GetStartIndex(), 9); // 7 + 2 = 9
1790 EXPECT_EQ(span->GetEndIndex(), 11); // 9 + 2 = 11
1791 }
1792 }
1793
1794 /**
1795 * @tc.name: SpanStringTest021
1796 * @tc.desc: Test RemoveString shortens span positions
1797 * @tc.type: FUNC
1798 */
1799 HWTEST_F(SpanStringTestNg, SpanString021, TestSize.Level1)
1800 {
1801 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1802 TextBackgroundStyle textBackgroundStyle;
1803 textBackgroundStyle.backgroundColor = Color::BLUE;
1804 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(textBackgroundStyle, 3, 7));
1805
1806 spanString->RemoveString(5, 2); // 删除位置5的两个字符
1807
1808 auto spans = spanString->GetSpans(3, 2); // 原3-7变为3-5
1809 EXPECT_EQ(spans.size(), 1);
1810 if (!spans.empty()) {
1811 EXPECT_EQ(spans.front()->GetEndIndex(), 5);
1812 }
1813 }
1814
1815 /**
1816 * @tc.name: SpanStringTest022
1817 * @tc.desc: Test ReplaceSpan replaces existing span
1818 * @tc.type: FUNC
1819 */
1820 HWTEST_F(SpanStringTestNg, SpanString022, TestSize.Level1)
1821 {
1822 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1823 TextBackgroundStyle oldStyle;
1824 oldStyle.backgroundColor = Color::GRAY;
1825 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(oldStyle, 2, 5));
1826
1827 TextBackgroundStyle newStyle;
1828 newStyle.backgroundColor = Color::GREEN;
1829 auto newSpan = AceType::MakeRefPtr<BackgroundColorSpan>(newStyle, 2, 5);
1830
1831 spanString->ReplaceSpan(2, 3, newSpan); // 替换2-5范围的span
1832
1833 auto spans = spanString->GetSpans(2, 3);
1834 EXPECT_EQ(spans.size(), 1);
1835 EXPECT_EQ(AceType::DynamicCast<BackgroundColorSpan>(spans.front())->GetBackgroundColor().backgroundColor.value(),
1836 Color::GREEN);
1837 }
1838
1839 /**
1840 * @tc.name: SpanStringTest023
1841 * @tc.desc: Test RemoveSpans removes spans in range
1842 * @tc.type: FUNC
1843 */
1844 HWTEST_F(SpanStringTestNg, SpanString023, TestSize.Level1)
1845 {
1846 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1847 TextBackgroundStyle style;
1848 style.backgroundColor = Color::RED;
1849 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 1, 3));
1850 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 4, 6));
1851
1852 spanString->RemoveSpans(2, 3, true); // 移除2-5区间
1853
1854 EXPECT_EQ(spanString->GetSpans(1, 6).size(), 2); // 剩余2个span
1855 }
1856
1857 /**
1858 * @tc.name: SpanStringTest024
1859 * @tc.desc: Test ClearAllSpans removes all spans
1860 * @tc.type: FUNC
1861 */
1862 HWTEST_F(SpanStringTestNg, SpanString024, TestSize.Level1)
1863 {
1864 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1865 TextBackgroundStyle style;
1866 style.backgroundColor = Color::RED;
1867 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 0, 2));
1868 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 5, 8));
1869
1870 spanString->ClearAllSpans();
1871
1872 EXPECT_EQ(spanString->GetSpans(0, 10).size(), 0);
1873 }
1874
1875 /**
1876 * @tc.name: SpanStringTest025
1877 * @tc.desc: Test ReplaceSpanString replaces text and spans
1878 * @tc.type: FUNC
1879 */
1880 HWTEST_F(SpanStringTestNg, SpanString025, TestSize.Level1)
1881 {
1882 auto original = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1883 TextBackgroundStyle originalStyle;
1884 originalStyle.backgroundColor = Color::BLACK;
1885 original->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(originalStyle, 2, 5));
1886
1887 auto replacement = AceType::MakeRefPtr<MutableSpanString>(u"abc");
1888 TextBackgroundStyle newStyle;
1889 newStyle.backgroundColor = Color::WHITE;
1890 replacement->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(newStyle, 0, 3));
1891
1892 original->ReplaceSpanString(3, 2, replacement); // 替换位置3的2字符为"abc"
1893
1894 auto spans = original->GetSpans(3, 3); // 新插入的span应位于3-6
1895 EXPECT_EQ(spans.size(), 1);
1896 EXPECT_EQ(AceType::DynamicCast<BackgroundColorSpan>(spans.front())->GetBackgroundColor().backgroundColor.value(),
1897 Color::WHITE);
1898 }
1899
1900 /**
1901 * @tc.name: SpanStringTest026
1902 * @tc.desc: Test InsertSpanString merges spans correctly
1903 * @tc.type: FUNC
1904 */
1905 HWTEST_F(SpanStringTestNg, SpanString026, TestSize.Level1)
1906 {
1907 auto target = AceType::MakeRefPtr<MutableSpanString>(u"0123");
1908 auto source = AceType::MakeRefPtr<MutableSpanString>(u"abc");
1909 TextBackgroundStyle style;
1910 style.backgroundColor = Color::RED;
1911 source->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 0, 3));
1912
1913 target->InsertSpanString(2, source); // 在位置2插入"abc"
1914
1915 auto spans = target->GetSpans(2, 3); // 检查插入的span是否在2-5
1916 EXPECT_EQ(spans.size(), 1);
1917 EXPECT_EQ(spans.front()->GetEndIndex(), 5);
1918 }
1919
1920 /**
1921 * @tc.name: SpanStringTest027
1922 * @tc.desc: Test AppendSpanString adds to the end
1923 * @tc.type: FUNC
1924 */
1925 HWTEST_F(SpanStringTestNg, SpanString027, TestSize.Level1)
1926 {
1927 auto target = AceType::MakeRefPtr<MutableSpanString>(u"start");
1928 auto source = AceType::MakeRefPtr<MutableSpanString>(u"end");
1929 TextBackgroundStyle style;
1930 style.backgroundColor = Color::TRANSPARENT;
1931 source->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 0, 3));
1932
1933 target->AppendSpanString(source);
1934
1935 auto spans = target->GetSpans(5, 3); // 检查追加后的span在5-8
1936 EXPECT_EQ(spans.size(), 1);
1937 EXPECT_EQ(spans.front()->GetEndIndex(), 8);
1938 }
1939
1940 /**
1941 * @tc.name: SpanStringTest028
1942 * @tc.desc: Test span adjustment when inserting at text beginning
1943 * @tc.type: FUNC
1944 */
1945 HWTEST_F(SpanStringTestNg, SpanString028, TestSize.Level1)
1946 {
1947 // 初始化10字符文本+span覆盖5-8区间
1948 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"0123456789");
1949 TextBackgroundStyle style;
1950 style.backgroundColor = Color::FromRGB(255, 0, 0);
1951 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 5, 8));
1952
1953 // 在文本开头插入3个字符
1954 spanString->InsertString(0, u"ABC");
1955
1956 // 验证span位置偏移
1957 auto spans = spanString->GetSpans(8, 3); // 原5-8应变为8-11
1958 EXPECT_EQ(spans.size(), 1);
1959 if (!spans.empty()) {
1960 auto span = AceType::DynamicCast<BackgroundColorSpan>(spans.front());
1961 EXPECT_EQ(span->GetStartIndex(), 8);
1962 EXPECT_EQ(span->GetEndIndex(), 11);
1963 }
1964
1965 // 验证原始文本内容
1966 EXPECT_EQ(spanString->GetString(), "ABC0123456789");
1967 }
1968
1969 /**
1970 * @tc.name: SpanStringTest029
1971 * @tc.desc: Test overlapping spans after multiple insertions
1972 * @tc.type: FUNC
1973 */
1974 HWTEST_F(SpanStringTestNg, SpanString029, TestSize.Level1)
1975 {
1976 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"base text");
1977
1978 // 添加三个重叠span
1979 TextBackgroundStyle redStyle, blueStyle, greenStyle;
1980 redStyle.backgroundColor = Color::RED;
1981 blueStyle.backgroundColor = Color::BLUE;
1982 greenStyle.backgroundColor = Color::GREEN;
1983
1984 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(redStyle, 2, 6)); // 覆盖2-6
1985 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(blueStyle, 4, 8)); // 覆盖4-8
1986 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(greenStyle, 0, 3)); // 覆盖0-3
1987
1988 // 在位置5插入3个字符
1989 spanString->InsertString(5, u"XYZ");
1990
1991 // 验证span位置调整
1992 auto spans = spanString->GetSpans(0, spanString->GetLength());
1993 EXPECT_EQ(spans.size(), 3); // 应保持三个span
1994
1995 auto frontSpan = AceType::DynamicCast<BackgroundColorSpan>(spans.front());
1996 EXPECT_EQ(frontSpan->GetStartIndex(), 0);
1997 EXPECT_EQ(frontSpan->GetEndIndex(), 3);
1998
1999
2000 auto midSpan = AceType::DynamicCast<BackgroundColorSpan>(*(std::next(spans.begin())));
2001 EXPECT_EQ(midSpan->GetStartIndex(), 3);
2002 EXPECT_EQ(midSpan->GetEndIndex(), 4);
2003
2004 auto lastSpan = AceType::DynamicCast<BackgroundColorSpan>(spans.back());
2005 EXPECT_EQ(lastSpan->GetStartIndex(), 4);
2006 EXPECT_EQ(lastSpan->GetEndIndex(), 11);
2007 }
2008
2009 /**
2010 * @tc.name: SpanStringTest030
2011 * @tc.desc: Test span removal with partial overlap
2012 * @tc.type: FUNC
2013 */
2014 HWTEST_F(SpanStringTestNg, SpanString030, TestSize.Level1)
2015 {
2016 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"abcdefghijklmn");
2017 TextBackgroundStyle style;
2018 style.backgroundColor = Color::FromARGB(255, 100, 150, 200);
2019
2020 // 添加两个相邻span
2021 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 3, 7)); // span1:3-7
2022 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 7, 10)); // span2:7-10
2023
2024 // 删除6-9区间的字符(影响两个span)
2025 spanString->RemoveString(6, 3); // 删除位置6的3字符(字符6,7,8)
2026
2027 // 验证span调整
2028 auto spans = spanString->GetSpans(0, spanString->GetLength());
2029 EXPECT_EQ(spans.size(), 2);
2030
2031 // span1调整后:3-6(原3-7,删除位置6导致结束变为6)
2032 auto firstSpan = AceType::DynamicCast<BackgroundColorSpan>(spans.front());
2033 EXPECT_EQ(firstSpan->GetStartIndex(), 3);
2034 EXPECT_EQ(firstSpan->GetEndIndex(), 6);
2035
2036 // span2调整后:6-7(原7-10,删除3字符后位置变为7-3=4 → 7→4, 10→7)
2037 auto secondSpan = AceType::DynamicCast<BackgroundColorSpan>(spans.back());
2038 EXPECT_EQ(secondSpan->GetStartIndex(), 6); // 7 - (6 <= pos <9被删除)
2039 EXPECT_EQ(secondSpan->GetEndIndex(), 7); // 10 - 3 =7
2040 }
2041
2042 /**
2043 * @tc.name: SpanStringTest031
2044 * @tc.desc: Test complex span replacement scenarios
2045 * @tc.type: FUNC
2046 */
2047 HWTEST_F(SpanStringTestNg, SpanString031, TestSize.Level1)
2048 {
2049 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"Hello World");
2050
2051 // 创建三种样式
2052 TextBackgroundStyle styleA, styleB, styleC;
2053 styleA.backgroundColor = Color(0xFFFF0000); // ARGB
2054 styleB.backgroundColor = Color(0xFF00FF00);
2055 styleC.backgroundColor = Color(0xFF0000FF);
2056
2057 // 添加交错span
2058 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(styleA, 0, 5)); // Hello
2059 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(styleB, 3, 8)); // lo Wo
2060 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(styleC, 6, 11)); // World
2061
2062 // 替换4-6区间的文本为"XXX"(3字符)
2063 spanString->ReplaceString(4, 2, u"XXX");
2064
2065 // 验证文本内容
2066 EXPECT_EQ(spanString->GetString(), "HellXXXWorld");
2067
2068 // 验证span调整(总长度增加1)
2069 auto spans = spanString->GetSpans(0, spanString->GetLength());
2070 EXPECT_EQ(spans.size(), 3);
2071
2072 auto spanA = AceType::DynamicCast<BackgroundColorSpan>(spans.front());
2073 EXPECT_EQ(spanA->GetStartIndex(), 0);
2074 EXPECT_EQ(spanA->GetEndIndex(), 3);
2075
2076 auto spanB = AceType::DynamicCast<BackgroundColorSpan>(*(std::next(spans.begin())));
2077 EXPECT_EQ(spanB->GetStartIndex(), 3);
2078 EXPECT_EQ(spanB->GetEndIndex(), 7);
2079
2080 auto spanC = AceType::DynamicCast<BackgroundColorSpan>(spans.back());
2081 EXPECT_EQ(spanC->GetStartIndex(), 7);
2082 EXPECT_EQ(spanC->GetEndIndex(), 12);
2083 }
2084
2085 /**
2086 * @tc.name: SpanStringTest032
2087 * @tc.desc: Test inserting at span start boundary
2088 * @tc.type: FUNC
2089 */
2090 HWTEST_F(SpanStringTestNg, SpanString032, TestSize.Level1)
2091 {
2092 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"ABCDEFGHIJ");
2093 TextBackgroundStyle style;
2094 style.backgroundColor = Color::BLUE;
2095 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 3, 7));
2096
2097 // 在span起始位置前插入2字符
2098 spanString->InsertString(3, u"XY");
2099
2100 auto spans = spanString->GetSpans(5, 4); // 原3-7变为5-9
2101 EXPECT_EQ(spans.size(), 1);
2102 EXPECT_EQ(spans.front()->GetStartIndex(), 5);
2103 EXPECT_EQ(spans.front()->GetEndIndex(), 9);
2104 }
2105
2106 /**
2107 * @tc.name: SpanStringTest033
2108 * @tc.desc: Test removing entire span coverage
2109 * @tc.type: FUNC
2110 */
2111 HWTEST_F(SpanStringTestNg, SpanString033, TestSize.Level1)
2112 {
2113 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"1234567890");
2114 TextBackgroundStyle style;
2115 style.backgroundColor = Color::GREEN;
2116 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(style, 2, 6));
2117
2118 // 删除完全覆盖span的区域
2119 spanString->RemoveString(2, 4);
2120
2121 auto spans = spanString->GetSpans(2, 4);
2122 EXPECT_TRUE(spans.empty());
2123 }
2124
2125 /**
2126 * @tc.name: SpanStringTest034
2127 * @tc.desc: Test replacing span with larger range
2128 * @tc.type: FUNC
2129 */
2130 HWTEST_F(SpanStringTestNg, SpanString034, TestSize.Level1)
2131 {
2132 auto spanString = AceType::MakeRefPtr<MutableSpanString>(u"TestString");
2133 TextBackgroundStyle oldStyle, newStyle;
2134 oldStyle.backgroundColor = Color::RED;
2135 newStyle.backgroundColor = Color::BLUE;
2136 spanString->AddSpan(AceType::MakeRefPtr<BackgroundColorSpan>(oldStyle, 1, 4));
2137
2138 // 替换span为更大范围
2139 auto newSpan = AceType::MakeRefPtr<BackgroundColorSpan>(newStyle, 0, 5);
2140 spanString->ReplaceSpan(1, 3, newSpan);
2141
2142 auto spans = spanString->GetSpans(0, 5);
2143 EXPECT_EQ(spans.size(), 1);
2144 EXPECT_EQ(AceType::DynamicCast<BackgroundColorSpan>(spans.front())->GetBackgroundColor().backgroundColor.value(),
2145 Color::BLUE);
2146 }
2147
2148 /**
2149 * @tc.name: Tlv001
2150 * @tc.desc: Test basic function of TLV
2151 * @tc.type: FUNC
2152 */
2153 HWTEST_F(SpanStringTestNg, Tlv001, TestSize.Level1)
2154 {
2155 std::vector<uint8_t> buffer;
2156 std::vector<std::string> writeFontFamily = { "f1", "f2" };
2157 std::vector<uint8_t> result = { 0x25, 0x2, 0x20, 0x2, 0x66, 0x31, 0x20, 0x2, 0x66, 0x32 };
2158 TLVUtil::WriteFontFamily(buffer, writeFontFamily);
2159 EXPECT_TRUE(buffer == result);
2160
2161 int32_t cursor = 0;
2162 std::vector<std::string> readFontFamily = TLVUtil::ReadFontFamily(buffer, cursor);
2163 EXPECT_TRUE(writeFontFamily == readFontFamily);
2164 buffer.clear();
2165 readFontFamily.clear();
2166 cursor = 0;
2167 readFontFamily = TLVUtil::ReadFontFamily(buffer, cursor);
2168 EXPECT_TRUE(readFontFamily.empty());
2169 }
2170
2171 /**
2172 * @tc.name: Tlv002
2173 * @tc.desc: Test basic function of TLV
2174 * @tc.type: FUNC
2175 */
2176 HWTEST_F(SpanStringTestNg, Tlv002, TestSize.Level1)
2177 {
2178 std::vector<uint8_t> buffer;
2179 Shadow textShadow1;
2180 textShadow1.SetBlurRadius(2.0);
2181 textShadow1.SetColor(Color::BLACK);
2182 textShadow1.SetOffsetX(8.0);
2183 textShadow1.SetOffsetY(8.0);
2184 std::vector<uint8_t> result = { 0x23, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x22, 0xff, 0x0, 0x0, 0x0, 0x0,
2185 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40 };
2186 TLVUtil::WriteTextShadow(buffer, textShadow1);
2187 EXPECT_TRUE(buffer == result);
2188
2189 int32_t cursor = 0;
2190 Shadow readShadow = TLVUtil::ReadTextShadow(buffer, cursor);
2191 EXPECT_TRUE(textShadow1 == readShadow);
2192 buffer.clear();
2193 Shadow errShadow = TLVUtil::ReadTextShadow(buffer, cursor);
2194 EXPECT_FALSE(textShadow1 == errShadow);
2195
2196 std::vector<Shadow> writeShadows = { textShadow1 };
2197 std::vector<uint8_t> result2 = { 0x26, 0x1, 0x23, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x22, 0xff, 0x0,
2198 0x0, 0x0, 0x0, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40 };
2199 buffer.clear();
2200 TLVUtil::WriteTextShadows(buffer, writeShadows);
2201 EXPECT_TRUE(buffer == result2);
2202
2203 cursor = 0;
2204 std::vector<Shadow> readShadows = TLVUtil::ReadTextShadows(buffer, cursor);
2205 EXPECT_TRUE(writeShadows == readShadows);
2206 buffer.clear();
2207 cursor = 0;
2208 std::vector<Shadow> errShadows = TLVUtil::ReadTextShadows(buffer, cursor);
2209 EXPECT_TRUE(errShadows.empty());
2210 }
2211
2212 /**
2213 * @tc.name: Tlv003
2214 * @tc.desc: Test basic function of TLV
2215 * @tc.type: FUNC
2216 */
2217 HWTEST_F(SpanStringTestNg, Tlv003, TestSize.Level1)
2218 {
2219 std::vector<uint8_t> buffer;
2220 std::list<std::pair<std::string, int32_t>> writeFontFeature = { { "f1", 1 }, { "f2", 2 } };
2221 std::vector<uint8_t> result = { 0x29, 0x2, 0x20, 0x2, 0x66, 0x31, 0x1, 0x20, 0x2, 0x66, 0x32, 0x2 };
2222 TLVUtil::WriteFontFeature(buffer, writeFontFeature);
2223 EXPECT_TRUE(buffer == result);
2224
2225 int32_t cursor = 0;
2226 std::list<std::pair<std::string, int32_t>> readFontFeature = TLVUtil::ReadFontFeature(buffer, cursor);
2227 EXPECT_TRUE(writeFontFeature == readFontFeature);
2228 buffer.clear();
2229 readFontFeature.clear();
2230 cursor = 0;
2231 readFontFeature = TLVUtil::ReadFontFeature(buffer, cursor);
2232 EXPECT_TRUE(readFontFeature.empty());
2233 }
2234
2235 /**
2236 * @tc.name: Tlv004
2237 * @tc.desc: Test basic function of TLV
2238 * @tc.type: FUNC
2239 */
2240 HWTEST_F(SpanStringTestNg, Tlv004, TestSize.Level1)
2241 {
2242 std::vector<uint8_t> buffer;
2243 NG::BorderRadiusProperty writeBorderRadiusProperty;
2244 writeBorderRadiusProperty.SetRadius(2.0_vp);
2245 std::vector<uint8_t> result = { 0x27, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21, 0x0,
2246 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21,
2247 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1 };
2248 TLVUtil::WriteBorderRadiusProperty(buffer, writeBorderRadiusProperty);
2249 EXPECT_TRUE(buffer == result);
2250
2251 int32_t cursor = 0;
2252 NG::BorderRadiusProperty readBorderRadiusProperty = TLVUtil::ReadBorderRadiusProperty(buffer, cursor);
2253 EXPECT_TRUE(writeBorderRadiusProperty == readBorderRadiusProperty);
2254 buffer.clear();
2255 cursor = 0;
2256 readBorderRadiusProperty = TLVUtil::ReadBorderRadiusProperty(buffer, cursor);
2257 EXPECT_FALSE(writeBorderRadiusProperty == readBorderRadiusProperty);
2258 }
2259
2260 /**
2261 * @tc.name: Tlv005
2262 * @tc.desc: Test basic function of TLV
2263 * @tc.type: FUNC
2264 */
2265 HWTEST_F(SpanStringTestNg, Tlv005, TestSize.Level1)
2266 {
2267 std::vector<uint8_t> buffer;
2268 RefPtr<Ace::PixelMap> writePixelMap = Ace::PixelMap::CreatePixelMap(nullptr);
2269 std::vector<uint8_t> result = { 0x28, 0x0 };
2270 TLVUtil::WritePixelMap(buffer, writePixelMap);
2271 EXPECT_TRUE(buffer == result);
2272
2273 int32_t cursor = 0;
2274 RefPtr<Ace::PixelMap> readPixelMap = TLVUtil::ReadPixelMap(buffer, cursor);
2275 EXPECT_FALSE(writePixelMap == readPixelMap);
2276 buffer.clear();
2277 cursor = 0;
2278 readPixelMap = TLVUtil::ReadPixelMap(buffer, cursor);
2279 EXPECT_FALSE(writePixelMap == readPixelMap);
2280 }
2281
2282 /**
2283 * @tc.name: Tlv006
2284 * @tc.desc: Test basic function of TLV
2285 * @tc.type: FUNC
2286 */
2287 HWTEST_F(SpanStringTestNg, Tlv006, TestSize.Level1)
2288 {
2289 std::vector<uint8_t> buffer;
2290 Dimension dim(8);
2291 CalcDimension writeCalcDimension = CalcDimension(dim);
2292 std::vector<uint8_t> result = { 0x2a, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40, 0x0 };
2293 TLVUtil::WriteCalcDimension(buffer, writeCalcDimension);
2294 EXPECT_TRUE(buffer == result);
2295
2296 int32_t cursor = 0;
2297 CalcDimension readCalcDimension = TLVUtil::ReadCalcDimension(buffer, cursor);
2298 EXPECT_TRUE(writeCalcDimension == readCalcDimension);
2299 buffer.clear();
2300 cursor = 0;
2301 readCalcDimension = TLVUtil::ReadCalcDimension(buffer, cursor);
2302 EXPECT_FALSE(writeCalcDimension == readCalcDimension);
2303 }
2304
2305 /**
2306 * @tc.name: Tlv007
2307 * @tc.desc: Test basic function of TLV
2308 * @tc.type: FUNC
2309 */
2310 HWTEST_F(SpanStringTestNg, Tlv007, TestSize.Level1)
2311 {
2312 std::vector<uint8_t> buffer;
2313 NG::CalcLength writeCalcLength(8);
2314 std::vector<uint8_t> result = { 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40, 0x0 };
2315 TLVUtil::WriteCalcLength(buffer, writeCalcLength);
2316 EXPECT_TRUE(buffer == result);
2317
2318 int32_t cursor = 0;
2319 NG::CalcLength readCalcLength = TLVUtil::ReadCalcLength(buffer, cursor);
2320 EXPECT_TRUE(writeCalcLength == readCalcLength);
2321 buffer.clear();
2322 cursor = 0;
2323 readCalcLength = TLVUtil::ReadCalcLength(buffer, cursor);
2324 EXPECT_FALSE(writeCalcLength == readCalcLength);
2325 }
2326
2327 /**
2328 * @tc.name: Tlv008
2329 * @tc.desc: Test basic function of TLV
2330 * @tc.type: FUNC
2331 */
2332 HWTEST_F(SpanStringTestNg, Tlv008, TestSize.Level1)
2333 {
2334 std::vector<uint8_t> buffer;
2335 ImageSpanSize writeImageSpanSize { .width = 60.0_vp, .height = 60.0_vp };
2336 std::vector<uint8_t> result = { 0x42, 0x43, 0x2a, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x40, 0x1, 0x44,
2337 0x2a, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x40, 0x1, 0x45 };
2338 TLVUtil::WriteImageSpanSize(buffer, writeImageSpanSize);
2339 EXPECT_TRUE(buffer == result);
2340
2341 int32_t cursor = 0;
2342 ImageSpanSize readImageSpanSize = TLVUtil::ReadImageSpanSize(buffer, cursor);
2343 EXPECT_TRUE(writeImageSpanSize == readImageSpanSize);
2344 buffer.clear();
2345 cursor = 0;
2346 readImageSpanSize = TLVUtil::ReadImageSpanSize(buffer, cursor);
2347 EXPECT_FALSE(writeImageSpanSize == readImageSpanSize);
2348 }
2349
2350 /**
2351 * @tc.name: Tlv009
2352 * @tc.desc: Test basic function of TLV
2353 * @tc.type: FUNC
2354 */
2355 HWTEST_F(SpanStringTestNg, Tlv009, TestSize.Level1)
2356 {
2357 std::vector<uint8_t> buffer;
2358 NG::PaddingProperty writePaddingProperty;
2359 writePaddingProperty.left = CalcLength(5);
2360 writePaddingProperty.right = CalcLength(5);
2361 writePaddingProperty.top = CalcLength(8);
2362 writePaddingProperty.bottom = CalcLength(8);
2363 std::vector<uint8_t> result = { 0x46, 0x49, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x40,
2364 0x0, 0x4a, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x40, 0x0, 0x47, 0x2b, 0x20, 0x0,
2365 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x40, 0x0, 0x48, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0,
2366 0x0, 0x0, 0x0, 0x20, 0x40, 0x0, 0x4b };
2367 TLVUtil::WritePaddingProperty(buffer, writePaddingProperty);
2368 EXPECT_TRUE(buffer == result);
2369
2370 int32_t cursor = 0;
2371 NG::PaddingProperty readPaddingProperty = TLVUtil::ReadPaddingProperty(buffer, cursor);
2372 EXPECT_TRUE(writePaddingProperty == readPaddingProperty);
2373 buffer.clear();
2374 cursor = 0;
2375 readPaddingProperty = TLVUtil::ReadPaddingProperty(buffer, cursor);
2376 EXPECT_FALSE(writePaddingProperty == readPaddingProperty);
2377 }
2378
2379 /**
2380 * @tc.name: Tlv010
2381 * @tc.desc: Test basic function of TLV
2382 * @tc.type: FUNC
2383 */
2384 HWTEST_F(SpanStringTestNg, Tlv010, TestSize.Level1)
2385 {
2386 std::vector<uint8_t> buffer;
2387 BorderRadiusProperty borderRadius;
2388 borderRadius.SetRadius(2.0_vp);
2389 MarginProperty margins;
2390 margins.SetEdges(CalcLength(10.0));
2391 PaddingProperty paddings;
2392 paddings.SetEdges(CalcLength(5.0));
2393 ImageSpanAttribute writeImageSpanAttribute { .paddingProp = paddings,
2394 .marginProp = margins,
2395 .borderRadius = borderRadius,
2396 .objectFit = ImageFit::COVER,
2397 .verticalAlign = VerticalAlign::BOTTOM };
2398 std::vector<uint8_t> result = { 0x3a, 0x3c, 0x2c, 0x3, 0x3d, 0x2d, 0x2, 0x3e, 0x46, 0x49, 0x2b, 0x20, 0x0, 0x24,
2399 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x40, 0x0, 0x4a, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0,
2400 0x0, 0x24, 0x40, 0x0, 0x47, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x40, 0x0, 0x48,
2401 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x40, 0x0, 0x4b, 0x3f, 0x27, 0x24, 0x21, 0x0,
2402 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21,
2403 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x40,
2404 0x46, 0x49, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x40, 0x0, 0x4a, 0x2b, 0x20, 0x0,
2405 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x40, 0x0, 0x47, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0,
2406 0x0, 0x0, 0x0, 0x14, 0x40, 0x0, 0x48, 0x2b, 0x20, 0x0, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x40,
2407 0x0, 0x4b, 0x41 };
2408 TLVUtil::WriteImageSpanAttribute(buffer, writeImageSpanAttribute);
2409 EXPECT_TRUE(buffer == result);
2410
2411 int32_t cursor = 0;
2412 ImageSpanAttribute readImageSpanAttribute = TLVUtil::ReadImageSpanAttribute(buffer, cursor);
2413 EXPECT_TRUE(writeImageSpanAttribute == readImageSpanAttribute);
2414 buffer.clear();
2415 cursor = 0;
2416 readImageSpanAttribute = TLVUtil::ReadImageSpanAttribute(buffer, cursor);
2417 EXPECT_FALSE(writeImageSpanAttribute == readImageSpanAttribute);
2418 }
2419
2420 /**
2421 * @tc.name: Tlv011
2422 * @tc.desc: Test basic function of TLV
2423 * @tc.type: FUNC
2424 */
2425 HWTEST_F(SpanStringTestNg, Tlv011, TestSize.Level1)
2426 {
2427 std::vector<uint8_t> buffer;
2428 NG::LeadingMargin writeLeadingMargin;
2429 writeLeadingMargin.size = LeadingMarginSize(Dimension(12.0), Dimension(48.0));
2430 std::vector<uint8_t> result = { 0x4c, 0x24, 0x21, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x28, 0x40, 0x0, 0x24, 0x21, 0x0,
2431 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x40, 0x0, 0x4e };
2432 TLVUtil::WriteLeadingMargin(buffer, writeLeadingMargin);
2433 EXPECT_TRUE(buffer == result);
2434
2435 int32_t cursor = 0;
2436 NG::LeadingMargin readLeadingMargin = TLVUtil::ReadLeadingMargin(buffer, cursor);
2437 EXPECT_TRUE(writeLeadingMargin == readLeadingMargin);
2438 buffer.clear();
2439 cursor = 0;
2440 readLeadingMargin = TLVUtil::ReadLeadingMargin(buffer, cursor);
2441 EXPECT_FALSE(writeLeadingMargin == readLeadingMargin);
2442 }
2443
2444 /**
2445 * @tc.name: GetSpanResultObject001
2446 * @tc.desc: Test GetSpanResultObject
2447 * @tc.type: FUNC
2448 */
2449 HWTEST_F(SpanStringTestNg, GetSpanResultObject001, TestSize.Level1)
2450 {
2451 auto customSpanItem = AceType::MakeRefPtr<NG::CustomSpanItem>();
2452 ASSERT_NE(customSpanItem, nullptr);
2453 customSpanItem->interval.first = 1;
2454 customSpanItem->interval.second = 2;
2455 auto resultObject = customSpanItem->GetSpanResultObject(0, 3);
2456 EXPECT_TRUE(resultObject.isInit);
2457 }
2458
2459 /**
2460 * @tc.name: GetSpanResultObject002
2461 * @tc.desc: Test GetSpanResultObject
2462 * @tc.type: FUNC
2463 */
2464 HWTEST_F(SpanStringTestNg, GetSpanResultObject002, TestSize.Level1)
2465 {
2466 auto customSpanItem = AceType::MakeRefPtr<NG::CustomSpanItem>();
2467 ASSERT_NE(customSpanItem, nullptr);
2468 customSpanItem->interval.first = 1;
2469 customSpanItem->interval.second = 2;
2470 auto resultObject = customSpanItem->GetSpanResultObject(2, 3);
2471 EXPECT_FALSE(resultObject.isInit);
2472 }
2473
2474 /**
2475 * @tc.name: GetSpanResultObject003
2476 * @tc.desc: Test GetSpanResultObject
2477 * @tc.type: FUNC
2478 */
2479 HWTEST_F(SpanStringTestNg, GetSpanResultObject003, TestSize.Level1)
2480 {
2481 auto customSpanItem = AceType::MakeRefPtr<NG::CustomSpanItem>();
2482 ASSERT_NE(customSpanItem, nullptr);
2483 customSpanItem->interval.first = 1;
2484 customSpanItem->interval.second = 4;
2485 auto resultObject = customSpanItem->GetSpanResultObject(0, 3);
2486 EXPECT_FALSE(resultObject.isInit);
2487 }
2488 } // namespace OHOS::Ace::NG