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

!2809 【communication】修改BT JS L2测试用例代码规范

Merge pull request !2809 from 权力/cherry-pick-1648025011
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
var MajorMinorClass = { let MajorMinorClass = {
COMPUTER_UNCATEGORIZED : 0x0100, COMPUTER_UNCATEGORIZED : 0x0100,
COMPUTER_DESKTOP : 0x0104, COMPUTER_DESKTOP : 0x0104,
COMPUTER_SERVER : 0x0108, COMPUTER_SERVER : 0x0108,
...@@ -106,10 +106,11 @@ var MajorMinorClass = { ...@@ -106,10 +106,11 @@ var MajorMinorClass = {
HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C
}; };
describe('bluetoothhostTest', function() { describe('bluetoothhostTest', function() {
var gattServer = null; let gattServer = null;
var gattClient = null; let gattClient = null;
beforeAll(function () { beforeAll(function () {
console.info('beforeAll called') console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
...@@ -131,11 +132,10 @@ describe('bluetoothhostTest', function() { ...@@ -131,11 +132,10 @@ describe('bluetoothhostTest', function() {
} }
async function tryToEnableBt() { async function tryToEnableBt() {
var sta = bluetooth.getState(); let sta = bluetooth.getState();
switch(sta){ switch(sta){
case 0: case 0:
var enable = bluetooth.enableBluetooth(); bluetooth.enableBluetooth();
console.info('[bluetooth_js] enable0 = '+ JSON.stringify(enable));
await sleep(3000); await sleep(3000);
break; break;
case 1: case 1:
...@@ -146,8 +146,7 @@ describe('bluetoothhostTest', function() { ...@@ -146,8 +146,7 @@ describe('bluetoothhostTest', function() {
console.info('[bluetooth_js] state is On:'+ JSON.stringify(sta)); console.info('[bluetooth_js] state is On:'+ JSON.stringify(sta));
break; break;
case 3: case 3:
var enable = bluetooth.enableBluetooth(); bluetooth.enableBluetooth();
console.info('[bluetooth_js] enable0 = '+ JSON.stringify(enable));
await sleep(3000); await sleep(3000);
break; break;
default: default:
...@@ -159,7 +158,6 @@ describe('bluetoothhostTest', function() { ...@@ -159,7 +158,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_ENABLE_0001 * @tc.number SUB_COMMUNACATION_bluetooth_ENABLE_0001
* @tc.name testEnableBluetooth * @tc.name testEnableBluetooth
* @tc.desc Test EnableBluetooth api by promise. * @tc.desc Test EnableBluetooth api by promise.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -174,7 +172,7 @@ describe('bluetoothhostTest', function() { ...@@ -174,7 +172,7 @@ describe('bluetoothhostTest', function() {
} }
} }
await tryToEnableBt(); await tryToEnableBt();
var state = bluetooth.getState(); let state = bluetooth.getState();
expect(state).assertEqual(2); expect(state).assertEqual(2);
await bluetooth.off('stateChange', result => { await bluetooth.off('stateChange', result => {
expect(true).assertEqual(result ==null); expect(true).assertEqual(result ==null);
...@@ -187,7 +185,6 @@ describe('bluetoothhostTest', function() { ...@@ -187,7 +185,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001 * @tc.number SUB_COMMUNACATION_bluetooth_START_BLUETOOTH_DISCOVERY_0001
* @tc.name testClassicStartBluetoothDiscovery * @tc.name testClassicStartBluetoothDiscovery
* @tc.desc Test ClassicStartBluetoothDiscovery api. * @tc.desc Test ClassicStartBluetoothDiscovery api.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -215,7 +212,6 @@ describe('bluetoothhostTest', function() { ...@@ -215,7 +212,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001 * @tc.number SUB_COMMUNACATION_bluetooth_START_BLESCAN_WITHOUT_PARAM_0001
* @tc.name testClassicStartBLEScan * @tc.name testClassicStartBLEScan
* @tc.desc Test ClassicStartBLEScan api. * @tc.desc Test ClassicStartBLEScan api.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -236,7 +232,7 @@ describe('bluetoothhostTest', function() { ...@@ -236,7 +232,7 @@ describe('bluetoothhostTest', function() {
expect(true).assertEqual(result ==null); expect(true).assertEqual(result ==null);
done(); done();
}); });
var result = bluetooth.BLE.stopBLEScan(); let result = bluetooth.BLE.stopBLEScan();
console.info("[bluetooth_js] onStopBLEScan -> " + JSON.stringify(result)); console.info("[bluetooth_js] onStopBLEScan -> " + JSON.stringify(result));
console.info('[bluetooth_js] BLE scan start end'); console.info('[bluetooth_js] BLE scan start end');
resolve() resolve()
...@@ -250,7 +246,6 @@ describe('bluetoothhostTest', function() { ...@@ -250,7 +246,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001 * @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0001
* @tc.name testClassicPairDevice * @tc.name testClassicPairDevice
* @tc.desc Test ClassicPairDevice api. * @tc.desc Test ClassicPairDevice api.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -264,7 +259,7 @@ describe('bluetoothhostTest', function() { ...@@ -264,7 +259,7 @@ describe('bluetoothhostTest', function() {
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
done(); done();
}); });
var enable = bluetooth.pairDevice("00:00:00:00:00:00") let enable3 = bluetooth.pairDevice("00:00:00:00:00:00")
bluetooth.BLE.off('pinRequired', result => { bluetooth.BLE.off('pinRequired', result => {
console.info("[bluetooth_js] pinRequired off:" + JSON.stringify(result)); console.info("[bluetooth_js] pinRequired off:" + JSON.stringify(result));
expect(true).assertEqual(result ==null); expect(true).assertEqual(result ==null);
...@@ -276,7 +271,6 @@ describe('bluetoothhostTest', function() { ...@@ -276,7 +271,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002 * @tc.number SUB_COMMUNACATION_bluetooth_PAIR_DEVICE_0002
* @tc.name testClassicPairDevice * @tc.name testClassicPairDevice
* @tc.desc Test ClassicPairDevice api. * @tc.desc Test ClassicPairDevice api.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -290,7 +284,7 @@ describe('bluetoothhostTest', function() { ...@@ -290,7 +284,7 @@ describe('bluetoothhostTest', function() {
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
done(); done();
}); });
var enable = bluetooth.pairDevice("00:00:00:00:00:00") let enable4 = bluetooth.pairDevice("00:00:00:00:00:00")
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();
...@@ -305,7 +299,6 @@ describe('bluetoothhostTest', function() { ...@@ -305,7 +299,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001 * @tc.number SUB_COMMUNACATION_bluetooth_SPP_LISTEN_0001
* @tc.name testSppListen * @tc.name testSppListen
* @tc.desc Test SppListen api by callback. * @tc.desc Test SppListen api by callback.
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -332,7 +325,6 @@ describe('bluetoothhostTest', function() { ...@@ -332,7 +325,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001 * @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_READ_ON_0001
* @tc.name testonCharacteristicReadOn * @tc.name testonCharacteristicReadOn
* @tc.desc Test CharacteristicReadOn api . * @tc.desc Test CharacteristicReadOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -345,14 +337,14 @@ describe('bluetoothhostTest', function() { ...@@ -345,14 +337,14 @@ describe('bluetoothhostTest', function() {
console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId + console.info('[bluetooth_js] CharRedReq deviceId: ' + data.deviceId +
'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' + 'transId:' + data.transId + 'offset:' + data.offset + 'charUuid:' +
data.characteristicUuid + 'serviceUuid:' + data.serviceUuid); data.characteristicUuid + 'serviceUuid:' + data.serviceUuid);
var serverResponse = { let serverResponse = {
"deviceId": data.deviceId, "deviceId": data.deviceId,
"transId": data.transId, "transId": data.transId,
"status": 0, "status": 0,
"offset": data.offset, "offset": data.offset,
"value": str2ab("characteristic read response", data.offset), "value": str2ab("characteristic read response", data.offset),
}; };
var result = gattServer.sendResponse(serverResponse); let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true"); expect(JSON.stringify(result)).assertContain("true");
}); });
}catch(e) { }catch(e) {
...@@ -375,7 +367,6 @@ describe('bluetoothhostTest', function() { ...@@ -375,7 +367,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001 * @tc.number SUB_COMMUNACATION_bluetoothble_CHARAC_WRITE_ON_0001
* @tc.name testonCharacteristicwriteOn * @tc.name testonCharacteristicwriteOn
* @tc.desc Test CharacteristicwriteOn api . * @tc.desc Test CharacteristicwriteOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -397,14 +388,14 @@ describe('bluetoothhostTest', function() { ...@@ -397,14 +388,14 @@ describe('bluetoothhostTest', function() {
return; return;
} }
console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`) console.log(`data.value is ArraryBuffer: ${ab2hex(data.value)}`)
var serverResponse = { let serverResponse = {
"deviceId": data.deviceId, "deviceId": data.deviceId,
"transId": data.transId, "transId": data.transId,
"status": 0, "status": 0,
"offset": data.offset, "offset": data.offset,
"value": data.value, "value": data.value,
}; };
var result = gattServer.sendResponse(serverResponse); let result = gattServer.sendResponse(serverResponse);
expect(JSON.stringify(result)).assertContain("true"); expect(JSON.stringify(result)).assertContain("true");
}); });
}catch(e) { }catch(e) {
...@@ -427,7 +418,6 @@ describe('bluetoothhostTest', function() { ...@@ -427,7 +418,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001 * @tc.number SUB_COMMUNACATION_bluetooth_DESC_READ_ON_0001
* @tc.name testDescriptorReadOn * @tc.name testDescriptorReadOn
* @tc.desc Test DescriptorReadOn api . * @tc.desc Test DescriptorReadOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -464,7 +454,6 @@ describe('bluetoothhostTest', function() { ...@@ -464,7 +454,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001 * @tc.number SUB_COMMUNACATION_bluetooth_DESC_WRITE_ON_0001
* @tc.name testDescriptorWriteOn * @tc.name testDescriptorWriteOn
* @tc.desc Test DescriptorWriteOn api . * @tc.desc Test DescriptorWriteOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -501,7 +490,6 @@ describe('bluetoothhostTest', function() { ...@@ -501,7 +490,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001 * @tc.number SUB_COMMUNACATION_bluetooth_CONNE_STATE_CHANGE_ON_0001
* @tc.name testConnectStateChangeOn * @tc.name testConnectStateChangeOn
* @tc.desc Test ConnectStateChangeOn api . * @tc.desc Test ConnectStateChangeOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -536,7 +524,6 @@ describe('bluetoothhostTest', function() { ...@@ -536,7 +524,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001 * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CHAR_CHANGE_ON_0001
* @tc.name testBLECharacteristicChangeOn * @tc.name testBLECharacteristicChangeOn
* @tc.desc Test BLECharacteristicChangeOn api . * @tc.desc Test BLECharacteristicChangeOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -570,7 +557,6 @@ describe('bluetoothhostTest', function() { ...@@ -570,7 +557,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001 * @tc.number SUB_COMMUNACATION_bluetooth_BLE_CONNE_STATE_CHANGE_ON_0001
* @tc.name testBLEConnectionStateChangeOn * @tc.name testBLEConnectionStateChangeOn
* @tc.desc Test BLEConnectionStateChangeOn api . * @tc.desc Test BLEConnectionStateChangeOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -605,7 +591,6 @@ describe('bluetoothhostTest', function() { ...@@ -605,7 +591,6 @@ describe('bluetoothhostTest', function() {
* @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001 * @tc.number SUB_COMMUNACATION_bluetoothble_SPP_READ_ON_0001
* @tc.name testonsppReadOn * @tc.name testonsppReadOn
* @tc.desc Test sppReadOn api . * @tc.desc Test sppReadOn api .
* @tc.author zhangyujie zwx1079266
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
...@@ -635,4 +620,3 @@ describe('bluetoothhostTest', function() { ...@@ -635,4 +620,3 @@ describe('bluetoothhostTest', function() {
}) })
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册