未验证 提交 16530892 编写于 作者: O openharmony_ci 提交者: Gitee

!9802 【XTS】【communication】【同步monthly】短距NFC、LBS、wifi、BT覆盖率新增用例

Merge pull request !9802 from 权力/myfeature1
...@@ -27,6 +27,7 @@ group("communication") { ...@@ -27,6 +27,7 @@ group("communication") {
"dsoftbus/rpc_request:ActsRpcRequestJsTest", "dsoftbus/rpc_request:ActsRpcRequestJsTest",
"nfc_Controller:ActsNFCJSTest", "nfc_Controller:ActsNFCJSTest",
"nfc_ErrorCode:ActsNFCErrorJSTest", "nfc_ErrorCode:ActsNFCErrorJSTest",
"nfc_SecureElement:ActsnfcSEServiceTest",
"wifi_ErrorCode201:ActsErrorcode201Test", "wifi_ErrorCode201:ActsErrorcode201Test",
"wifi_ErrorCode202:ActsErrorcode202Test", "wifi_ErrorCode202:ActsErrorcode202Test",
"wifi_ErrorCode401:ActsErrorcode401Test", "wifi_ErrorCode401:ActsErrorcode401Test",
......
...@@ -88,47 +88,27 @@ ...@@ -88,47 +88,27 @@
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.USE_BLUETOOTH", "name": "ohos.permission.USE_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.MANAGE_BLUETOOTH", "name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.DISCOVER_BLUETOOTH", "name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", "name": "ohos.permission.LOCATION",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" "reason": ""
}, },
{ {
"name": "ohos.permission.LOCATION", "name": "ohos.permission.ACCESS_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": { },
"ability": [ {
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
], "reason": ""
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
......
/*
* 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.ble';
import btAccess from '@ohos.bluetooth.access';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btBleServiceTest() {
describe('btBleServiceTest', function() {
let gattServer = null;
let gattClient = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = btAccess.getState();
switch(sta){
case 0:
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta));
btAccess.enableBluetooth();
await sleep(10000);
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:
console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta));
btAccess.enableBluetooth();
await sleep(10000);
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(async function (done) {
console.info('beforeAll called')
await tryToEnableBt()
gattServer = bluetooth.createGattServer();
console.info('bluetooth ble create gattserver result:' + gattServer);
gattClient = bluetooth.createGattClientDevice('04:30:02:01:00:00');
console.info('bluetooth ble create gattclientdevice result:' + gattClient);
done()
})
beforeEach(async function(done) {
console.info('beforeEach called')
await tryToEnableBt()
done();
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
gattServer.close();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100
* @tc.name test Server connectStateChange
* @tc.desc Test on and off api10 .
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100', 0, async function (done) {
try {
function Connected(BLEConnectChangedState) {
let deviceId = BLEConnectChangedState.deviceId;
let status = BLEConnectChangedState.state;
console.info("[bluetooth_js] connectStateChange jsondata:"
+'deviceId:' + deviceId + 'status:' + status);
expect(true).assertEqual(BLEConnectChangedState !=null);
}
gattServer.on("connectStateChange", Connected);
gattServer.off("connectStateChange");
} catch (error) {
console.error(`[bluetooth_js]Connect_0100 failed, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100
* @tc.name testAddService
* @tc.desc Test AddService api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let characteristics = [];
let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: false,
characteristics:characteristics, includeServices:[]};
try {
gattServer.addService(gattService);
} catch (error) {
console.error(`[bluetooth_js]AddService2 failed, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200
* @tc.name testAddService
* @tc.desc Test api10 401 - characteristics of service is null.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200', 0, async function (done) {
try {
gattServer.removeService('00001810-0000-1000-8000-00805F9B34FB');
} catch (error) {
console.error(`[bluetooth_js]AddService2 failed, code is ${error.code},message is ${error.message}`);
expect(true).assertEqual(error.code == '2900099' || error.code == '401');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100
* @tc.name testNotifyCharacteristicChanged callback
* @tc.desc Test NotifyCharacteristicChanged api10.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
try {
gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic, (err, data) => {
console.info('notifyCharacteristicChanged err:' + JSON.stringify(err) + ',notifyCharacteristicChanged data:' + JSON.stringify(data));
});
} catch (error) {
console.error('[bluetooth_js]notifyCharacteristicChanged1 failed, code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200
* @tc.name testNotifyCharacteristicChanged promise
* @tc.desc Test NotifyCharacteristicChanged api10.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200', 0, async function (done) {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
try {
gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', notifyCharacteristic).then(() => {
console.info("notifyCharacteristicChanged");
}, err => {
console.error("notifyCharacteristicChanged:errCode" + err.code + ",errMessage:" + err.message);
});
} catch (error) {
console.error('[bluetooth_js]notifyCharacteristicChanged2 failed, code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100', 0, async function (done) {
try {
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1,
status: 0, offset: 0, value: arrayBuffer};
gattServer.sendResponse(ServerResponse);
expect(true).assertFalse();
done();
} catch (error) {
console.error(`[bluetooth_js]sendResponse1 failed, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual('2900099');
done()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200', 0, async function (done) {
try {
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let ServerResponse = {deviceId: '00:11:22:33:44:55', transId: 1,
status: -1, offset: 0, value: arrayBuffer};
gattServer.sendResponse(ServerResponse);
expect(true).assertFalse();
done();
} catch (error) {
console.error(`[bluetooth_js]sendResponse2 failed, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual('2900099');
done()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300
* @tc.name testSendResponse success
* @tc.desc Test SendResponse 401 -null parameter.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300', 0, async function (done) {
try {
gattServer.sendResponse();
expect(true).assertFalse();
done();
} catch (error) {
console.error('[bluetooth_js]sendResponse3 error.code:'+JSON.stringify(error.code)+
'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('401');
done()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400
* @tc.name testSendResponse success
* @tc.desc Test SendResponse 401 -error parameter.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400', 0, async function (done) {
try {
let arrayBuffer = new ArrayBuffer(8);
let value = new Uint8Array(arrayBuffer);
value[0] = 1;
let ServerResponse = {transId: 1,
status: -1, offset: 0, value: arrayBuffer};
gattServer.sendResponse(ServerResponse);
expect(true).assertFalse();
done();
} catch (error) {
console.error(`[bluetooth_js]sendResponse4 failed, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual('401');
done()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100
* @tc.name test gattserver on blemtuchange
* @tc.desc test gattserver on blemtuchange api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100', 0, async function (done) {
try {
gattServer.on('BLEMtuChange', (err, data)=> {
console.info('BLEMtuChange on err ' + JSON.stringify(err));
console.info('BLEMtuChange on value' + JSON.stringify(data));
})
} catch (err) {
console.error("bluetooth mtu changed on errCode:" + err.code + ",bluetooth mtu changed on errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
gattServer.off('BLEMtuChange', (err, data)=> {
console.info('BLEMtuChange off err ' + JSON.stringify(err));
console.info('BLEMtuChange off value' + JSON.stringify(data));
})
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200
* @tc.name test gattserver off blemtuchange
* @tc.desc test gattserver off blemtuchange api10
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200', 0, async function (done) {
gattServer.on('BLEMtuChange', (err, data)=> {
console.info('BLEMtuChange on err ' + JSON.stringify(err));
console.info('BLEMtuChange on value' + JSON.stringify(data));
})
try {
gattServer.off('BLEMtuChange', (err, data)=> {
console.info('BLEMtuChange off err ' + JSON.stringify(err));
console.info('BLEMtuChange off value' + JSON.stringify(data));
})
} catch (err) {
console.error("bluetooth mtu changed off errCode:" + err.code + ",bluetooth mtu changed off errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
})
}
...@@ -75,13 +75,14 @@ describe('btGattManagerTest', function() { ...@@ -75,13 +75,14 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GATTCLICONNECT_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GATTCLICONNECT_0100', 0, async function (done) {
let ret = gattClient.connect(); try {
await sleep(2000); gattClient.connect();
console.info('[bluetooth_js] gattClient connect' + ret) await sleep(2000);
expect(ret).assertFalse(); gattClient.disconnect();
let disconnect = gattClient.disconnect(); } catch (error) {
console.info('[bluetooth_js] gatt disconnect:' + disconnect); console.info('[bluetooth_js] gatt disconnect:' + disconnect);
expect(disconnect).assertEqual(false); expect(error.code).assertEqual('2900099');
}
done(); done();
}) })
...@@ -113,12 +114,14 @@ describe('btGattManagerTest', function() { ...@@ -113,12 +114,14 @@ describe('btGattManagerTest', function() {
console.info('[bluetooth_js] state changed' + connectState) console.info('[bluetooth_js] state changed' + connectState)
expect(true).assertEqual(connectState!=null); expect(true).assertEqual(connectState!=null);
} }
await gattClient.on('BLEConnectionStateChange', ConnectStateChanged); try {
let ret = gattClient.connect(); await gattClient.on('BLEConnectionStateChange', ConnectStateChanged);
console.info('[bluetooth_js] gattClient connect' + ret) gattClient.connect();
expect(ret).assertFalse(); gattClient.disconnect();
gattClient.disconnect(); } catch (error) {
await sleep(2000); console.info('[bluetooth_js] gatt disconnect:' + disconnect);
expect(error.code).assertEqual('2900099');
}
await gattClient.off("BLEConnectionStateChange"); await gattClient.off("BLEConnectionStateChange");
done(); done();
}) })
...@@ -131,9 +134,7 @@ describe('btGattManagerTest', function() { ...@@ -131,9 +134,7 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0100', 0, async function (done) {
let ret = gattClient.connect(); gattClient.connect();
console.info('[bluetooth_js] gattClient getrssi connect:' + JSON.stringify(ret))
expect(ret).assertFalse();
try { try {
await gattClient.getRssiValue().then((data) => { await gattClient.getRssiValue().then((data) => {
console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data));
...@@ -150,14 +151,13 @@ describe('btGattManagerTest', function() { ...@@ -150,14 +151,13 @@ describe('btGattManagerTest', function() {
expect(true).assertEqual(b); expect(true).assertEqual(b);
done(); done();
}); });
let disconnect = gattClient.disconnect(); gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi disconnect:' + disconnect);
expect(disconnect).assertEqual(false);
}catch (error) { }catch (error) {
console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, console.error(`[bluetooth_js]error, code is ${error.code},
message is ${error.message}`); message is ${error.message}`);
expect(error.code).assertEqual('2900099');
} }
done() done();
}) })
...@@ -169,31 +169,32 @@ describe('btGattManagerTest', function() { ...@@ -169,31 +169,32 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0200', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0200', 0, async function (done) {
let ret = gattClient.connect(); try {
console.info('[bluetooth_js] gattClient getRssi connect' + JSON.stringify(ret)) gattClient.connect();
expect(ret).assertFalse(); gattClient.getRssiValue((err, data)=> {
gattClient.getRssiValue((err, data)=> { if(err)
if(err) {
{ console.info('[bluetooth_js]getRssi value:'+JSON.stringify(err));
console.info('[bluetooth_js]getRssi value:'+JSON.stringify(err)); let b=false;
let b=false; if(err.code==2900099||err.code==-1)
if(err.code==2900099||err.code==-1) {
{
b=true b=true
} }
expect(true).assertEqual(b); expect(true).assertEqual(b);
} }
else else
{ {
console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data));
expect(true).assertEqual(data!=null) expect(true).assertEqual(data!=null)
} }
}); });
let disconnect = gattClient.disconnect(); gattClient.disconnect();
console.info('[bluetooth_js] gatt getrssi1 disconnect:' + disconnect); } catch (error) {
expect(disconnect).assertEqual(false); console.error(`[bluetooth_js]error, code is ${error.code},
await sleep(3000); message is ${error.message}`);
done() expect(error.code).assertEqual('2900099');
}
done();
}) })
/** /**
...@@ -204,22 +205,24 @@ describe('btGattManagerTest', function() { ...@@ -204,22 +205,24 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0100', 0, async function (done) {
let ret = gattClient.connect(); try {
console.info('[bluetooth_js] gattClient getname2 connect' + JSON.stringify(ret)) gattClient.connect();
expect(ret).assertFalse(); await gattClient.getDeviceName().then((data) => {
await gattClient.getDeviceName().then((data) => { console.info('[bluetooth_js] device name' + JSON.stringify(data))
console.info('[bluetooth_js] device name' + JSON.stringify(data)) expect(true).assertEqual(data != null);
expect(true).assertEqual(data != null); done();
done(); }).catch(err => {
}).catch(err => { console.error('bluetooth getDeviceName has error: '+ err);
console.error('bluetooth getDeviceName has error: '+ err); expect(err.code).assertEqual(2900099);
expect(err.code).assertEqual(2900099); done();
done(); });
}); gattClient.disconnect();
let disconnect = gattClient.disconnect(); } catch (error) {
console.info('[bluetooth_js] gatt getname2 disconnect:' + disconnect); console.error(`[bluetooth_js]error, code is ${error.code},
expect(disconnect).assertEqual(false); message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
}) })
...@@ -231,17 +234,19 @@ describe('btGattManagerTest', function() { ...@@ -231,17 +234,19 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0200', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0200', 0, async function (done) {
let ret = gattClient.connect(); try {
console.info('[bluetooth_js] gattClient getname1 connect' + JSON.stringify(ret)) gattClient.connect();
expect(ret).assertFalse(); gattClient.getDeviceName((err, data)=> {
gattClient.getDeviceName((err, data)=> { console.info('[bluetooth_js]getname value:'+JSON.stringify(data));
console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); console.info('[bluetooth_js]getname err code:'+JSON.stringify(err));
console.info('[bluetooth_js]getname err code:'+JSON.stringify(err)); expect(true).assertEqual(data != null);
expect(true).assertEqual(data != null); gattClient.disconnect();
let disconnect = gattClient.disconnect(); });
console.info('[bluetooth_js] gatt getname1 disconnect:' + disconnect); } catch (error) {
expect(disconnect).assertEqual(false); console.error(`[bluetooth_js]error, code is ${error.code},
}); message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done(); done();
}) })
...@@ -253,21 +258,24 @@ describe('btGattManagerTest', function() { ...@@ -253,21 +258,24 @@ describe('btGattManagerTest', function() {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_GETSERVICE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_GETSERVICE_0100', 0, async function (done) {
let ret = gattClient.connect(); try {
console.info('[bluetooth_js]gattClient getservices1 connect' + JSON.stringify(ret)) gattClient.connect();
expect(ret).assertFalse(); await gattClient.getServices().then((GattService) => {
await gattClient.getServices().then((GattService) => { console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService));
console.info('[bluetooth_js] getServices successfully:'+JSON.stringify(GattService)); expect(GattService).assertNull();
expect(GattService).assertNull(); done();
done(); }).catch(err => {
}).catch(err => { console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err));
console.error('[bluetooth_js] getServices has error:'+ JSON.stringify(err)); expect(true).assertEqual(true);
expect(true).assertEqual(true); done();
done(); });
}); gattClient.disconnect();
let disconnect = gattClient.disconnect(); } catch (error) {
console.info('[bluetooth_js] gatt getservices1 disconnect:' + disconnect); console.error(`[bluetooth_js]error, code is ${error.code},
expect(disconnect).assertEqual(false); message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
}) })
/** /**
......
...@@ -81,13 +81,14 @@ describe('btGattServiceTest', function() { ...@@ -81,13 +81,14 @@ describe('btGattServiceTest', function() {
let status = BLEConnectChangedState.state; let status = BLEConnectChangedState.state;
console.info("[bluetooth_js] connectStateChange jsondata:" console.info("[bluetooth_js] connectStateChange jsondata:"
+'deviceId:' + deviceId + 'status:' + status); +'deviceId:' + deviceId + 'status:' + status);
expect(true).assertEqual(BLEConnectChangedState !=null); }
} try {
await gattServer.on("connectStateChange", Connected); await gattServer.on("connectStateChange", Connected);
let ret = gattClient.connect(); gattClient.connect();
await sleep(2000); } catch (error) {
console.info('[bluetooth_js] gattClient connect' + ret) console.error(`[bluetooth_js]code is ${error.code},message is ${error.message}`);
expect(ret).assertFalse(); expect(error.code).assertEqual('2900099');
}
await gattServer.off("connectStateChange"); await gattServer.off("connectStateChange");
done(); done();
}) })
......
...@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() { ...@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() {
beforeAll(function () { beforeAll(function () {
console.info('beforeAll called') console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("92:3A:C0:3A:4C:28"); gattClient = bluetooth.BLE.createGattClientDevice('92:3A:C0:3A:4C:28');
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
console.info('beforeEach called') console.info('beforeEach called')
...@@ -78,15 +78,21 @@ describe('btManagerGattManagerTest', function() { ...@@ -78,15 +78,21 @@ describe('btManagerGattManagerTest', function() {
it('SUB_COMMUNICATION_BTMANAGER_GATTCONNECT_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GATTCONNECT_0100', 0, async function (done) {
try { try {
gattClient.connect(); gattClient.connect();
await sleep(2000); console.info(`[bluetooth_js]connect success`);
}
catch(error) {
console.info(`[bluetooth_js]connect failed, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
try {
gattClient.disconnect(); gattClient.disconnect();
expect(true).assertFalse(); console.info(`[bluetooth_js]disconnect success`);
} catch(error) { }
console.error(`[bluetooth_js]disconnect failed, code is ${error.code}, catch(error) {
message is ${error.message}`); console.info(`[bluetooth_js]disconnect failed, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099'); expect(error.code).assertEqual('2900099');
} }
done() done();
}) })
/** /**
...@@ -147,28 +153,16 @@ describe('btManagerGattManagerTest', function() { ...@@ -147,28 +153,16 @@ describe('btManagerGattManagerTest', function() {
*/ */
it('SUB_COMMUNICATION_BTMANAGER_GETRSSIVALUE_0100', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETRSSIVALUE_0100', 0, async function (done) {
try { try {
await gattClient.getRssiValue().then((data) => {
console.info('[bluetooth_js] BLE read rssi: ' + JSON.stringify(data)); let gattRssi = gattClient.getRssiValue().then((data) => {
expect(true).assertEqual(data!=null); console.info('[bluetooth_js] gattRssi: ' + gattRssi);
done(); console.info('[bluetooth_js] gattRssi data: ' + JSON.stringify(data));
}).catch(err => { })
console.info('bluetooth getRssiValue has error: '+ JSON.stringify(err));
// expect(true).assertEqual(error.code==2900099||error.code==-1);
let b=false;
if(err.code==2900099||err.code==-1)
{
b=true
}
expect(true).assertEqual(b);
done();
});
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code}, console.error(`[bluetooth_js]GetRssiValue_0100 error, code is ${error.code},message is ${error.message}`);
message is ${error.message}`); expect(true).assertEqual(error.code == '2900099' || error.code == 2900099 || error.code == -1);
expect(false).assertEqual(true);
done()
} }
done();
}) })
/** /**
...@@ -195,7 +189,6 @@ describe('btManagerGattManagerTest', function() { ...@@ -195,7 +189,6 @@ describe('btManagerGattManagerTest', function() {
else else
{ {
console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data)); console.info('[bluetooth_js]getRssi value:'+JSON.stringify(data));
expect(true).assertEqual(data!=null );
} }
resolve(); resolve();
}); });
...@@ -203,11 +196,9 @@ describe('btManagerGattManagerTest', function() { ...@@ -203,11 +196,9 @@ describe('btManagerGattManagerTest', function() {
} }
await getRssi(); await getRssi();
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetRssiValue_0200 error, code is ${error.code}, console.error(`[bluetooth_js]GetRssiValue_0200 error, code is ${error.code},message is ${error.message}`);
message is ${error.message}`); expect(error.code).assertEqual('2900099');
expect(false).assertEqual(true);
} }
await sleep(2000);
done(); done();
}) })
...@@ -250,14 +241,13 @@ describe('btManagerGattManagerTest', function() { ...@@ -250,14 +241,13 @@ describe('btManagerGattManagerTest', function() {
console.info('[bluetooth_js]getname value:'+JSON.stringify(data)); console.info('[bluetooth_js]getname value:'+JSON.stringify(data));
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
}); });
await sleep(2000);
done(); done();
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetDeviceName_0200 failed, code is ${error.code}, console.error(`[bluetooth_js]GetDeviceName_0200 failed, code is ${error.code},message is ${error.message}`);
message is ${error.message}`); expect(error.code).assertEqual('2900099');
expect(true).assertFalse(); done();
done() }
} done();
}) })
/** /**
...@@ -279,11 +269,11 @@ describe('btManagerGattManagerTest', function() { ...@@ -279,11 +269,11 @@ describe('btManagerGattManagerTest', function() {
done(); done();
}); });
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code}, console.error(`[bluetooth_js]GetService_0100 failed, code is ${error.code},message is ${error.message}`);
message is ${error.message}`); expect(error.code).assertEqual('2900099');
expect(true).assertFalse(); done();
done() }
} done();
}) })
/** /**
...@@ -307,7 +297,7 @@ describe('btManagerGattManagerTest', function() { ...@@ -307,7 +297,7 @@ describe('btManagerGattManagerTest', function() {
}); });
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code},message is ${error.message}`); console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code},message is ${error.message}`);
expect(true).assertFalse(); expect(error.code).assertEqual('2900099');
done(); done();
} }
done(); done();
......
...@@ -19,12 +19,15 @@ import btGattServiceTest from './BtGattService.test.js' ...@@ -19,12 +19,15 @@ import btGattServiceTest from './BtGattService.test.js'
import btManagerGattAdvertTest from './BtManagerGattAdvertiser.test.js' import btManagerGattAdvertTest from './BtManagerGattAdvertiser.test.js'
import btManagerGattManagerTest from './BtManagerGattManager.test.js' import btManagerGattManagerTest from './BtManagerGattManager.test.js'
import btManagerGattServiceTest from './BtManagerGattService.test.js' import btManagerGattServiceTest from './BtManagerGattService.test.js'
import btBleManagerTest from './BtBleManager.test.js'
import btBleServiceTest from './BtBleService.test.js'
export default function testsuite() { export default function testsuite() {
btGattAdvertTest() btBleManagerTest()
btBleServiceTest()
btManagerGattManagerTest()
btManagerGattServiceTest() btManagerGattServiceTest()
btGattServiceTest() btGattServiceTest()
btManagerGattAdvertTest()
btManagerGattManagerTest()
btGattManagerTest() btGattManagerTest()
btManagerGattAdvertTest()
btGattAdvertTest()
} }
...@@ -106,10 +106,6 @@ ...@@ -106,10 +106,6 @@
"when": "inuse" "when": "inuse"
} }
}, },
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{ {
"name": "ohos.permission.DISCOVER_BLUETOOTH", "name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "", "reason": "",
...@@ -129,6 +125,16 @@ ...@@ -129,6 +125,16 @@
], ],
"when": "inuse" "when": "inuse"
} }
},
{
"name": "ohos.permission.ACCESS_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
} }
], ],
"testRunner": { "testRunner": {
......
/*
* 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.a2dp';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btA2dpTest() {
describe('btA2dpTest', function() {
let A2dpSourceProfile = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = bluetooth.getState();
switch (sta) {
case 0:
bluetooth.enableBluetooth();
await sleep(10000);
let sta1 = bluetooth.getState();
console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1));
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();
await sleep(10000);
let sta2 = bluetooth.getState();
console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2));
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
A2dpSourceProfile = bluetooth.createA2dpSrcProfile();
})
beforeEach(async function (done) {
console.info('beforeEach called')
await tryToEnableBt()
done();
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100
* @tc.name test getPlayingState
* @tc.desc Test getPlayingState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100', 0, async function (done) {
try {
let state = A2dpSourceProfile.getPlayingState('11:22:33:44:55:66');
assert(true).assertEqual(state == bluetooth.PlayingState.STATE_NOT_PLAYING || state == bluetooth.PlayingState.STATE_PLAYING);
} catch (err) {
console.error("bluetooth a2dp getPlayingState errCode:" + err.code + ",bluetooth a2dp getPlayingState errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200
* @tc.name test PlayingState
* @tc.desc Test PlayingState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200', 0, async function (done) {
let statePlaying = bluetooth.PlayingState.STATE_PLAYING;
console.info("[bluetooth_js]PlayingState: " + JSON.stringify(statePlaying));
expect(statePlaying).assertEqual(1);
let stateNotPlaying = bluetooth.PlayingState.STATE_NOT_PLAYING;
console.info("[bluetooth_js]PlayingState: " + JSON.stringify(stateNotPlaying));
expect(stateNotPlaying).assertEqual(0);
done();
})
})
}
\ No newline at end of file
/*
* 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 btAccess from '@ohos.bluetooth.access';
import a2dp from '@ohos.bluetooth.a2dp';
import hid from '@ohos.bluetooth.hid';
import hfp from '@ohos.bluetooth.hfp';
import pan from '@ohos.bluetooth.pan';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btBaseProfileTest() {
describe('btBaseProfileTest', function() {
let A2dpSourceProfile = null;
let HandsFreeAudioGatewayProfile = null;
let HidHostProfile = null;
let PanProfile = null;
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = btAccess.getState();
switch (sta) {
case 0:
btAccess.enableBluetooth();
await sleep(10000);
let sta1 = btAccess.getState();
console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1));
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:
btAccess.enableBluetooth();
await sleep(10000);
let sta2 = btAccess.getState();
console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2));
break;
default:
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
console.info('beforeAll called')
A2dpSourceProfile = a2dp.createA2dpSrcProfile();
HandsFreeAudioGatewayProfile = hfp.createHfpAgProfile();
HidHostProfile = hid.createHidHostProfile();
PanProfile = pan.createPanProfile();
expect(true).assertEqual(A2dpSourceProfile != null && HandsFreeAudioGatewayProfile != null && HidHostProfile != null && PanProfile != null);
})
beforeEach(async function (done) {
console.info('beforeEach called')
await tryToEnableBt()
done()
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100', 0, async function (done) {
try {
let devices = A2dpSourceProfile.getConnectedDevices();
console.info("address of connected devices list:" + devices);
expect(true).assertEqual(devices != null);
} catch (err) {
console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200', 0, async function (done) {
try {
let state = A2dpSourceProfile.getConnectionState("11:22:33:AA:BB:FF");
console.info("the connection state:" + state);
expect(true).assertEqual(state == 0 || state == 1 || state == 2);
} catch (err) {
console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
try {
A2dpSourceProfile.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
A2dpSourceProfile.off('connectionStateChange', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
A2dpSourceProfile.on('connectionStateChange', onReceiveEvent);
try {
A2dpSourceProfile.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500', 0, async function (done) {
try {
let devices = HandsFreeAudioGatewayProfile.getConnectedDevices();
console.info("address of connected devices list:" + devices);
expect(true).assertEqual(devices != null);
} catch (err) {
console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600', 0, async function (done) {
try {
let state = HandsFreeAudioGatewayProfile.getConnectionState("11:22:33:AA:BB:FF");
console.info("the connection state:" + state);
expect(true).assertEqual(state == 0 || state == 1 || state == 2);
} catch (err) {
console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
console.info('connection state change:'+ data.deviceId);
console.info('connection state change:'+ data.state);
}
try {
HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
HandsFreeAudioGatewayProfile.off('connectionStateChange', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent);
try {
HandsFreeAudioGatewayProfile.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900', 0, async function (done) {
try {
let devices = HidHostProfile.getConnectedDevices();
console.info("address of connected devices list:" + devices);
expect(true).assertEqual(devices != null);
} catch (err) {
console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000', 0, async function (done) {
try {
let state = HidHostProfile.getConnectionState("11:22:33:AA:BB:FF");
console.info("the connection state:" + state);
expect(true).assertEqual(state == 0 || state == 1 || state == 2);
} catch (err) {
console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
try {
HidHostProfile.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
HidHostProfile.off('connectionStateChange', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
HidHostProfile.on('connectionStateChange', onReceiveEvent);
try {
HidHostProfile.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300', 0, async function (done) {
try {
let devices = PanProfile.getConnectedDevices();
console.info("address of connected devices list:" + devices);
expect(true).assertEqual(devices != null);
} catch (err) {
console.error("bluetooth getConnectedDevices errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400', 0, async function (done) {
try {
let state = PanProfile.getConnectionState("11:22:33:AA:BB:FF");
console.info("the connection state:" + state);
expect(true).assertEqual(state == 0 || state == 1 || state == 2);
} catch (err) {
console.error("bluetooth getConnectionState errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
try {
PanProfile.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
PanProfile.off('connectionStateChange', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600', 0, async function (done) {
function onReceiveEvent(data) {
console.info('connection state change:'+ JSON.stringify(data));
}
PanProfile.on('connectionStateChange', onReceiveEvent);
try {
PanProfile.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error("bluetooth connectionStateChange errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertFalse();
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1700
* @tc.name test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile
* @tc.desc Test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile api10.
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_1700', 0, async function (done) {
try {
let asp = a2dp.createA2dpSrcProfile();
let hp = hfp.createHfpAgProfile();
let hhp = hid.createHidHostProfile();
let pp = pan.createPanProfile();
expect(true).assertEqual(asp != null);
expect(true).assertEqual(hp != null);
expect(true).assertEqual(hhp != null);
expect(true).assertEqual(pp != null);
} catch (err) {
console.error("bluetooth createProfile errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
})
}
\ No newline at end of file
...@@ -17,9 +17,13 @@ import btHfpConnTest from './BluetoothHfp.test.js' ...@@ -17,9 +17,13 @@ import btHfpConnTest from './BluetoothHfp.test.js'
import btA2dpConnTest from './BluetoothA2dp.test.js' import btA2dpConnTest from './BluetoothA2dp.test.js'
import btManagerHfpConnTest from './BtManagerHfp.test.js' import btManagerHfpConnTest from './BtManagerHfp.test.js'
import btManagerA2dpConnTest from './BtManagerA2dp.test.js' import btManagerA2dpConnTest from './BtManagerA2dp.test.js'
import btA2dpTest from './BtA2dp.test.js'
import btBaseProfileTest from './BtBaseProfile.test.js'
export default function testsuite() { export default function testsuite() {
btBaseProfileTest()
btHfpConnTest() btHfpConnTest()
btA2dpConnTest() btA2dpConnTest()
btManagerHfpConnTest() btManagerHfpConnTest()
btManagerA2dpConnTest() btManagerA2dpConnTest()
btA2dpTest()
} }
...@@ -106,10 +106,6 @@ ...@@ -106,10 +106,6 @@
"when": "inuse" "when": "inuse"
} }
}, },
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{ {
"name": "ohos.permission.DISCOVER_BLUETOOTH", "name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "", "reason": "",
...@@ -129,6 +125,24 @@ ...@@ -129,6 +125,24 @@
], ],
"when": "inuse" "when": "inuse"
} }
},
{
"name": "ohos.permission.ACCESS_BLUETOOTH",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": ""
},
{
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason": ""
} }
], ],
"testRunner": { "testRunner": {
......
/*
* 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.ble';
import btAccess from '@ohos.bluetooth.access';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function bluetoothBleTest() {
describe('bluetoothBleTest', function() {
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = btAccess.getState();
switch(sta){
case 0:
btAccess.enableBluetooth();
await sleep(10000);
let sta1 = btAccess.getState();
console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1));
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:
btAccess.enableBluetooth();
await sleep(10000);
let sta2 = btAccess.getState();
console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2));
break;
default:
console.info('[bluetooth_js] enable success');
}
}
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')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100
* @tc.name test startBLEScan
* @tc.desc Test startBLEScan api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100', 0, async function (done) {
function onReceiveEvent(data) {
console.info('BLE scan device find result = '+ JSON.stringify(data));
}
try {
bluetooth.on("BLEDeviceFind", onReceiveEvent);
bluetooth.startBLEScan(
[{
deviceId:"00:11:22:33:44:55",
name:"test",
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
}],
{
interval: 500,
dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
bluetooth.off("BLEDeviceFind", onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200
* @tc.name test stopBLEScan
* @tc.desc Test stopBLEScan api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200', 0, async function (done) {
try {
bluetooth.stopBLEScan();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300
* @tc.name test on-BLEDeviceFind
* @tc.desc Test on-BLEDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300', 0, async function (done) {
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
bluetooth.on('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
bluetooth.off('BLEDeviceFind', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400
* @tc.name test off-BLEDeviceFind
* @tc.desc Test off-BLEDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400', 0, async function (done) {
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
bluetooth.on('BLEDeviceFind', onReceiveEvent);
try {
bluetooth.off('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
})
}
/*
* 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.connection';
import btAccess from '@ohos.bluetooth.access';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btConnectionTest() {
describe('btConnectionTest', function() {
let Btname = {
LETTERS_TEST :'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
CHINESES_TEST2 :'测试蓝牙名称正常',
}
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = btAccess.getState();
switch (sta) {
case 0:
btAccess.enableBluetooth();
await sleep(10000);
let sta1 = btAccess.getState();
console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1));
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:
btAccess.enableBluetooth();
await sleep(10000);
let sta2 = btAccess.getState();
console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2));
break;
default:
console.info('[bluetooth_js] enable success');
}
}
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')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100
* @tc.name Test pinRequired and setDevicePairing true
* @tc.desc Test pinRequired off api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100', 0, async function (done) {
function onReceiveEvent(data) {
console.info('pin required = '+ JSON.stringify(data));
}
try {
bluetooth.on('pinRequired', onReceiveEvent);
bluetooth.off('pinRequired', onReceiveEvent);
} catch (error) {
console.error(`[bluetooth_js]PairDevice error, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200
* @tc.name test get PairedDevices
* @tc.desc Test getPairedDevices api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200', 0, async function (done) {
try {
let ret = bluetooth.getPairedDevices();
console.info('[bluetooth_js] getPairedDevices ret2:' + JSON.stringify(ret));
expect(true).assertEqual(ret.length >= 0);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300
* @tc.name test getRemoteDeviceName
* @tc.desc Test get RemoteDeviceName api 10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300', 0, async function (done) {
try {
let ret = bluetooth.getRemoteDeviceName("00:00:00:00:00:00");
console.info('[bluetooth_js] getRemoteDeviceName ret2:' + JSON.stringify(ret));
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400
* @tc.name Test On pair StateChange
* @tc.desc Test bondStateChange ON api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400', 0, async function (done) {
function BondStateParam(data) {
console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data)
+'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state);
}
try {
bluetooth.on('bondStateChange', BondStateParam);
bluetooth.pairDevice("11:22:55:66:33:44");
expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue();
expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue();
expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue();
bluetooth.off('bondStateChange', BondStateParam);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500
* @tc.name Test setDevicePairingConfirmation
* @tc.desc Test setDevicePairingConfirmation api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500', 0, async function (done) {
function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId, false);
console.info("[bluetooth_js] setDevicePairingConfirmation data.deviceId:" + data.deviceId);
}
try {
bluetooth.on('pinRequired', PinRequiredParam);
await sleep(2000);
bluetooth.off('pinRequired', PinRequiredParam);
} catch (err) {
console.error("setDevicePairingConfirmation errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600
* @tc.name test getRemoteDeviceClass
* @tc.desc Test get RemoteDeviceClass api10
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600', 0, async function (done) {
try {
let DeviceClass = bluetooth.getRemoteDeviceClass("00:00:00:00:00:00");
console.info('[bluetooth_js]getRemoteDeviceClass majorClass:' + DeviceClass.majorClass);
console.info('[bluetooth_js]getRemoteDeviceClass majorMinorClass:' + DeviceClass.majorMinorClass);
console.info('[bluetooth_js]getRemoteDeviceClass classOfDevice:' + DeviceClass.classOfDevice);
} catch (err) {
console.error("getRemoteDeviceClass errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700
* @tc.name Test setDevicePinCode callback
* @tc.desc Test setDevicePinCode api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700', 0, async function (done) {
try {
bluetooth.setDevicePinCode('11:22:33:44:55:66', '12345', (err, data) => {
console.info('setDevicePinCode callback,device name err:' + JSON.stringify(err) + ',device name:' + JSON.stringify(data));
});
} catch (err) {
console.error("setDevicePinCode callback errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800
* @tc.name Test setDevicePinCode promise
* @tc.desc Test setDevicePinCode api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800', 0, async function (done) {
try {
bluetooth.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => {
console.info('setDevicePinCode promise');
}, error => {
console.info('setDevicePinCode promise: errCode:' + error.code + ',errMessage' + error.message);
})
} catch (err) {
console.error("setDevicePinCode promise errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100', 0, async function (done) {
let state = btAccess.getState();
console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state));
if(state == 2)
{
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_NONE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 newscanmode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_NONE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 setoldscanmode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
}
else
{
console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state));
expect(true).assertFalse();
done();
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200', 0, async function (done) {
let state = btAccess.getState();
console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state));
if(state == 2)
{
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0);
expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 newscanmode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 setoldscanmode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
done();
}
else
{
console.info('[bluetooth_js] bluetooth switch off,state is = '+ JSON.stringify(state));
expect(true).assertFalse();
done();
}
})
/**
* @tc.number SUB_COMMUNICATION_BTMANAGER_DISCOVERY_0100
* @tc.name TEST bluetoothDeviceFind on&off
* @tc.desc TEST bluetoothDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_DISCOVERY_0100', 0, async function (done) {
function onReceiveEvent(data) {
console.info('[bluetooth_js] Device' + JSON.stringify(data) +
'length' + data.length);
expect(true).assertTrue(data.length > 0);
}
try {
bluetooth.on("bluetoothDeviceFind", onReceiveEvent);
let result = bluetooth.startBluetoothDiscovery();
await sleep(3000);
console.info('[bluetooth_js] startDiscovery' + result);
expect(result).assertTrue();
bluetooth.off('bluetoothDeviceFind', onReceiveEvent);
result = bluetooth.stopBluetoothDiscovery();
console.info('[bluetooth_js] stopDiscovery' + result);
expect(true).assertTrue();
} catch (error) {
console.error(`[bluetooth_js]bluetoothDeviceFin error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100
* @tc.name setLocalName
* @tc.desc Test setLocalName api10
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100', 0, async function (done) {
let result = bluetooth.setLocalName(Btname.LETTERS_TEST);
expect(result).assertTrue();
await sleep(1000);
try {
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0100 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.LETTERS_TEST == getNewName);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200
* @tc.name setLocalName
* @tc.desc Test setLocalName api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200', 0, async function (done) {
try {
let result = bluetooth.setLocalName(Btname.CHINESES_TEST2);
expect(result).assertTrue();
await sleep(1000);
let getNewName = bluetooth.getLocalName();
console.info('[bluetooth_js] LocalName_0200 NewName = '+ JSON.stringify(getNewName));
expect(true).assertEqual(Btname.CHINESES_TEST2 == getNewName);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100
* @tc.name test getBtConnectionState
* @tc.desc Test getBtConnectionState api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100', 0, async function (done) {
try {
let connectionState = bluetooth.getBtConnectionState();
expect(true).assertEqual(connectionState == 0 || connectionState == 1 || connectionState == 2 || connectionState == 3);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200
* @tc.name getProfileConnectionState
* @tc.desc Test getProfileConnectionState api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200', 0, async function (done) {
try {
let result = bluetooth.getProfileConnectionState(1);
expect(true).assertEqual(result == 0 || result == 1 || result == 2 || result == 3);
} catch (err) {
console.error("getProfileConnectionState errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100
* @tc.name BluetoothTransport
* @tc.desc Test BluetoothTransport api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100', 0, async function (done) {
try {
let TRANSPORT_BR_EDR = bluetooth.BluetoothTransport.TRANSPORT_BR_EDR;
let TRANSPORT_LE = bluetooth.BluetoothTransport.TRANSPORT_LE;
expect(TRANSPORT_BR_EDR).assertEqual(0);
expect(TRANSPORT_LE).assertEqual(1);
} catch (err) {
console.error("BluetoothTransport errCode:" + err.code + ",errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
})
}
\ No newline at end of file
...@@ -73,9 +73,8 @@ describe('btPairTest', function() { ...@@ -73,9 +73,8 @@ describe('btPairTest', function() {
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0100', 0, async function (done) {
try{ try{
let result = bluetooth.pairDevice("11:22:55:66:33:44"); bluetooth.pairDevice("11:22:55:66:33:44");
await sleep(3000); await sleep(3000);
expect(true).assertEqual(result == false);
} catch(err) { } catch(err) {
console.error("pairDevice errCode:" + err.code + ",errMessage:" + err.message); console.error("pairDevice errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('2900099'); expect(err.code).assertEqual('2900099');
...@@ -229,13 +228,13 @@ describe('btPairTest', function() { ...@@ -229,13 +228,13 @@ describe('btPairTest', function() {
it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0700', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0700', 0, async function (done) {
function PinRequiredParam(data) { function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId, false); let ret = bluetooth.setDevicePairingConfirmation(data.deviceId, false);
expect(ret).assertFalse();
} }
try { try {
bluetooth.BLE.on('pinRequired', PinRequiredParam); bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("11:22:55:66:33:44"); bluetooth.pairDevice("99:55:22:88:66:11");
await sleep(2000); await sleep(2000);
expect(true).assertEqual(result == false);
bluetooth.BLE.off('pinRequired', PinRequiredParam); bluetooth.BLE.off('pinRequired', PinRequiredParam);
} catch(err) { } catch(err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -254,13 +253,13 @@ describe('btPairTest', function() { ...@@ -254,13 +253,13 @@ describe('btPairTest', function() {
it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0800', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_PAIR_0800', 0, async function (done) {
function PinRequiredParam(data) { function PinRequiredParam(data) {
console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data)); console.info("[bluetooth_js] pinRequired on:" + JSON.stringify(data));
bluetooth.setDevicePairingConfirmation(data.deviceId, true); let ret = bluetooth.setDevicePairingConfirmation(data.deviceId, true);
expect(ret).assertTrue();
} }
try { try {
bluetooth.BLE.on('pinRequired', PinRequiredParam); bluetooth.BLE.on('pinRequired', PinRequiredParam);
let result = bluetooth.pairDevice("11:22:55:66:33:44"); bluetooth.pairDevice("66:88:33:55:22:99");
await sleep(2000); await sleep(1000);
expect(true).assertEqual(result == false);
bluetooth.BLE.off('pinRequired', PinRequiredParam); bluetooth.BLE.off('pinRequired', PinRequiredParam);
} catch(err) { } catch(err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -282,12 +281,12 @@ describe('btPairTest', function() { ...@@ -282,12 +281,12 @@ describe('btPairTest', function() {
+'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state);
} }
bluetooth.BLE.on('bondStateChange', BondStateParam); bluetooth.BLE.on('bondStateChange', BondStateParam);
let result = bluetooth.pairDevice("11:22:55:66:33:44"); bluetooth.pairDevice("58:62:22:23:69:54");
expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue(); expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue();
expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue(); expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue();
expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue(); expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue();
bluetooth.BLE.off('bondStateChange', BondStateParam); bluetooth.BLE.off('bondStateChange', BondStateParam);
done() done();
}) })
}) })
......
...@@ -20,13 +20,18 @@ import btPairTest from './BtPair.test.js' ...@@ -20,13 +20,18 @@ import btPairTest from './BtPair.test.js'
import btScanModeTest from './BtScanMode.test.js' import btScanModeTest from './BtScanMode.test.js'
import btManagerDiscoveryTest from './BtManagerDiscovery.test.js' import btManagerDiscoveryTest from './BtManagerDiscovery.test.js'
import btManagerPairTest from './BtManagerPair.test.js' import btManagerPairTest from './BtManagerPair.test.js'
import bluetoothBleTest from './BluetoothBle.test.js'
import btConnectionTest from './BtConnection.test.js'
export default function testsuite() { export default function testsuite() {
bluetoothBleTest()
btConnectionTest()
btPairTest()
btBleScanTest() btBleScanTest()
btDiscoveryTest() btDiscoveryTest()
btManagerBleScanTest() btManagerBleScanTest()
btPairTest()
btScanModeTest() btScanModeTest()
btManagerDiscoveryTest() btManagerDiscoveryTest()
btManagerPairTest() btManagerPairTest()
} }
...@@ -88,47 +88,31 @@ ...@@ -88,47 +88,31 @@
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.USE_BLUETOOTH", "name": "ohos.permission.USE_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
}, },
{ {
"name": "ohos.permission.MANAGE_BLUETOOTH", "name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.DISCOVER_BLUETOOTH", "name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "", "reason": ""
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.LOCATION", "name": "ohos.permission.LOCATION",
"reason": "", "reason": ""
"usedScene": { },
"ability": [ {
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" "name": "ohos.permission.ACCESS_BLUETOOTH",
], "reason": ""
"when": "inuse" },
} {
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": ""
},
{
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason": ""
} }
], ],
"testRunner": { "testRunner": {
......
/*
* 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.access';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btAccessTest() {
describe('btAccessTest', function() {
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
beforeAll(function () {
console.info('beforeAll called')
})
beforeEach(function() {
console.info('beforeEach called')
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100
* @tc.name test enableBluetooth
* @tc.desc Test enableBluetooth api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100', 0, async function (done) {
let state = bluetooth.getState();
console.info('[bluetooth_js] bluetooth state = '+ JSON.stringify(state));
if(state != bluetooth.BluetoothState.STATE_OFF) {
bluetooth.disableBluetooth();
await sleep(10000);
let closeSt = bluetooth.getState();
console.info('[bluetooth_js] bluetooth disable state ='+ JSON.stringify(closeSt));
expect(closeSt).assertEqual(bluetooth.BluetoothState.STATE_OFF);
} else {
console.info('[bluetooth_js] bluetooth state is OFF');
}
try {
bluetooth.enableBluetooth();
await sleep(10000);
} catch {
console.error(`[bluetooth_js] enable StateChange error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
let openSt = bluetooth.getState();
console.info('[bluetooth_js] bluetooth enable state ='+ JSON.stringify(openSt));
expect(openSt).assertEqual(bluetooth.BluetoothState.STATE_ON);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200
* @tc.name test disableBluetooth
* @tc.desc Test disableBluetooth api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200', 0, async function (done) {
let state = bluetooth.getState();
console.info('[bluetooth_js] bluetooth state = '+ JSON.stringify(state));
if(state != bluetooth.BluetoothState.STATE_ON) {
bluetooth.enableBluetooth();
await sleep(10000);
let openSt = bluetooth.getState();
console.info('[bluetooth_js] bluetooth enable state ='+ JSON.stringify(openSt));
expect(openSt).assertEqual(bluetooth.BluetoothState.STATE_ON);
} else {
console.info('[bluetooth_js] bluetooth state is ON');
}
try {
bluetooth.disableBluetooth();
await sleep(10000);
} catch {
console.error(`[bluetooth_js] disable StateChange error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
let closeSt = bluetooth.getState();
console.info('[bluetooth_js] bluetooth disable state ='+ JSON.stringify(closeSt));
expect(closeSt).assertEqual(bluetooth.BluetoothState.STATE_OFF);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300
* @tc.name test getState
* @tc.desc Test getState api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300', 0, async function (done) {
try {
let state = bluetooth.getState();
expect(true).assertTrue(0 <= state <= 6);
} catch {
console.error("[bluetooth_js] bluetooth getState errCode:" + err.code + ",bluetooth getState errMessage:" + err.message);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400
* @tc.name test on 'stateChange'
* @tc.desc Test on 'stateChange' api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400', 0, async function (done) {
function onReceiveEvent(data) {
console.info('bluetooth state001 =' + JSON.stringify(data));
}
try {
await bluetooth.on('stateChange', onReceiveEvent);
let state = bluetooth.getState();
console.info('[bluetooth_js] get bluetooth state' + JSON.stringify(state));
if (state != bluetooth.BluetoothState.STATE_ON) {
let enable = bluetooth.enableBluetooth();
await sleep(10000);
console.info('[bluetooth_js] bluetooth enable' + JSON.stringify(enable));
expect(enable).assertTrue();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] enable state ' + JSON.stringify(state1));
expect(state1).assertEqual(bluetooth.BluetoothState.STATE_ON);
}
} catch (error) {
console.error(`[bluetooth_js]enable StateChange error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
bluetooth.off('stateChange', onReceiveEvent);
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500
* @tc.name test off 'stateChange'
* @tc.desc Test off 'stateChange' api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500', 0, async function (done) {
function onReceiveEvent(data) {
console.info('bluetooth state001 =' + JSON.stringify(data));
}
try {
await bluetooth.on('stateChange', onReceiveEvent);
await sleep(3000);
await bluetooth.off('stateChange', onReceiveEvent);
let state = bluetooth.getState();
console.info('[bluetooth_js] get bluetooth state001' + JSON.stringify(state));
if (state != bluetooth.BluetoothState.STATE_OFF) {
let disable = bluetooth.disableBluetooth();
await sleep(10000);
console.info('[bluetooth_js] bluetooth disable001' + JSON.stringify(disable));
expect(disable).assertTrue();
let state1 = bluetooth.getState();
console.info('[bluetooth_js] disable state001 ' + JSON.stringify(state1));
expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF);
}
} catch (error) {
console.error(`[bluetooth_js]disable StateChange error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('2900099');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600
* @tc.name test BluetoothState
* @tc.desc Test BluetoothState api10
* @tc.type Function
* @tc.level Level 0
*/
it('SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600', 0, async function (done) {
let STATE_ON = bluetooth.BluetoothState.STATE_ON;
console.info("[bluetooth_js]STATE_ON : " + JSON.stringify(STATE_ON));
expect(true).assertTrue(STATE_ON == 2);
let STATE_OFF = bluetooth.BluetoothState.STATE_OFF;
console.info("[bluetooth_js]STATE_OFF : " + JSON.stringify(STATE_OFF));
expect(true).assertTrue(STATE_OFF == 0);
let STATE_TURNING_ON = bluetooth.BluetoothState.STATE_TURNING_ON;
console.info("[bluetooth_js]STATE_TURNING_ON : " + JSON.stringify(STATE_TURNING_ON));
expect(true).assertTrue(STATE_TURNING_ON == 1);
let STATE_TURNING_OFF = bluetooth.BluetoothState.STATE_TURNING_OFF;
console.info("[bluetooth_js]STATE_TURNING_OFF : " + JSON.stringify(STATE_TURNING_OFF));
expect(true).assertTrue(STATE_TURNING_OFF == 3);
let STATE_BLE_TURNING_ON = bluetooth.BluetoothState.STATE_BLE_TURNING_ON;
console.info("[bluetooth_js]STATE_BLE_TURNING_ON : " + JSON.stringify(STATE_BLE_TURNING_ON));
expect(true).assertTrue(STATE_BLE_TURNING_ON == 4);
let STATE_BLE_ON = bluetooth.BluetoothState.STATE_BLE_ON;
console.info("[bluetooth_js]STATE_BLE_ON : " + JSON.stringify(STATE_BLE_ON));
expect(true).assertTrue(STATE_BLE_ON == 5);
let STATE_BLE_TURNING_OFF = bluetooth.BluetoothState.STATE_BLE_TURNING_OFF;
console.info("[bluetooth_js]STATE_BLE_TURNING_OFF : " + JSON.stringify(STATE_BLE_TURNING_OFF));
expect(true).assertTrue(STATE_BLE_TURNING_OFF == 6);
done();
})
})
}
\ No newline at end of file
/*
* 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.socket';
import btAccess from '@ohos.bluetooth.access';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
export default function btSocketTest() {
describe('btSocketTest', function() {
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
async function tryToEnableBt() {
let sta = btAccess.getState();
switch (sta) {
case 0:
btAccess.enableBluetooth();
await sleep(10000);
let sta1 = btAccess.getState();
console.info('[bluetooth_js] bt turn off:' + JSON.stringify(sta1));
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:
btAccess.enableBluetooth();
await sleep(10000);
let sta2 = btAccess.getState();
console.info('[bluetooth_js] bt turning off:' + JSON.stringify(sta2));
break;
default:
console.info('[bluetooth_js] enable success');
}
}
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')
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100
* @tc.name test SppListen
* @tc.desc Test SppListen api10
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100', 0, async function (done) {
let SppOptions = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
} else {
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
try {
await bluetooth.sppListen('server1', SppOptions, serverSocket);
} catch (error) {
console.error(`[bluetooth_js]SPPListen error, code is ${error.code},message is ${error.message}`);
expect(true).assertEqual(error == null);
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200
* @tc.name testSppAccept
* @tc.desc Test SppAccept api10
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200', 0, async function (done) {
let SppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code02: ' + code);
} else {
console.log('bluetooth serverSocket Number02:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
bluetooth.sppListen('server_accept', SppOption, serverSocket);
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
clientNumber = number;
expect(true).assertEqual(clientNumber != -1);
}
}
try {
bluetooth.sppAccept(serverNumber, acceptClientSocket);
} catch (error) {
console.error(`[bluetooth_js]SPPAccept error, code is ${error.code},message is ${error.message}`);
expect(error.code).assertEqual('401');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300
* @tc.name test SppConnect
* @tc.desc Test SppConnect api10
* @tc.type Function
* @tc.level Level 1
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300', 0, async function (done) {
let sppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0
};
try {
await bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function (code, number) {
if (code) {
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppConnect Number:'
+ JSON.stringify(number));
expect(true).assertEqual(number != null);
}
});
} catch (error) {
console.error(`[bluetooth_js]SPPConnect error, code is ${error.code},message is ${error.message}`);
expect(true).assertEqual(error == null);
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400
* @tc.name test sppReadOn
* @tc.desc Test On and Off api10
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400', 0, async function (done) {
let SppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
} else {
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
clientNumber = number;
expect(true).assertEqual(clientNumber != -1);
}
}
function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]);
}
try {
bluetooth.sppListen('server04', SppOption, serverSocket);
bluetooth.sppAccept(serverNumber, acceptClientSocket);
bluetooth.on('sppRead', clientNumber, dataRead);
bluetooth.off('sppRead', clientNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('401');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800
* @tc.name test sppReadOn
* @tc.desc Test On and Off api10
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800', 0, async function (done) {
let SppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
} else {
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
clientNumber = number;
expect(true).assertEqual(clientNumber != -1);
}
}
function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]);
}
try {
bluetooth.sppListen('server08', SppOption, serverSocket);
bluetooth.sppAccept(serverNumber, acceptClientSocket);
bluetooth.on('sppRead', clientNumber, dataRead);
bluetooth.off('sppRead', clientNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('401');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500
* @tc.name testsppCloseServerSocket
* @tc.desc Test sppCloseServerSocket api10 by callback.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500', 0, async function (done) {
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code10: ' + JSON.stringify(code));
}else{
console.log('bluetooth serverSocket Number:'+ JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber!=null);
}
}
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
await bluetooth.sppListen('server1', SppOption, serverSocket);
try {
bluetooth.sppCloseServerSocket(serverNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(true).assertEqual(error == null);
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600
* @tc.name testsppCloseClientSocket
* @tc.desc Test sppCloseClientSocket api10 by callback.
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600', 0, async function (done) {
let SppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
} else {
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
clientNumber = number;
expect(true).assertEqual(clientNumber != -1);
}
}
try {
bluetooth.sppListen('server06', SppOption, serverSocket);
bluetooth.sppAccept(serverNumber, acceptClientSocket);
bluetooth.sppCloseClientSocket(clientNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('401');
}
done();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700
* @tc.name testSppWrite
* @tc.desc Test sppWrite api10
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700', 0, async function (done) {
let SppOption = {
uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: false, type: bluetooth.SppType.SPP_RFCOMM
};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
} else {
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(serverNumber != -1);
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
clientNumber = number;
expect(true).assertEqual(clientNumber != -1);
}
}
let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer);
data[0] = 123;
try {
bluetooth.sppListen('server07', SppOption, serverSocket);
bluetooth.sppAccept(serverNumber, acceptClientSocket);
bluetooth.sppWrite(clientNumber, arrayBuffer);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
expect(err.code).assertEqual('401');
}
done();
})
})
}
\ No newline at end of file
...@@ -81,9 +81,9 @@ describe('btSppTest', function() { ...@@ -81,9 +81,9 @@ describe('btSppTest', function() {
serverNumber = number; serverNumber = number;
expect(true).assertEqual(number!=null); expect(true).assertEqual(number!=null);
} }
done();
} }
await bluetooth.sppListen('server1', SppOption, serverSocket); bluetooth.sppListen('server1', SppOption, serverSocket);
done()
}) })
/** /**
...@@ -105,9 +105,9 @@ describe('btSppTest', function() { ...@@ -105,9 +105,9 @@ describe('btSppTest', function() {
serverNumber = number; serverNumber = number;
expect(true).assertEqual(number!=null); expect(true).assertEqual(number!=null);
} }
done();
} }
await bluetooth.sppListen('server1', sppOption, serverSocket); bluetooth.sppListen('server1', sppOption, serverSocket);
done();
}) })
/** /**
...@@ -154,9 +154,9 @@ describe('btSppTest', function() { ...@@ -154,9 +154,9 @@ describe('btSppTest', function() {
serverNumber = number; serverNumber = number;
expect(true).assertEqual(serverNumber!=null); expect(true).assertEqual(serverNumber!=null);
} }
done();
} }
await bluetooth.sppListen('server1', sppOption, serverSocket); bluetooth.sppListen('server1', sppOption, serverSocket);
done();
}) })
/** /**
...@@ -175,9 +175,9 @@ describe('btSppTest', function() { ...@@ -175,9 +175,9 @@ describe('btSppTest', function() {
console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number)); console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number));
expect(true).assertEqual(number!=null); expect(true).assertEqual(number!=null);
} }
done();
} }
await bluetooth.sppAccept(0, acceptClientSocket); bluetooth.sppAccept(0, acceptClientSocket);
done();
}) })
/** /**
......
...@@ -13,14 +13,20 @@ ...@@ -13,14 +13,20 @@
* limitations under the License. * limitations under the License.
*/ */
import btAccessTest from './BluetoothAccess.test.js'
import btManagerSwitchTest from './BtManagerSetSwitch.test.js'
import btLocalNameTest from './BtSetLocalName.test.js' import btLocalNameTest from './BtSetLocalName.test.js'
import btSwitchTest from './BtSetSwitch.test.js' import btSwitchTest from './BtSetSwitch.test.js'
import btSppTest from './BtSpp.test.js' import btSppTest from './BtSpp.test.js'
import btSubscBleTest from './BtSysSubscBle.test.js' import btSubscBleTest from './BtSysSubscBle.test.js'
import btManagerSppTest from './BtManagerSpp.test.js' import btManagerSppTest from './BtManagerSpp.test.js'
import btManagerSwitchTest from './BtManagerSetSwitch.test.js' import btSocketTest from './BtSocket.test.js'
import btConstantTest from './BluetoothConstant.test.js'
export default function testsuite() { export default function testsuite() {
btAccessTest()
btConstantTest()
btSocketTest()
btLocalNameTest() btLocalNameTest()
btSwitchTest() btSwitchTest()
btSppTest() btSppTest()
......
...@@ -323,6 +323,92 @@ export default function nfcIsoDepTagTest() { ...@@ -323,6 +323,92 @@ export default function nfcIsoDepTagTest() {
expect(tag.NDEF_FORMATABLE).assertEqual(7); expect(tag.NDEF_FORMATABLE).assertEqual(7);
}) })
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0900
* @tc.name Test startHCE
* @tc.desc startHCE
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_0900', 0, function () {
let starthce ;
let aidList = "test"
try {
starthce = cardEmulation.startHCE(aidList);
console.info('[NFC_test] cardEmulationnfc9 hasHceCapability type ->' + starthce )
expect(starthce).assertTrue();
} catch (error) {
console.info('[NFC_test] cardEmulationnfc9 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1000
* @tc.name Test start
* @tc.desc start.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1000', 0, function () {
let Start ;
let aidList = "test"
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
try {
Start = cardEmulation.start(elementName, aidList);
console.info('[NFC_test] cardEmulationnfc10 Start pass' )
} catch (error) {
console.info('[NFC_test] cardEmulationnfc10 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1100
* @tc.name Test stopHCE
* @tc.desc stopHCE.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1100', 0, function () {
let stophce ;
try {
stophce = cardEmulation.stopHCE();
console.info('[NFC_test] cardEmulationnfc11 hasHceCapability type ->' + starthce )
expect(starthce).assertTrue();
} catch (error) {
console.info('[NFC_test] cardEmulationnfc11 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1200
* @tc.name Test stop
* @tc.desc stop.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1200', 0, function () {
let Stop ;
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
try {
Stop = cardEmulation.stop(elementName);
console.info('[NFC_test] cardEmulationnfc12 stop pass' )
} catch (error) {
console.info('[NFC_test] cardEmulationnfc12 HCE not delivered')
}
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
\ No newline at end of file
...@@ -674,6 +674,36 @@ export default function nfcTagABFVTest() { ...@@ -674,6 +674,36 @@ export default function nfcTagABFVTest() {
} }
}) })
/**
* @tc.number SUB_Communication_NFC_nfctage_js_2300
* @tc.name Test registerForegroundDispatch
* @tc.desc This interface registerForegroundDispatch.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_2300', 0, function () {
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
let discTech = [1, 2, 4];
try {
let recvNfcTagFunc = tagInfo => {
console.info("[NFC_test] controller1 nfc state receive state ->" + tagInfo);
expect(tagInfo != null).assertTrue();
}
tag.registerForegroundDispatch(elementName, discTech, recvNfcTagFunc);
console.info('[NFC_test] nfc registerForegroundDispatch pass')
tag.unregisterForegroundDispatch(elementName);
console.info('[NFC_test] nfc unregisterForegroundDispatch pass')
} catch (error) {
console.info('nfc registerForegroundDispatch error' + error)
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
\ No newline at end of file
# Copyright (C) 2023 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsnfcSEServiceTest") {
hap_profile = "./src/main/config.json"
deps = [
":nfc_js_assets",
":nfc_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsnfcSEServiceTest"
part_name = "nfc"
subsystem_name = "communication"
}
ohos_js_assets("nfc_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("nfc_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for nfc js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "600000",
"testcase-timeout": "600000",
"bundle-name": "ohos.acts.communication.nfc.nfcdevice",
"package-name": "ohos.acts.communication.nfc.nfcdevice"
},
"kits": [
{
"test-file-name": [
"ActsnfcSEServiceTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"svc nfc enable",
"power-shell wakeup",
"power-shell setmode 602"
]
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.communication.nfc.nfcdevice",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.nfc.nfcdevice",
"name": ".entry",
"mainAbility": ".MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "nfc_standard",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.NFC_CARD_EMULATION",
"reason": "use ohos.permission.SET_nfc_INFO"
},
{
"name": "ohos.permission.NFC_TAG",
"reason": "use ohos.permission.NFC_TAG"
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"srcPath": ""
}
}
/*
* Copyright (C) 2023 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.
*/
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
/*
* Copyright (C) 2023 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
/*
* Copyright (C) 2023 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.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (C) 2023 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.
*/
export default {
data: {
title: '',
myTimeout: 25000
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
console.info('onReady finish')
},
}
/*
* Copyright (c) 2023 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (c) 2023 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* Copyright (c) 2023 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.info('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* Copyright (C) 2023 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 newSEServicetest from './newSEService.test.js';
import openSessionTest from './openSession.test.js';
import openBasicChanneltest from './openBasicChannel.test.js';
import openLogicalChanneltest from './openLogicalChannel.test.js';
import channelCallbacktest from './channelCallback.test.js';
import parameter from '@ohos.systemparameter';
let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
export default function testsuite() {
if (info != "false")
{
newSEServicetest();
openSessionTest();
openBasicChanneltest();
openLogicalChanneltest();
channelCallbacktest();
}
}
\ No newline at end of file
{
"string": [
{
"name": "app_name",
"value": "OsAccountTest"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
...@@ -165,9 +165,9 @@ export default function actsWifiManagerCandidateNetWorkTest() { ...@@ -165,9 +165,9 @@ export default function actsWifiManagerCandidateNetWorkTest() {
"identity": "aaa", "identity": "aaa",
"anonymousIdentity": "bbb", "anonymousIdentity": "bbb",
"password": "12345678", "password": "12345678",
"caCertAliases": "ddd", "caCertAlias": "ddd",
"caPath": "eee", "caPath": "eee",
"clientCertAliases": "fff", "clientCertAlias": "fff",
"certEntry": new Uint8Array(), "certEntry": new Uint8Array(),
"certPassword": "12345678", "certPassword": "12345678",
"altSubjectMatch": "ggg", "altSubjectMatch": "ggg",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册