• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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
16import systemLoad from '@ohos.resourceschedule.systemload';
17
18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
19
20export default function ThermalControlMgrTest() {
21    describe("ThermalControlMgrTest", function () {
22        beforeAll(function() {
23
24            /*
25             * @tc.setup: setup invoked before all testcases
26             */
27             console.info('beforeAll called')
28        })
29
30        afterAll(function() {
31
32            /*
33             * @tc.teardown: teardown invoked after all testcases
34             */
35             console.info('afterAll called')
36        })
37
38        beforeEach(function() {
39
40            /*
41             * @tc.setup: setup invoked before each testcases
42             */
43             console.info('beforeEach called')
44        })
45
46        afterEach(function() {
47
48            /*
49             * @tc.teardown: teardown invoked after each testcases
50             */
51             console.info('afterEach called')
52        })
53
54        /*
55         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_001
56         * @tc.name: ThermalControlMgrTest001
57         * @tc.desc: test request On successful
58         * @tc.size MEDIUM
59         * @tc.type Function
60         * @tc.level Level 0
61         * @tc.require
62         */
63        it("ThermalControlMgrTest001", 0, async function (done) {
64            console.info('----------------------ThermalControlMgrTest001---------------------------');
65            function onSystemLoadChange(res) {
66                console.info('ThermalControlMgrTest001 res is ' + res);
67            }
68
69            try {
70                systemLoad.on('systemLoadChange', onSystemLoadChange);
71                console.info('ThermalControlMgrTest001 callback successful');
72
73                expect(true).assertTure();
74
75            } catch (err) {
76                console.error('ThermalControlMgrTest001 err.code is ' + JSON.stringify(err.code));
77            }
78            done();
79        })
80
81        /*
82         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_002
83         * @tc.name: ThermalControlMgrTest002
84         * @tc.desc: test request Off successful
85         * @tc.size MEDIUM
86         * @tc.type Function
87         * @tc.level Level 0
88         * @tc.require
89         */
90        it("ThermalControlMgrTest002", 0, async function (done) {
91            console.info('----------------------ThermalControlMgrTest002---------------------------');
92            function onSystemLoadChange(res) {
93                console.info('ThermalControlMgrTest002 res is ' + res);
94            }
95
96            try {
97                systemLoad.off('systemLoadChange', onSystemLoadChange);
98                console.info('ThermalControlMgrTest002 callback successful');
99
100                expect(true).assertTure();
101            } catch (err) {
102                console.error('ThermalControlMgrTest002 err.code is ' + JSON.stringify(err.code));
103            }
104            done();
105        })
106
107        /*
108         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_003
109         * @tc.name: ThermalControlMgrTest003
110         * @tc.desc: test request getLevel successful
111         * @tc.size MEDIUM
112         * @tc.type Function
113         * @tc.level Level 0
114         * @tc.require
115         */
116        it("ThermalControlMgrTest003", 0, async function (done) {
117            console.info('----------------------ThermalControlMgrTest003---------------------------');
118            systemLoad.getLevel().then((res) => {
119                console.log('ThermalControlMgrTest003 promise res is ' + JSON.stringify(res));
120                let level = res
121
122                expect(level).assertLess(7);
123                done();
124            }).catch((err) => {
125                console.error('ThermalControlMgrTest003 err is ' + JSON.stringify(err));
126            })
127        })
128
129        /*
130         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_004
131         * @tc.name: ThermalControlMgrTest004
132         * @tc.desc: test SystemLoadLevel is LOW
133         * @tc.size MEDIUM
134         * @tc.type Function
135         * @tc.level Level 0
136         * @tc.require
137         */
138        it("ThermalControlMgrTest004", 0, async function (done) {
139            console.info('----------------------ThermalControlMgrTest004---------------------------');
140            let level = systemLoad.SystemLoadLevel.LOW
141
142            expect(level).assertEqual(0);
143            done();
144        })
145
146        /*
147         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_005
148         * @tc.name: ThermalControlMgrTest005
149         * @tc.desc: test SystemLoadLevel is NORMAL
150         * @tc.size MEDIUM
151         * @tc.type Function
152         * @tc.level Level 0
153         * @tc.require
154         */
155        it("ThermalControlMgrTest005", 0, async function (done) {
156            console.info('----------------------ThermalControlMgrTest005---------------------------');
157            let level = systemLoad.SystemLoadLevel.NORMAL
158
159            expect(level).assertEqual(1);
160            done();
161        })
162
163        /*
164         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_006
165         * @tc.name: ThermalControlMgrTest006
166         * @tc.desc: test SystemLoadLevel is MEDIUM
167         * @tc.size MEDIUM
168         * @tc.type Function
169         * @tc.level Level 0
170         * @tc.require
171         */
172        it("ThermalControlMgrTest006", 0, async function (done) {
173            console.info('----------------------ThermalControlMgrTest006---------------------------');
174            let level = systemLoad.SystemLoadLevel.MEDIUM
175
176            expect(level).assertEqual(2);
177            done();
178        })
179
180        /*
181         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_007
182         * @tc.name: ThermalControlMgrTest007
183         * @tc.desc: test SystemLoadLevel is HIGH
184         * @tc.size MEDIUM
185         * @tc.type Function
186         * @tc.level Level 0
187         * @tc.require
188         */
189        it("ThermalControlMgrTest007", 0, async function (done) {
190            console.info('----------------------ThermalControlMgrTest007---------------------------');
191            let level = systemLoad.SystemLoadLevel.HIGH
192
193            expect(level).assertEqual(3);
194            done();
195        })
196
197        /*
198         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_008
199         * @tc.name: ThermalControlMgrTest008
200         * @tc.desc: test SystemLoadLevel is OVERHEATED
201         * @tc.size MEDIUM
202         * @tc.type Function
203         * @tc.level Level 0
204         * @tc.require
205         */
206        it("ThermalControlMgrTest008", 0, async function (done) {
207            console.info('----------------------ThermalControlMgrTest008---------------------------');
208            let level = systemLoad.SystemLoadLevel.OVERHEATED
209
210            expect(level).assertEqual(4);
211            done();
212        })
213
214        /*
215         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_009
216         * @tc.name: ThermalControlMgrTest009
217         * @tc.desc: test SystemLoadLevel is WARNNING
218         * @tc.size MEDIUM
219         * @tc.type Function
220         * @tc.level Level 0
221         * @tc.require
222         */
223        it("ThermalControlMgrTest009", 0, async function (done) {
224            console.info('----------------------ThermalControlMgrTest009---------------------------');
225            let level = systemLoad.SystemLoadLevel.WARNING
226
227            expect(level).assertEqual(5);
228            done();
229        })
230
231        /*
232         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_010
233         * @tc.name: ThermalControlMgrTest010
234         * @tc.desc: test SystemLoadLevel is EMERGENCY
235         * @tc.size MEDIUM
236         * @tc.type Function
237         * @tc.level Level 0
238         * @tc.require
239         */
240        it("ThermalControlMgrTest010", 0, async function (done) {
241            console.info('----------------------ThermalControlMgrTest010---------------------------');
242            let level = systemLoad.SystemLoadLevel.EMERGENCY
243
244            expect(level).assertEqual(6);
245            done();
246        })
247
248        /*
249         * @tc.number:SUB_RESOURCESCHEDULE_THERMAL_CONTROL_XTS_011
250         * @tc.name: ThermalControlMgrTest011
251         * @tc.desc: test SystemLoadLevel is RSCAPTE
252         * @tc.size MEDIUM
253         * @tc.type Function
254         * @tc.level Level 0
255         * @tc.require
256         */
257        it("ThermalControlMgrTest011", 0, async function (done) {
258            console.info('----------------------ThermalControlMgrTest011---------------------------');
259            let level = systemLoad.SystemLoadLevel.ESCAPE
260
261            expect(level).assertEqual(7);
262            done();
263        })
264    })
265    }