• 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'
20const MSEC_1000 = 1000;
21
22describe('appInfoTest_thermal4', function () {
23    console.log("*************Thermal API Test Begin*************");
24    test14();
25    test15();
26    test16();
27})
28
29function test14() {
30
31    /* @tc.number thermal_manager_js_014
32     * @tc.name Thermal_014
33     * @tc.desc Thermal acquisition kit
34     */
35    it('Thermal_014', 0, async function (done) {
36        console.info("enter");
37        await new Promise((resolve, reject) => {
38            setTimeout(() => {
39                let level = thermal.getThermalLevel();
40                console.info("level is: " + level);
41                expect(level >= 0 && level <= 6).assertTrue();
42                resolve();
43                done();
44            }, MSEC_1000 * 4);
45        })
46    })
47}
48
49function test15() {
50
51    /* @tc.number thermal_manager_js_015
52     * @tc.name Thermal_015
53     * @tc.desc Thermal acquisition kit
54     */
55    it('Thermal_015', 0, async function (done) {
56        thermal.subscribeThermalLevel((level) => {
57            console.info("level is: " + level);
58            expect(level >= 0 && level <= 6).assertTrue();
59            done();
60        })
61        await new Promise((resolve, reject) => {
62            setTimeout(() => {
63                thermal.unsubscribeThermalLevel(() => {
64                    console.info("unsubscribe successfully!");
65                });
66                resolve();
67            }, MSEC_1000 * 4);
68        })
69    })
70}
71
72function test16() {
73
74    /* @tc.number thermal_manager_js_013
75     * @tc.name Thermal_013
76     * @tc.desc Thermal acquisition kit
77     */
78    it('Thermal_016', 0, function () {
79        console.info("Thermal level is: " + thermal.ThermalLevel.COOL + thermal.ThermalLevel.NORMAL
80            + thermal.ThermalLevel.WARM + thermal.ThermalLevel.HOT + thermal.ThermalLevel.OVERHEATED
81            + thermal.ThermalLevel.WARNING + thermal.ThermalLevel.EMERGENCY);
82        expect(thermal.ThermalLevel.COOL == 0).assertTrue();
83        expect(thermal.ThermalLevel.NORMAL == 1).assertTrue();
84        expect(thermal.ThermalLevel.WARM == 2).assertTrue();
85        expect(thermal.ThermalLevel.HOT == 3).assertTrue();
86        expect(thermal.ThermalLevel.OVERHEATED == 4).assertTrue();
87        expect(thermal.ThermalLevel.WARNING == 5).assertTrue();
88        expect(thermal.ThermalLevel.EMERGENCY == 6).assertTrue();
89    })
90}