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 */
15import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Level, Size, TestType } from '@ohos/hypium';
16import power from '@ohos.power';
17
18const PERMISSION_DENIED_CODE = 201
19
20export default function PowerPermissionTest() {
21  describe('PowerPermissionTest', () => {
22    // Defines a test suite. Two parameters are supported: test suite name and test suite function.
23    beforeAll(() => {
24      // Presets an action, which is performed only once before all test cases of the test suite start.
25      // This API supports only one parameter: preset action function.
26    })
27    beforeEach(() => {
28      // Presets an action, which is performed before each unit test case starts.
29      // The number of execution times is the same as the number of test cases defined by **it**.
30      // This API supports only one parameter: preset action function.
31    })
32    afterEach(() => {
33      // Presets a clear action, which is performed after each unit test case ends.
34      // The number of execution times is the same as the number of test cases defined by **it**.
35      // This API supports only one parameter: clear action function.
36    })
37    afterAll(() => {
38      // Presets a clear action, which is performed after all test cases of the test suite end.
39      // This API supports only one parameter: clear action function.
40    })
41
42    /*
43     * @tc.number  PowerPermissionTest_0100
44     * @tc.name   testPowerPermissionTest_0100
45     * @tc.desc    Function test
46     * @tc.level: Level 3
47     * @tc.type: Function
48     * @tc.size: MediumTest
49     */
50    it('PowerPermissionTest_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done: Function) => {
51      let TAG = 'PowerPermissionTest_0100'
52      try {
53        power.rebootDevice('reboot_test');
54        let isActive = power.isActive();
55        console.info(`${TAG} isActive:${typeof isActive}`);
56        expect(typeof isActive).assertEqual('boolean');
57        done();
58      } catch (error) {
59        console.error(TAG + ` err: ${error.code}  ${error.message}`);
60        expect(error.code).assertEqual(PERMISSION_DENIED_CODE);
61        done();
62      }
63    });
64  })
65}