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 
17 namespace OHOS {
18 namespace Security {
19 namespace SecurityComponent {
BuildLocationComponentJson(nlohmann::json & jsonComponent)20 void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent)
21 {
22     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT;
23     jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
24     jsonComponent[JsonTagConstants::JSON_RECT] =  nlohmann::json {
25         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
26         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
27         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
28         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
29     };
30     jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
31         { JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
32         { JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
33         { JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
34         { JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
35     };
36     nlohmann::json jsonPadding = nlohmann::json {
37         { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
38         { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
39         { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
40         { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
41     };
42 
43     jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
44         { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
45         { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
46         { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
47         { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
48     };
49 
50     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
51         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
52         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
53         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
54     };
55 
56     jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
57         { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
58     };
59     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
60         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
61         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
62         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
63         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
64         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
65         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
66         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
67     };
68     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
69         { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION },
70         { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON },
71         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
72     };
73     jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
74 }
75 
BuildSaveComponentJson(nlohmann::json & jsonComponent)76 void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent)
77 {
78     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT;
79     jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
80     jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
81         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
82         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
83         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
84         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
85     };
86     jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
87         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
88         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
89         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
90         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
91     };
92     nlohmann::json jsonPadding = nlohmann::json {
93         { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
94         { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
95         { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
96         { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
97     };
98 
99     jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
100         { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
101         { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
102         { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
103         { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
104     };
105 
106     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
107         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
108         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
109         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
110     };
111 
112     jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
113         { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
114     };
115     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
116         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
117         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
118         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
119         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
120         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
121         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
122         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
123     };
124     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
125         { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD },
126         { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON },
127         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
128     };
129     jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
130 }
131 
BuildPasteComponentJson(nlohmann::json & jsonComponent)132 void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent)
133 {
134     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT;
135     jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0;
136     jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json {
137         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
138         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
139         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
140         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
141     };
142     jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json {
143         {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE },
144         {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE },
145         {JsonTagConstants::JSON_RECT_WIDTH, ServiceTestCommon::TEST_COORDINATE },
146         {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE }
147     };
148     nlohmann::json jsonPadding = nlohmann::json {
149         { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION },
150         { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION },
151         { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION },
152         { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION },
153     };
154 
155     jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json {
156         { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
157         { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE },
158         { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE },
159         { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding },
160     };
161 
162     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
163         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
164         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE },
165         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
166     };
167 
168     jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json {
169         { JsonTagConstants::JSON_BORDER_WIDTH_TAG, ServiceTestCommon::TEST_SIZE },
170     };
171     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
172         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false },
173         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
174         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
175         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
176         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
177         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
178         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
179     };
180     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
181         { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE },
182         { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON },
183         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
184     };
185     jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0;
186 }
187 }  // namespace SecurityComponent
188 }  // namespace Security
189 }  // namespace OHOS
190