• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 app from '@system.app'
17import thermal from "@ohos.thermal"
18import ThermalLevel from "@ohos.thermal"
19import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
20
21describe('ThermalMgrInterfaceTest', function () {
22    console.log("*************Thermal API Test Begin*************");
23    test0();
24    test1();
25    test2();
26    test3();
27    test4();
28    test5();
29    test6();
30    test7();
31    test8();
32    test9();
33    test10();
34    test11();
35    test12();
36    test13();
37    test14();
38    test15();
39    console.log("*************Thermal API Test End*************");
40})
41
42function test0() {
43    const MSEC_1000 = 1000;
44
45    /* @tc.number thermal_manager_js_000
46     * @tc.name Thermal_000
47     * @tc.desc Thermal acquisition kit
48     */
49    it('Thermal_000', 0, async function (done) {
50        console.info("enter");
51        await new Promise((resolve, reject) => {
52            setTimeout(() => {
53                let cold = thermal.getThermalLevel();
54                console.info("cold level is: " + cold);
55                resolve();
56                done();
57            }, MSEC_1000 * 1);
58        })
59    })
60}
61
62function test1() {
63    const MSEC_1000 = 1000;
64
65    /* @tc.number thermal_manager_js_001
66     * @tc.name Thermal_001
67     * @tc.desc Thermal acquisition kit
68     */
69    it('Thermal_001', 0, async function (done) {
70        console.info("enter");
71        await new Promise((resolve, reject) => {
72            setTimeout(() => {
73                let normal = thermal.getThermalLevel();
74                console.info("normal level is: " + normal);
75                resolve();
76                done();
77            }, MSEC_1000 * 1);
78        })
79    })
80}
81
82function test2() {
83    const MSEC_1000 = 1000;
84
85    /* @tc.number thermal_manager_js_002
86     * @tc.name Thermal_002
87     * @tc.desc Thermal acquisition kit
88     */
89    it('Thermal_002', 0, async function (done) {
90        await new Promise((resolve, reject) => {
91            setTimeout(() => {
92                let warm = thermal.getThermalLevel();
93                console.info("warm level is: " + warm);
94                resolve();
95                done();
96            }, MSEC_1000 * 1);
97        })
98    })
99}
100
101function test3() {
102    const MSEC_1000 = 1000;
103
104    /* @tc.number thermal_manager_js_003
105     * @tc.name Thermal_003
106     * @tc.desc Thermal acquisition kit
107     */
108    it('Thermal_003', 0, async function (done) {
109        await new Promise((resolve, reject) => {
110            setTimeout(() => {
111                let hot = thermal.getThermalLevel();
112                console.info("hot level is: " + hot);
113                resolve();
114                done();
115            }, MSEC_1000 * 1);
116        })
117    })
118}
119
120function test4() {
121    const MSEC_1000 = 1000;
122
123    /* @tc.number thermal_manager_js_004
124     * @tc.name Thermal_004
125     * @tc.desc Thermal acquisition kit
126     */
127    it('Thermal_004', 0, async function (done) {
128        await new Promise((resolve, reject) => {
129            setTimeout(() => {
130                let overheated = thermal.getThermalLevel();
131                console.info("overheated level is: " + overheated);
132                resolve();
133                done();
134            }, MSEC_1000 * 1);
135        })
136    })
137}
138
139function test5() {
140    const MSEC_1000 = 1000;
141
142    /* @tc.number thermal_manager_js_005
143     * @tc.name Thermal_005
144     * @tc.desc Thermal acquisition kit
145     */
146    it('Thermal_005', 0, async function (done) {
147        await new Promise((resolve, reject) => {
148            setTimeout(() => {
149                let warning = thermal.getThermalLevel();
150                console.info("warning level is: " + warning);
151                resolve();
152                done();
153            }, MSEC_1000 * 1);
154        })
155    })
156}
157
158function test6() {
159    const MSEC_1000 = 1000;
160
161    /* @tc.number thermal_manager_js_006
162     * @tc.name Thermal_006
163     * @tc.desc Thermal acquisition kit
164     */
165    it('Thermal_006', 0, async function (done) {
166        await new Promise((resolve, reject) => {
167            setTimeout(() => {
168                let emergency = thermal.getThermalLevel();
169                console.info("emergency level is: " + emergency);
170                resolve();
171                done();
172            }, MSEC_1000 * 1);
173        })
174    })
175}
176
177function test7() {
178    const MSEC_1000 = 1000;
179
180    /* @tc.number thermal_manager_js_007
181     * @tc.name Thermal_007
182     * @tc.desc Thermal acquisition kit
183     */
184    it('Thermal_007', 0, async function (done) {
185        thermal.subscribeThermalLevel((cool) => {
186            console.info("warm level is: " + cool);
187            done();
188        })
189        await new Promise((resolve, reject) => {
190            setTimeout(() => {
191                thermal.unsubscribeThermalLevel(() => {
192                    console.info("unsubscribe successfully!");
193                });
194                resolve();
195            }, MSEC_1000 * 4);
196        })
197    })
198}
199
200function test8() {
201    const MSEC_1000 = 1000;
202
203    /* @tc.number thermal_manager_js_008
204     * @tc.name Thermal_008
205     * @tc.desc Thermal acquisition kit
206     */
207    it('Thermal_008', 0, async function (done) {
208        thermal.subscribeThermalLevel((warm) => {
209            console.info("warm level is: " + warm);
210            done();
211        })
212        await new Promise((resolve, reject) => {
213            setTimeout(() => {
214                thermal.unsubscribeThermalLevel(() => {
215                    console.info("unsubscribe successfully!");
216                });
217                resolve();
218            }, MSEC_1000 * 4);
219        })
220    })
221}
222
223function test9() {
224    const MSEC_1000 = 1000;
225
226    /* @tc.number thermal_manager_js_009
227     * @tc.name Thermal_009
228     * @tc.desc Thermal acquisition kit
229     */
230    it('Thermal_009', 0, async function (done) {
231        thermal.subscribeThermalLevel((hot) => {
232            console.info("hot level is: " + hot);
233            done();
234        })
235        await new Promise((resolve, reject) => {
236            setTimeout(() => {
237                thermal.unsubscribeThermalLevel(() => {
238                    console.info("unsubscribe successfully!");
239                });
240                resolve();
241            }, MSEC_1000 * 2);
242        })
243    })
244
245}
246
247function test10() {
248    const MSEC_1000 = 1000;
249
250    /* @tc.number thermal_manager_js_010
251     * @tc.name Thermal_010
252     * @tc.desc Thermal acquisition kit
253     */
254    it('Thermal_010', 0, async function (done) {
255        thermal.subscribeThermalLevel((overheated) => {
256            console.info("overheated level is: " + overheated);
257            done();
258        })
259        await new Promise((resolve, reject) => {
260            setTimeout(() => {
261                thermal.unsubscribeThermalLevel(() => {
262                    console.info("unsubscribe successfully!");
263                });
264                resolve();
265            }, MSEC_1000 * 2);
266        })
267    })
268}
269
270function test11() {
271    const MSEC_1000 = 1000;
272
273    /* @tc.number thermal_manager_js_011
274     * @tc.name Thermal_011
275     * @tc.desc Thermal acquisition kit
276     */
277    it('Thermal_011', 0, async function (done) {
278        thermal.subscribeThermalLevel((warning) => {
279            console.info("warning level is: " + warning);
280            done();
281        })
282        await new Promise((resolve, reject) => {
283            setTimeout(() => {
284                thermal.unsubscribeThermalLevel(() => {
285                    console.info("unsubscribe successfully!");
286                });
287                resolve();
288            }, MSEC_1000 * 4);
289        })
290    })
291}
292
293function test12() {
294    const MSEC_1000 = 1000;
295
296    /* @tc.number thermal_manager_js_012
297     * @tc.name Thermal_012
298     * @tc.desc Thermal acquisition kit
299     */
300    it('Thermal_012', 0, async function (done) {
301        thermal.subscribeThermalLevel((emergency) => {
302            console.info("emergency level is: " + emergency);
303            done();
304        })
305        await new Promise((resolve, reject) => {
306            setTimeout(() => {
307                thermal.unsubscribeThermalLevel(() => {
308                    console.info("unsubscribe successfully!");
309                });
310                resolve();
311            }, MSEC_1000 * 4);
312        })
313    })
314}
315
316function test13() {
317    const MSEC_1000 = 1000;
318
319    /* @tc.number thermal_manager_js_013
320     * @tc.name Thermal_013
321     * @tc.desc Thermal acquisition kit
322     */
323    it('Thermal_013', 0, async function (done) {
324        thermal.subscribeThermalLevel((normal) => {
325            console.info("normal level is: " + normal);
326            done();
327        })
328        await new Promise((resolve, reject) => {
329            setTimeout(() => {
330                thermal.unsubscribeThermalLevel(() => {
331                    console.info("unsubscribe successfully!");
332                });
333                resolve();
334            }, MSEC_1000 * 4);
335        })
336    })
337}
338
339function test14() {
340    const MSEC_1000 = 1000;
341
342    /* @tc.number thermal_manager_js_014
343     * @tc.name Thermal_014
344     * @tc.desc Thermal acquisition kit
345     */
346    it('Thermal_013', 0, async function (done) {
347        thermal.subscribeThermalLevel((cool) => {
348            console.info("cool level is: " + cool);
349            done();
350        })
351        await new Promise((resolve, reject) => {
352            setTimeout(() => {
353                thermal.unsubscribeThermalLevel(() => {
354                    console.info("unsubscribe successfully!");
355                });
356                resolve();
357            }, MSEC_1000 * 4);
358        })
359    })
360}
361
362function test15() {
363
364    /* @tc.number thermal_manager_js_015
365     * @tc.name Thermal_015
366     * @tc.desc Thermal acquisition kit
367     */
368    it('Thermal_015', 0, async function (done) {
369        thermal.subscribeThermalLevel((level) => {
370            console.info("level is: " + level);
371            expect(level >= thermal.ThermalLevel.COOL && level <= thermal.ThermalLevel.EMERGENCY).assertTrue();
372            done();
373        })
374        await new Promise((resolve, reject) => {
375            setTimeout(() => {
376                thermal.unsubscribeThermalLevel(() => {
377                    console.info("unsubscribe successfully!");
378                });
379                resolve();
380            }, MSEC_1000 * 4);
381        })
382    })
383}
384