• 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 */
15import commonEvent from '@ohos.commonEvent';
16import thermal from "@ohos.thermal"
17
18describe('appInfoTest_thermal1', function () {
19    console.log("*************Thermal commonEvent Test Begin*************");
20
21    /**
22     * @tc.number ThermalCommonEventTest_001
23     * @tc.name subscribe thermal level changed common event
24     * @tc.desc Thermal acquisition kit
25     */
26    it('ThermalCommonEventTest_001', 0, function (done) {
27        createSubscriber();
28        done();
29    })
30    console.log("*************Thermal commonEvent Test End*************");
31})
32
33function createSubscriber() {
34    let commonEventSubscribeInfo = {
35        events: [commonEvent.Support.COMMON_EVENT_THERMAL_LEVEL_CHANGED],
36    };
37    commonEvent.createSubscriber(commonEventSubscribeInfo)
38        .then(subscriber => {
39            console.info('createSubscriber success');
40            let mySubscriber = subscriber;
41            console.log(subscriber);
42
43            if (subscriber == "" || subscriber == undefined || subscriber == null) {
44                console.info("createSubscriber failed");
45            }
46            mySubscriber.getCode()
47                .then((data) => {
48                    console.info('Subscriber getCode success : ' + JSON.stringify(data));
49                }).catch((error) => {
50                    console.error('Subscriber getCode error because: ' + JSON.stringify(error));
51                })
52            mySubscriber.getData()
53                .then((data) => {
54                    console.info('Subscriber getData success : ' + JSON.stringify(data));
55                }).catch((error) => {
56                    console.error('Subscriber getData error because: ' + JSON.stringify(error));
57                })
58            console.info('subscribe begin ');
59
60            commonEvent.subscribe(mySubscriber, (error, commonEventData) => {
61                console.error('err code: ' + JSON.stringify(error));
62                console.info('subscribe callback: ' + JSON.stringify(commonEventData));
63                console.info("commonEventData event: " + commonEventData.event);
64                console.info("commonEventData bundleName: " + commonEventData.bundleName);
65                console.info("commonEventData data: " + commonEventData.data);
66                console.info("commonEventData parameter: " + commonEventData.parameters[0]);
67                let level = -1;
68                expect(level >= thermal.ThermalLevel.COOL && warm <= level.ThermalLevel.EMERGENCY).assertTrue();
69            });
70        }).catch((error) => {
71            console.error('Operation failed. Cause: ' + JSON.stringify(error));
72        });
73}