1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "test/unittest/adapter/ohos/capability/convert_test_tools.h"
16 using namespace testing;
17 using namespace testing::ext;
18 namespace OHOS::Ace::NG {
19
SetUpTestSuite()20 void HtmlConvertTestNg::SetUpTestSuite()
21 {
22 MockPipelineContext::SetUp();
23 }
24
TearDownTestSuite()25 void HtmlConvertTestNg::TearDownTestSuite()
26 {
27 MockPipelineContext::TearDown();
28 }
29
SetUp()30 void HtmlConvertTestNg::SetUp() {}
31
TearDown()32 void HtmlConvertTestNg::TearDown() {}
33
GetImageOption(const std::string & src)34 ImageSpanOptions HtmlConvertTestNg::GetImageOption(const std::string& src)
35 {
36 ImageSpanSize size { .width = 50.0_vp, .height = 50.0_vp };
37 BorderRadiusProperty borderRadius;
38 borderRadius.SetRadius(2.0_vp);
39 MarginProperty margins;
40 // margins len 10.0
41 margins.SetEdges(CalcLength(10.0));
42 PaddingProperty paddings;
43 // paddings len 5.0
44 paddings.SetEdges(CalcLength(5.0));
45 ImageSpanAttribute attr { .size = size,
46 .paddingProp = paddings,
47 .marginProp = margins,
48 .borderRadius = borderRadius,
49 .objectFit = ImageFit::COVER,
50 .verticalAlign = VerticalAlign::BOTTOM };
51 ImageSpanOptions option { .image = src, .imageAttribute = attr };
52 return option;
53 }
54
GetDefaultParagraphStyle()55 SpanParagraphStyle HtmlConvertTestNg::GetDefaultParagraphStyle()
56 {
57 SpanParagraphStyle spanParagraphStyle;
58 spanParagraphStyle.align = TextAlign::END;
59 // default max lines 4
60 spanParagraphStyle.maxLines = 4;
61 spanParagraphStyle.wordBreak = WordBreak::BREAK_ALL;
62 spanParagraphStyle.textOverflow = TextOverflow::ELLIPSIS;
63 // defalut textIndent 23
64 spanParagraphStyle.textIndent = Dimension(23.0_vp);
65 spanParagraphStyle.leadingMargin = LeadingMargin();
66 // default width 25.0 height 26.0
67 spanParagraphStyle.leadingMargin->size = LeadingMarginSize(Dimension(25.0_vp), Dimension(26.0));
68 return spanParagraphStyle;
69 }
70
IsSpanItemSame(std::list<RefPtr<NG::SpanItem>> src,std::list<RefPtr<NG::SpanItem>> other)71 bool HtmlConvertTestNg::IsSpanItemSame(std::list<RefPtr<NG::SpanItem>> src, std::list<RefPtr<NG::SpanItem>> other)
72 {
73 if (src.size() != other.size()) {
74 return false;
75 }
76
77 while (src.size() != 0) {
78 auto it = src.front();
79 auto otherIt = other.front();
80 if (it->interval.first != otherIt->interval.first || it->interval.second != otherIt->interval.second ||
81 it->content != otherIt->content) {
82 return false;
83 }
84 src.pop_front();
85 other.pop_front();
86 }
87 return true;
88 }
89
GetImageOption(const std::string & src,const Dimension & width,const Dimension & height,ImageFit fit,VerticalAlign align,const BorderRadiusProperty & borderRadius,const MarginProperty & margins,const PaddingProperty & paddings)90 ImageSpanOptions HtmlConvertTestNg::GetImageOption(
91 const std::string& src,
92 const Dimension& width,
93 const Dimension& height,
94 ImageFit fit,
95 VerticalAlign align,
96 const BorderRadiusProperty& borderRadius,
97 const MarginProperty& margins,
98 const PaddingProperty& paddings
99 )
100 {
101 ImageSpanSize size { width, height };
102
103 BorderRadiusProperty customBorderRadius = borderRadius;
104 MarginProperty customMargins = margins;
105 PaddingProperty customPaddings = paddings;
106
107 ImageSpanAttribute attr {
108 .size = size,
109 .paddingProp = customPaddings,
110 .marginProp = customMargins,
111 .borderRadius = customBorderRadius,
112 .objectFit = fit,
113 .verticalAlign = align
114 };
115
116 ImageSpanOptions option {
117 .image = src,
118 .imageAttribute = attr
119 };
120
121 return option;
122 }
123 };