1 /*
2 * Copyright (c) 2023 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 "service_test_common.h"
16 #include "sec_comp_base.h"
17
18 namespace OHOS {
19 namespace Security {
20 namespace SecurityComponent {
BuildLocationComponentJson(nlohmann::json & jsonComponent)21 void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent)
22 {
23 jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT;
24 jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
25 jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false;
26 jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
27 {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
28 {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
29 {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
30 {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
31 };
32 jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
33 { JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
34 { JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
35 { JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
36 { JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
37 };
38 nlohmann::json jsonPadding = nlohmann::json {
39 { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
40 { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
41 { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
42 { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
43 };
44
45 nlohmann::json jsonBorderRadius = nlohmann::json {
46 { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION },
47 { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION },
48 { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION },
49 { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION },
50 };
51
52 jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
53 { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
54 { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
55 { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
56 { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
57 { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius},
58 };
59
60 jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
61 { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
62 { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
63 { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
64 };
65
66 jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
67 { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
68 };
69 jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
70 { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
71 { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
72 { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
73 { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
74 { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
75 { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
76 { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
77 };
78 jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
79 { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION },
80 { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON },
81 { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
82 };
83 jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
84 jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0;
85 jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0;
86 jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
87 jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
88 }
89
BuildSaveComponentJson(nlohmann::json & jsonComponent)90 void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent)
91 {
92 jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT;
93 jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
94 jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false;
95 jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
96 {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
97 {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
98 {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
99 {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
100 };
101 jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
102 {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
103 {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
104 {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
105 {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
106 };
107 nlohmann::json jsonPadding = nlohmann::json {
108 { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
109 { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
110 { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
111 { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
112 };
113
114 nlohmann::json jsonBorderRadius = nlohmann::json {
115 { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION },
116 { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION },
117 { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION },
118 { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION },
119 };
120
121 jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
122 { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
123 { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
124 { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
125 { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
126 { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius},
127 };
128
129 jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
130 { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
131 { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
132 { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
133 };
134
135 jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
136 { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
137 };
138 jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
139 { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
140 { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
141 { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
142 { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
143 { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
144 { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
145 { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
146 };
147 jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
148 { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD },
149 { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON },
150 { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
151 };
152 jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
153 jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0;
154 jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0;
155 jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
156 jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
157 }
158
BuildPasteComponentJson(nlohmann::json & jsonComponent)159 void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent)
160 {
161 jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT;
162 jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
163 jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false;
164 jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
165 {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
166 {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
167 {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
168 {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
169 };
170 jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
171 {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
172 {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
173 {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
174 {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
175 };
176 nlohmann::json jsonPadding = nlohmann::json {
177 { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
178 { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
179 { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
180 { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
181 };
182
183 nlohmann::json jsonBorderRadius = nlohmann::json {
184 { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION },
185 { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION },
186 { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION },
187 { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION },
188 };
189
190 jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
191 { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
192 { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
193 { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
194 { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
195 { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius},
196 };
197
198 jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
199 { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
200 { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
201 { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
202 };
203
204 jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
205 { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
206 };
207 jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
208 { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
209 { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
210 { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
211 { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
212 { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
213 { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
214 { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
215 };
216 jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
217 { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE },
218 { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON },
219 { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
220 };
221 jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
222 jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0;
223 jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0;
224 jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
225 jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
226 }
227 } // namespace SecurityComponent
228 } // namespace Security
229 } // namespace OHOS
230