• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef HGM_TEST_BASE_H
17 #define HGM_TEST_BASE_H
18 
19 #include <gtest/gtest.h>
20 #include <test_header.h>
21 
22 #include "hgm_core.h"
23 #include "xml_parser.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 const std::string TEST_XML_CONTENT = (R"(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28     <!-- Copyright (c) 2025 Device Co., Ltd.
29         Licensed under the Apache License, Version 2.0 (the "License");
30         you may not use this file except in compliance with the License.
31         You may obtain a copy of the License at
32 
33             http://www.apache.org/licenses/LICENSE-2.0
34 
35         Unless required by applicable law or agreed to in writing, software
36         distributed under the License is distributed on an "AS IS" BASIS,
37         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38         See the License for the specific language governing permissions and
39         limitations under the License.
40     -->
41     <HgmConfig version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
42     <Param name="default_refreshrate_mode" value="-1"/>
43     <Param name="p3_node_count_config" value="1"/>
44     <Param name="is_covered_surface_close_p3_config" value="1"/>
45     <Params name="refresh_rate_4settings">
46         <Setting name="-1" id="-1"/>
47         <Setting name="60" id="1"/>
48         <Setting name="120" id="2"/>
49     </Params>
50     <Params name="additional_touch_rate_config">
51         <Strategy name="aaa"/>
52     </Params>
53     <Params name="refreshRate_strategy_config">
54         <Strategy name="8" min="60" max="120" dynamicMode="1" pointerMode="1"/>
55         <Strategy name="12" min="120" max="120" dynamicMode="0"/>
56     </Params>
57     <Params name="refreshRate_virtual_display_config" switch="1">
58     </Params>
59     <Params name="safe_vote" switch="1">
60     </Params>
61     <Params name="screen_strategy_config">
62         <Strategy name="screen0_LTPO" type="LTPO-DEFAULT"/>
63     </Params>
64     <Params name="screen_config" type="LTPO-DEFAULT">
65         <Category name="supported_mode">
66         <Mode name="aaa" value="1 2 3"/>
67         <Mode name="bbb" value="1 2"/>
68         </Category>
69         <Setting id="-1" strategy="8">
70         <Category name="LTPO_config">
71             <Ltpo name="switch" value="1"/>
72             <Ltpo name="maxTE" value="360"/>
73             <Ltpo name="alignRate" value="100"/>
74             <Ltpo name="pipelineOffsetPulseNum" value="100"/>
75             <Ltpo name="adaptiveSync" value="0"/>
76             <Ltpo name="vBlankIdleCorrectSwitch" value="100"/>
77             <Ltpo name="lowRateToHighQuickSwitch" value="100"/>
78             <Ltpo name="xxx" value="100"/>
79         </Category>
80         <Category name="rs_animation_power_config">
81             <Setting name="aaa" value="60"/>
82         </Category>
83         <Category name="ui_power_config">
84             <Setting name="aaa" value="60"/>
85         </Category>
86         <Category name="component_power_config">
87             <Setting name="aaa" value="60"/>
88         </Category>
89         <Category name="property_animation_dynamic_settings">
90             <DynamicSettings name="aaa">
91                 <SpeedThresholds name="1" min="0" max="-1" preferred_fps="60"/>
92             </DynamicSettings>
93             <DynamicSettings name="invalid_preferred_fps">
94                 <SpeedThresholds name="1" min="0" max="-1"/>
95             </DynamicSettings>
96             <DynamicSettings name="invalid_max">
97                 <SpeedThresholds name="1" min="0"/>
98             </DynamicSettings>
99             <DynamicSettings name="invalid_min">
100                 <SpeedThresholds name="1"/>
101             </DynamicSettings>
102         </Category>
103         <Category name="ace_scene_dynamic_settings">
104             <DynamicSettings name="aaa">
105             <SpeedThresholds name="1" min="0" max="-1" preferred_fps="120"/>
106             </DynamicSettings>
107         </Category>
108         <Category name="small_size_property_animation_dynamic_settings" area="1000" length="1000">
109             <DynamicSettings name="aaa">
110             <SpeedThresholds name="1" min="0" max="-1" preferred_fps="60"/>
111             </DynamicSettings>
112         </Category>
113         <Category name="scene_list">
114             <Scene name="aaa" strategy="12" priority="1"/>
115         </Category>
116         <Category name="game_scene_list">
117             <Scene name="aaa" value="1"/>
118         </Category>
119         <Category name="anco_scene_list">
120             <Scene name="aaa" value="1"/>
121         </Category>
122         <Category name="app_list" multi_app_strategy="focus">
123             <App name="aaa" strategy="12"/>
124             <App name="bbb" nodeName="12"/>
125         </Category>
126         <Category name="app_types">
127             <App name="aaa" strategy="12"/>
128             <App name="111" strategy="12"/>
129             <App name="333" strategy="33"/>
130         </Category>
131         <Category name="app_page_url_config">
132             <Package name="com.company.pkg0">
133                 <Strategy name="pageName" strategy="5"/>
134             </Package>
135         </Category>
136         <Category name="performance_config">
137             <Ltpo name="pluseNum" value="1"/>
138             <Ltpo name="pipelineDelayModeEnable" value="1"/>
139         </Category>
140         <Category name="xxx">
141             <App name="aaa" strategy="12"/>
142         </Category>
143         </Setting>
144     </Params>
145     <Params name="rs_video_frame_rate_vote_config" switch="1">
146         <App name="aaa" value="1"/>
147     </Params>
148     <Params name="source_tuning_for_yuv420">
149         <App name="aaa" value="1"/>
150     </Params>
151     <Params name="vrate_control_config">
152         <Vrate name="aaa" value="1"/>
153     </Params>
154     <Params name="rs_solid_color_layer_config">
155         <App name="aaa" value="1"/>
156     </Params>
157     <Params name="hfbc_config">
158         <App name="aaa" value="1"/>
159     </Params>
160     <Params name="timeout_strategy_config">
161         <App name="aaa" value="1"/>
162     </Params>
163     <Params name="video_call_layer_config">
164         <App name="aaa" value="1"/>
165     </Params>
166     <Params name="xxx">
167         <App name="aaa" value="1"/>
168     </Params>
169     <InvalidParams/>
170     </HgmConfig>)");
171 
172 const std::string TEST_XML_CONTENT_1 = (R"(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
173     <!-- Copyright (c) 2025 Device Co., Ltd.
174         Licensed under the Apache License, Version 2.0 (the "License");
175         you may not use this file except in compliance with the License.
176         You may obtain a copy of the License at
177 
178             http://www.apache.org/licenses/LICENSE-2.0
179 
180         Unless required by applicable law or agreed to in writing, software
181         distributed under the License is distributed on an "AS IS" BASIS,
182         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183         See the License for the specific language governing permissions and
184         limitations under the License.
185     -->
186     <HgmConfig version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
187     <Param name="default_refreshrate_mode" value="-1"/>
188     <Param name="p3_node_count_config" value="1"/>
189     <Param name="is_covered_surface_close_p3_config" value="1"/>
190     <Params name="refresh_rate_4settings">
191         <Setting name="-1" id="-1"/>
192         <Setting name="60" id="1"/>
193         <Setting name="120" id="2"/>
194     </Params>
195     <Params name="refresh_rate_4settings" type="padmode">
196         <Setting name="-1" id="-1"/>
197         <Setting name="60" id="1"/>
198         <Setting name="120" id="2"/>
199         <Setting name="144" id="3"/>
200         <Setting name="155" id="testid"/>
201         <Setting name="testName" id="4"/>
202         <Setting name="testName" id="testid"/>
203         <Setting name="testName" id="testid"/>
204     </Params>
205     <Params name="refresh_rate_4settings" type="pcmode">
206         <Setting name="-1" id="-101"/>
207         <Setting name="60" id="101"/>
208         <Setting name="120" id="102"/>
209     </Params>
210     <Params name="refresh_rate_4settings" type="testmode0">
211         <Setting value="testName" name="testid"/>
212     </Params>
213     <Params name="refresh_rate_4settings" type="testmode_no_auto">
214         <Setting name="60" id="101"/>
215         <Setting name="120" id="102"/>
216     </Params>
217     <Params name="additional_touch_rate_config">
218         <Strategy name="aaa"/>
219     </Params>
220     <Params name="refreshRate_strategy_config">
221         <Strategy name="8" min="60" max="120" dynamicMode="1" pointerMode="1"/>
222         <Strategy name="12" min="120" max="120" dynamicMode="0"/>
223     </Params>
224     <Params name="refreshRate_virtual_display_config" switch="1">
225     </Params>
226     <Params name="safe_vote" switch="1">
227     </Params>
228     <Params name="screen_strategy_config">
229         <Strategy name="screen0_LTPO" type="LTPO-DEFAULT"/>
230     </Params>
231     <Params name="screen_config" type="LTPO-DEFAULT">
232         <Category name="supported_mode">
233         <Mode name="aaa" value="1 2 3"/>
234         <Mode name="bbb" value="1 2"/>
235         </Category>
236         <Setting id="-1" strategy="8">
237         <Category name="LTPO_config">
238             <Ltpo name="switch" value="1"/>
239             <Ltpo name="maxTE" value="360"/>
240             <Ltpo name="alignRate" value="100"/>
241             <Ltpo name="pipelineOffsetPulseNum" value="100"/>
242             <Ltpo name="adaptiveSync" value="0"/>
243             <Ltpo name="vBlankIdleCorrectSwitch" value="100"/>
244             <Ltpo name="lowRateToHighQuickSwitch" value="100"/>
245             <Ltpo name="xxx" value="100"/>
246         </Category>
247         <Category name="rs_animation_power_config">
248             <Setting name="aaa" value="60"/>
249         </Category>
250         <Category name="ui_power_config">
251             <Setting name="aaa" value="60"/>
252         </Category>
253         <Category name="component_power_config">
254             <Setting name="aaa" value="60"/>
255         </Category>
256         <Category name="property_animation_dynamic_settings">
257             <DynamicSettings name="aaa">
258             <SpeedThresholds name="1" min="0" max="-1" preferred_fps="60"/>
259             </DynamicSettings>
260         </Category>
261         <Category name="ace_scene_dynamic_settings">
262             <DynamicSettings name="aaa">
263             <SpeedThresholds name="1" min="0" max="-1" preferred_fps="120"/>
264             </DynamicSettings>
265         </Category>
266         <Category name="small_size_property_animation_dynamic_settings" area="100" length="100">
267             <DynamicSettings name="aaa">
268             <SpeedThresholds name="1" min="0" max="-1" preferred_fps="60"/>
269             </DynamicSettings>
270         </Category>
271         <Category name="scene_list">
272             <Scene name="aaa" strategy="12" priority="1"/>
273         </Category>
274         <Category name="game_scene_list">
275             <Scene name="aaa" value="1"/>
276         </Category>
277         <Category name="anco_scene_list">
278             <Scene name="aaa" value="1"/>
279         </Category>
280         <Category name="app_list" multi_app_strategy="focus">
281             <App name="aaa" strategy="12"/>
282             <App name="bbb" nodeName="12"/>
283         </Category>
284         <Category name="app_types">
285             <App name="aaa" strategy="12" />
286             <App name="111" strategy="12" />
287             <App name="333" strategy="33" />
288         </Category>
289         <Category name="app_page_url_config">
290             <App name="aaa" strategy="12" />
291         </Category>
292         <Category name="performance_config">
293             <Ltpo name="pluseNum" value="1" />
294             <Ltpo name="pipelineDelayModeEnable" value="1" />
295         </Category>
296         <Category name="xxx">
297             <App name="aaa" strategy="12" />
298         </Category>
299         </Setting>
300     </Params>
301     <Params name="rs_video_frame_rate_vote_config" switch="1">
302         <App name="aaa" value="1"/>
303     </Params>
304     <Params name="source_tuning_for_yuv420">
305         <App name="aaa" value="1"/>
306     </Params>
307     <Params name="vrate_control_config">
308         <Vrate name="aaa" value="1"/>
309     </Params>
310     <Params name="rs_solid_color_layer_config">
311         <App name="aaa" value="1"/>
312     </Params>
313     <Params name="hfbc_config">
314         <App name="aaa" value="1"/>
315     </Params>
316     <Params name="timeout_strategy_config">
317         <App name="aaa" value="1"/>
318     </Params>
319     <Params name="video_call_layer_config">
320         <App name="aaa" value="1"/>
321     </Params>
322     <Params name="xxx">
323         <App name="aaa" value="1"/>
324     </Params>
325     </HgmConfig>)");
326 
StringToXmlDoc(const std::string & xmlContent)327 inline xmlDoc* StringToXmlDoc(const std::string& xmlContent)
328 {
329     xmlDoc* docPtr = xmlReadMemory(xmlContent.c_str(), xmlContent.size(), nullptr, nullptr, 0);
330     return docPtr;
331 }
332 
333 class HgmTestBase : public testing::Test {
334 public:
335     ~HgmTestBase() = default;
336 
337     static void SetUpTestCase()
338     {
339         auto& hgmCore = HgmCore::Instance();
340         std::unique_ptr<XMLParser> parser = std::make_unique<XMLParser>();
341         parser->mParsedData_ = std::make_unique<PolicyConfigData>();
342         ASSERT_NE(parser->mParsedData_, nullptr);
343         parser->xmlDocument_ = StringToXmlDoc(TEST_XML_CONTENT);
344         ASSERT_NE(parser->xmlDocument_, nullptr);
345         parser->Parse();
346         hgmCore.mPolicyConfigData_ = parser->GetParsedData();
347         hgmCore.mParser_ = std::move(parser);
348         hgmCore.InitXmlConfig();
349     }
350     static void TearDownTestCase() {}
351     void SetUp() {}
352     void TearDown() {}
353 };
354 } // namespace Rosen
355 } // namespace OHOS
356 #endif // HGM_TEST_BASE_H
357