“0ee1155eb83a31ddd47c354c0bf748ad888aeb32”上不存在“...wifi_standard/git@gitcode.net:openharmony/xts_acts.git”
BluetoothHfp.test.js 8.4 KB
Newer Older
J
jiyong_sd 已提交
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 28 29 30
/*
 * 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 bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'


export default function bluetoothhostTest_host_3() {
describe('bluetoothhostTest_host_3', function () {
    function sleep(delay) {
        return new Promise(resovle => setTimeout(resovle, delay))
    }

    async function tryToEnableBt() {
        let sta = bluetooth.getState();
        switch(sta){
            case 0:
                bluetooth.enableBluetooth();
Q
quanli 已提交
31
                await sleep(10000);
Q
quanli 已提交
32 33
                let sta1 = bluetooth.getState();
                console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1));
J
jiyong_sd 已提交
34 35 36 37 38 39 40 41 42 43
                break;
            case 1:
                console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta));
                await sleep(3000);
                break;
            case 2:
                console.info('[bluetooth_js] bt turn on:'+ JSON.stringify(sta));
                break;
            case 3:
                bluetooth.enableBluetooth();
Q
quanli 已提交
44
                await sleep(10000);
Q
quanli 已提交
45 46
                let sta2 = bluetooth.getState();
                console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2));
J
jiyong_sd 已提交
47 48 49 50 51
                break;
            default:
                console.info('[bluetooth_js] enable success');
        }
    }
Q
quanli 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65
    beforeAll(function () {
        console.info('beforeAll called')
    })
    beforeEach(async function(done) {
        console.info('beforeEach called')
        await tryToEnableBt()
        done()
    })
    afterEach(function () {
        console.info('afterEach called')
    })
    afterAll(function () {
        console.info('afterAll called')
    })
J
jiyong_sd 已提交
66

Q
quanli 已提交
67 68 69 70 71 72 73 74 75 76 77
    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1100
     * @tc.name test Get HFP ConnectionState
     * @tc.desc Test getProfileConnState api.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1100', 0, async function (done) {
        let hfpSrcConn = 
Q
quanli 已提交
78
            bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
79
        console.info('[bluetooth_js]get hfp result:' + JSON.stringify(hfpSrcConn));
Q
quanli 已提交
80
        expect(hfpSrcConn).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
Q
quanli 已提交
81 82
        done();
    })
J
jiyong_sd 已提交
83 84

    /**
Q
quanli 已提交
85 86 87 88 89
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200
     * @tc.name test getDevice HFP State.
     * @tc.desc Test getDeviceState api.
     * @tc.size MEDIUM
     * @ since 8
J
jiyong_sd 已提交
90
     * @tc.type Function
Q
quanli 已提交
91
     * @tc.level Level 3
J
jiyong_sd 已提交
92
     */
Q
quanli 已提交
93
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200', 0, async function (done) {
Q
quanli 已提交
94
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
95 96
        let ret = hfpSrc.getDeviceState('11:22:33:44:55:66');
        console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret));
Q
quanli 已提交
97
        expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
J
jiyong_sd 已提交
98 99 100
        done();
    })

Q
quanli 已提交
101 102 103 104 105 106 107 108 109 110
    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300
     * @tc.name test getDevice HFP State.
     * @tc.desc Test getDeviceState api.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300', 0, async function (done) {
Q
quanli 已提交
111
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
112 113
        let ret = hfpSrc.getDeviceState('bluetooth1');
        console.info('[bluetooth_js]hfp get valid mac DeviceState:' + JSON.stringify(ret));
Q
quanli 已提交
114
        expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
Q
quanli 已提交
115 116
        done();
    })
J
jiyong_sd 已提交
117 118

    /**
Q
quanli 已提交
119 120 121 122 123
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1400
     * @tc.name test HFP Connect
     * @tc.desc Test connect api.
     * @tc.size MEDIUM
     * @ since 8
J
jiyong_sd 已提交
124
     * @tc.type Function
Q
quanli 已提交
125
     * @tc.level Level 1
J
jiyong_sd 已提交
126
     */
