WifiP2P.test2.js 4.2 KB
Newer Older
Q
quanli 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'

function sleep(delay) {
    return new Promise(resovle => setTimeout(resovle, delay))
}

function checkWifiPowerOn(){
    console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}

export default function actsWifiTestNew() {
Q
quanli 已提交
28 29 30 31 32 33
describe('actsWifiTestNew', function () {
    beforeEach(function () {
        checkWifiPowerOn();
    })
    afterEach(function () {
    })
Q
quanli 已提交
34

Q
quanli 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    /**
    * @tc.number SUB_Communication_WiFi_XTS_P2P_0009
    * @tc.name testp2pCancelConnect
    * @tc.desc Test p2pCancelConnect Group  API functionality.
    * @tc.type Function
    * @tc.level Level 3
    */
    it('SUB_Communication_WiFi_XTS_P2P_0009', 0, async function (done) {
        let WifiP2PConfig = {
            deviceAddress : "00:00:00:00:00:00",
            netId : -1,
            passphrase : "12345678",
            groupName : "AAAZZZ123",
            goBand : 0
        };
        let addConfig = wifi.createGroup(WifiP2PConfig);
        console.info("[wifi_test] test p2pConnect result." + addConfig);
        let disConn = wifi.p2pCancelConnect();
        sleep(2000);
        console.info("[wifi_test] test p2pCancelConnect result." + disConn);
        expect(disConn).assertTrue();
        let removeConfig = wifi.removeGroup();
        console.info("[wifi_test] test start removeGroup" + removeConfig);
        expect(removeConfig).assertTrue();
        done();
    })
Q
quanli 已提交
61

Q
quanli 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74
    /**
    * @tc.number SUB_Communication_WiFi_XTS_P2P_0011
    * @tc.name testremoveGroup
    * @tc.desc Test remove error Group functionality.
    * @tc.type Function
    * @tc.level Level 3
    */
    it('SUB_Communication_WiFi_XTS_P2P_0011', 0, async function (done) {
        let isRemoved = wifi.removeGroup(10000);
        console.info("[wifi_test]removeGroup(10000) result : " + JSON.stringify(isRemoved));
        expect(isRemoved).assertTrue();
        done();
    })
Q
quanli 已提交
75

Q
quanli 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    /**
    * @tc.number     SUB_Communication_WiFi_XTS_P2P_0002
    * @tc.name       testP2pLocalDevice
    * @tc.desc       Test get TO P2pLocalDevice API functionality.
    * @tc.type Function
    * @tc.level Level 3
    */
    it('SUB_Communication_WiFi_XTS_P2P_0002', 0, async function (done) {
        await wifi.getP2pLocalDevice()
            .then(data => {
                let resultLength = Object.keys(data).length;
                console.info("[wifi_test] getP2pLocalDevice  [promise] result :" + JSON.stringify(data));
                expect(true).assertEqual(resultLength >= 0);
            }).catch((error) => {
                console.info("[wifi_test]getP2pLocalDevice promise error." + JSON.stringify(error));
                expect().assertFail();
            });
        function getP2pLocal(){
            return new Promise((resolve, reject) => {
                wifi.getP2pLocalDevice(
                    (err, ret) => {
                        if(err) {
                            console.info("[wifi_test]getP2pLocalDevice callback failed : " + JSON.stringify(err));
                            return;
                        }
                        console.info("[wifi_test] getP2pLocalDevice callback result: " + JSON.stringify(ret));
                        console.info("deviceName: " + ret.deviceName + "deviceAddress: " +
                        ret.deviceAddress + "primaryDeviceType: " + ret.primaryDeviceType +
                        "deviceStatus: " + ret.deviceStatus + "groupCapabilitys: " +
                        ret.groupCapabilitys );
                        resolve();
                    });
            });
        }
        await getP2pLocal();
        done();
    })
Q
quanli 已提交
113 114 115
    })
}