• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IS_ICON_EXCEEDED_TAG] = false;
87     jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false;
88     jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
89     jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
90     jsonComponent[JsonTagConstants::JSON_FOREGROUND_BLUR_RADIUS_TAG] = 0.0;
91     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = false;
92     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG] = false;
93     jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
94     jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
95 }
96 
BuildSaveComponentJson(nlohmann::json & jsonComponent)97 void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent)
98 {
99     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT;
100     jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
101     jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false;
102     jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
103         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
104         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
105         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
106         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
107     };
108     jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
109         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
110         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
111         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
112         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
113     };
114     nlohmann::json jsonPadding = nlohmann::json {
115         { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
116         { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
117         { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
118         { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
119     };
120 
121     nlohmann::json jsonBorderRadius = nlohmann::json {
122         { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION },
123         { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION },
124         { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION },
125         { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION },
126     };
127 
128     jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
129         { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
130         { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
131         { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
132         { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
133         { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius},
134     };
135 
136     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
137         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
138         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
139         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
140     };
141 
142     jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
143         { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
144     };
145     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
146         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
147         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
148         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
149         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
150         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
151         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
152         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
153     };
154     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
155         { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD },
156         { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON },
157         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
158     };
159     jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
160     jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0;
161     jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0;
162     jsonComponent[JsonTagConstants::JSON_IS_ICON_EXCEEDED_TAG] = false;
163     jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false;
164     jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
165     jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
166     jsonComponent[JsonTagConstants::JSON_FOREGROUND_BLUR_RADIUS_TAG] = 0.0;
167     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = false;
168     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG] = false;
169     jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
170     jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
171 }
172 
BuildPasteComponentJson(nlohmann::json & jsonComponent)173 void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent)
174 {
175     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT;
176     jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
177     jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false;
178     jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
179         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
180         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
181         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
182         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
183     };
184     jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
185         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
186         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
187         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
188         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
189     };
190     nlohmann::json jsonPadding = nlohmann::json {
191         { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
192         { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
193         { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
194         { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
195     };
196 
197     nlohmann::json jsonBorderRadius = nlohmann::json {
198         { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION },
199         { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION },
200         { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION },
201         { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION },
202     };
203 
204     jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
205         { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
206         { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
207         { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
208         { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
209         { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius},
210     };
211 
212     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
213         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
214         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
215         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
216     };
217 
218     jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
219         { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
220     };
221     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
222         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
223         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
224         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
225         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
226         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
227         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
228         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
229     };
230     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
231         { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE },
232         { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON },
233         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
234     };
235     jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
236     jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0;
237     jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0;
238     jsonComponent[JsonTagConstants::JSON_IS_ICON_EXCEEDED_TAG] = false;
239     jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false;
240     jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false;
241     jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0;
242     jsonComponent[JsonTagConstants::JSON_FOREGROUND_BLUR_RADIUS_TAG] = 0.0;
243     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = false;
244     jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG] = false;
245     jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
246     jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
247 }
248 }  // namespace SecurityComponent
249 }  // namespace Security
250 }  // namespace OHOS
251