Q
quanli 已提交
127 128 129 130 131 132
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1400', 0, async function (done) {
        function StateChangeParam(data) {
            console.info("[bluetooth_js] hfp state " + JSON.stringify(data) +
            'deviceId: ' + data.deviceId + 'state:'+ data.state);
            expect(true).assertEqual(data !=null);
        }
Q
quanli 已提交
133
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
134
        hfpSrc.on('connectionStateChange', StateChangeParam);
Q
quanli 已提交
135
        let conn = hfpSrc.connect('11:22:33:44:55:66');
Q
quanli 已提交
136
        await sleep(6000);
Q
quanli 已提交
137 138
		console.info('[bluetooth_js]hfp connect result:' + JSON.stringify(conn));
        expect(conn).assertFalse();
Q
quanli 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
        hfpSrc.off('connectionStateChange', StateChangeParam);
        done();
    })
    
    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1500
     * @tc.name test HFP disconnect
     * @tc.desc Test disconnect api.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
      it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1500', 0, async function (done) {
        function StateChangeParam(data) {
            console.info("[bluetooth_js] hfp state " + JSON.stringify(data) +
            'deviceId: ' + data.deviceId + 'state:'+ data.state);
            expect(true).assertEqual(data !=null);
        }
Q
quanli 已提交
158
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
159 160 161 162 163 164
        hfpSrc.on('connectionStateChange', StateChangeParam);
        await sleep(10000);
        let conn = hfpSrc.disconnect('11:22:33:44:55:66');
        console.info('[bluetooth_js]hfp disconnect result:' + JSON.stringify(conn));
        expect(conn).assertFalse();
        hfpSrc.off('connectionStateChange', StateChangeParam);
J
jiyong_sd 已提交
165 166 167
        done();
    })

Q
quanli 已提交
168 169 170 171 172 173 174 175 176 177
    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600
     * @tc.name test a invaild HFP Connect
     * @tc.desc Test connect api.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 3
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600', 0, async function (done) {
Q
quanli 已提交
178
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
179 180 181 182 183
        let conn1 = hfpSrc.connect('test');
        console.info('[bluetooth_js]hfp vaild MAC disconnect :' + JSON.stringify(conn1));
        expect(conn1).assertFalse();
        done();
    })
J
jiyong_sd 已提交
184 185

    /**
Q
quanli 已提交
186 187 188 189 190
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700
     * @tc.name test a invaild HFP disconnect
     * @tc.desc Test disconnect api.
     * @tc.size MEDIUM
     * @ since 8
J
jiyong_sd 已提交
191
     * @tc.type Function
Q
quanli 已提交
192
     * @tc.level Level 3
J
jiyong_sd 已提交
193
     */
Q
quanli 已提交
194
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700', 0, async function (done) {
Q
quanli 已提交
195
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
196 197 198 199
        console.info('[bluetooth_js]hfp get profile result:' + JSON.stringify(hfpSrc));
        let conn = hfpSrc.disconnect('test');
        console.info('[bluetooth_js]hfp disconnect1 result:' + JSON.stringify(conn));
        expect(conn).assertFalse();
J
jiyong_sd 已提交
200 201 202
        done();
    })

Q
quanli 已提交
203 204 205 206 207 208 209 210 211 212
    /**
     * @tc.number SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800
     * @tc.name test getDevice HFP State.
     * @tc.desc Test getDeviceState api.
     * @tc.size MEDIUM
     * @ since 8
     * @tc.type Function
     * @tc.level Level 1
     */
    it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800', 0, async function (done) {
Q
quanli 已提交
213
        let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
Q
quanli 已提交
214 215 216 217 218 219 220
        let retArray = hfpSrc.getConnectionDevices();
        console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray));
        expect(true).assertEqual(retArray.length>=0);
        done();
    })


J
jiyong_sd 已提交
221 222 223
})

}
Q
quanli 已提交
224