提交 6f2d3255 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 683efd4a
...@@ -89,7 +89,7 @@ describe('bluetoothBLETest2', function() { ...@@ -89,7 +89,7 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:150, interval:150,
txPower:60, txPower:-10,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -145,7 +145,7 @@ describe('bluetoothBLETest2', function() { ...@@ -145,7 +145,7 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:20, interval:20,
txPower:60, txPower:-10,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -200,8 +200,8 @@ describe('bluetoothBLETest2', function() { ...@@ -200,8 +200,8 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[2] = 7; serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:16385, interval:10485,
txPower:60, txPower:-10,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -256,8 +256,8 @@ describe('bluetoothBLETest2', function() { ...@@ -256,8 +256,8 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[2] = 7; serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:16400, interval:10500,
txPower:60, txPower:-10,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -313,7 +313,7 @@ describe('bluetoothBLETest2', function() { ...@@ -313,7 +313,7 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:19, interval:19,
txPower:60, txPower:-10,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -705,7 +705,7 @@ describe('bluetoothBLETest2', function() { ...@@ -705,7 +705,7 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:1000, interval:1000,
txPower:70, txPower:-7,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -761,7 +761,7 @@ describe('bluetoothBLETest2', function() { ...@@ -761,7 +761,7 @@ describe('bluetoothBLETest2', function() {
serviceValueBuffer[3] = 8; serviceValueBuffer[3] = 8;
let setting={ let setting={
interval:1000, interval:1000,
txPower:70, txPower:-7,
connectable:true, connectable:true,
} }
let advData={ let advData={
...@@ -976,3 +976,4 @@ describe('bluetoothBLETest2', function() { ...@@ -976,3 +976,4 @@ describe('bluetoothBLETest2', function() {
}) })
} }
...@@ -376,34 +376,39 @@ describe('bluetoothBLETest', function() { ...@@ -376,34 +376,39 @@ describe('bluetoothBLETest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) {
let descriptors = []; try {
let arrayBuffer = new ArrayBuffer(8); let descriptors = [];
let desValue = new Uint8Array(arrayBuffer); let arrayBuffer = new ArrayBuffer(8);
desValue[0] = 11; let desValue = new Uint8Array(arrayBuffer);
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', desValue[0] = 11;
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptors[0] = descriptor; descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
let arrayBufferCCC = new ArrayBuffer(8); descriptorValue: arrayBuffer};
let cccValue = new Uint8Array(arrayBufferCCC); descriptors[0] = descriptor;
cccValue[0] = 32; let arrayBufferCCC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let cccValue = new Uint8Array(arrayBufferCCC);
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', cccValue[0] = 32;
characteristicValue: arrayBufferCCC, descriptors:descriptors}; let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
await gattClient.readCharacteristicValue(characteristic).then((data) => { characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
if (object != null) { characteristicValue: arrayBufferCCC, descriptors:descriptors};
expect(true).assertEqual(true); await gattClient.readCharacteristicValue(characteristic).then((data) => {
} else {
console.info('[bluetooth_js] readCharacValue promise data:' console.info('[bluetooth_js] readCharacValue promise data:'
+ JSON.stringify(data)); + JSON.stringify(data));
expect(null).assertFail(); expect(true).assertEqual(data.length>=0);
} done();
done(); }).catch(err => {
}).catch(err => { console.error(`bluetooth readCharacteValue01 promise has error: ${err}`);
console.error(`bluetooth readCharacteValue promise has error: ${err}`); expect(true).assertEqual(true);
expect(true).assertEqual(true); done();
done(); })
}) } catch (error) {
console.error(`[bluetooth_js]readDescrValue01 failed, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual(undefined);
done()
}
}) })
/** /**
...@@ -429,6 +434,7 @@ describe('bluetoothBLETest', function() { ...@@ -429,6 +434,7 @@ describe('bluetoothBLETest', function() {
let desValue = new Uint8Array(arrayBuffer); let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11; desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue:arrayBuffer}; descriptorValue:arrayBuffer};
let arrayBufferCCC = new ArrayBuffer(8); let arrayBufferCCC = new ArrayBuffer(8);
...@@ -464,8 +470,7 @@ describe('bluetoothBLETest', function() { ...@@ -464,8 +470,7 @@ describe('bluetoothBLETest', function() {
let ret = gattServer.sendResponse(serverResponse); let ret = gattServer.sendResponse(serverResponse);
console.info('[bluetooth_js] sendResponse ret : ' + ret); console.info('[bluetooth_js] sendResponse ret : ' + ret);
expect(ret).assertEqual(false); expect(ret).assertEqual(false);
} }
let gattServer = bluetooth.BLE.createGattServer(); let gattServer = bluetooth.BLE.createGattServer();
await gattServer.on("characteristicRead", ReadCharacteristicReq); await gattServer.on("characteristicRead", ReadCharacteristicReq);
await gattServer.off("characteristicRead"); await gattServer.off("characteristicRead");
...@@ -482,27 +487,28 @@ describe('bluetoothBLETest', function() { ...@@ -482,27 +487,28 @@ describe('bluetoothBLETest', function() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) {
let arrayBuffer = new ArrayBuffer(8); try {
let desValue = new Uint8Array(arrayBuffer); let arrayBuffer = new ArrayBuffer(8);
desValue[0] = 11; let desValue = new Uint8Array(arrayBuffer);
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', desValue[0] = 11;
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer}; characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB',
await gattClient.readDescriptorValue(descriptor).then((object) => { descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
if (object != null) { descriptorValue: arrayBuffer};
console.error('readDescriptorValue promise object:'+JSON.stringify(object)); await gattClient.readDescriptorValue(descriptor).then((object) => {
console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object));
expect(true).assertEqual(object!=null);
done();
}).catch(err => {
console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err))
expect(true).assertEqual(true); expect(true).assertEqual(true);
done();
} else { })
console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); } catch (error) {
expect(null).assertFail(); console.error('[bluetooth_js]readDescrValue01 error code:'+JSON.stringify(error.code));
} expect(error.code).assertEqual(undefined);
done(); done()
}).catch(err => { }
console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err));
expect(true).assertEqual(true);
done();
})
}) })
/** /**
...@@ -528,6 +534,7 @@ describe('bluetoothBLETest', function() { ...@@ -528,6 +534,7 @@ describe('bluetoothBLETest', function() {
let desValue = new Uint8Array(arrayBuffer); let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11; desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
gattClient.readDescriptorValue(descriptor,readDesc); gattClient.readDescriptorValue(descriptor,readDesc);
done() done()
...@@ -584,6 +591,7 @@ describe('bluetoothBLETest', function() { ...@@ -584,6 +591,7 @@ describe('bluetoothBLETest', function() {
let desValue = new Uint8Array(arrayBuffer); let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11; desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor; descriptors[0] = descriptor;
let arrayBufferCCC = new ArrayBuffer(8); let arrayBufferCCC = new ArrayBuffer(8);
...@@ -659,6 +667,7 @@ describe('bluetoothBLETest', function() { ...@@ -659,6 +667,7 @@ describe('bluetoothBLETest', function() {
let desValue = new Uint8Array(arrayBuffer); let desValue = new Uint8Array(arrayBuffer);
desValue[0] = 11; desValue[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
let ret = gattClient.writeDescriptorValue(descriptor); let ret = gattClient.writeDescriptorValue(descriptor);
console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret);
...@@ -737,9 +746,11 @@ describe('bluetoothBLETest', function() { ...@@ -737,9 +746,11 @@ describe('bluetoothBLETest', function() {
let descNotifyValue = new Uint8Array(arrayBufferNotify); let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1 descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer}; descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify}; descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor; descriptors[0] = descriptor;
...@@ -773,9 +784,11 @@ describe('bluetoothBLETest', function() { ...@@ -773,9 +784,11 @@ describe('bluetoothBLETest', function() {
let descNotifyValue = new Uint8Array(arrayBufferNotify); let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1 descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer}; descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBufferNotify}; descriptorValue: arrayBufferNotify};
descriptors[0] = descriptor; descriptors[0] = descriptor;
...@@ -831,6 +844,7 @@ describe('bluetoothBLETest', function() { ...@@ -831,6 +844,7 @@ describe('bluetoothBLETest', function() {
let descNotifyValue = new Uint8Array(arrayBufferNotify); let descNotifyValue = new Uint8Array(arrayBufferNotify);
descNotifyValue[0] = 1 descNotifyValue[0] = 1
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB',
descriptorValue: arrayBuffer}; descriptorValue: arrayBuffer};
let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
...@@ -870,3 +884,4 @@ describe('bluetoothBLETest', function() { ...@@ -870,3 +884,4 @@ describe('bluetoothBLETest', function() {
} }
...@@ -15,18 +15,6 @@ ...@@ -15,18 +15,6 @@
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanDuty=
{
SCAN_MODE_LOW_POWER : 0,
SCAN_MODE_BALANCED : 1,
SCAN_MODE_LOW_LATENCY : 2,
};
let MatchMode=
{
MATCH_MODE_AGGRESSIVE : 1,
MATCH_MODE_STICKY : 2,
};
export default function bluetoothhostTest() { export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() { describe('bluetoothhostTest', function() {
...@@ -190,8 +178,8 @@ describe('bluetoothhostTest', function() { ...@@ -190,8 +178,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 100, interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -218,8 +206,8 @@ describe('bluetoothhostTest', function() { ...@@ -218,8 +206,8 @@ describe('bluetoothhostTest', function() {
} }
let ScanOptions= { let ScanOptions= {
interval: 100, interval: 100,
dutyMode: ScanDuty.SCAN_MODE_BALANCED, dutyMode: bluetooth.ScanDuty.SCAN_MODE_BALANCED,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent)
bluetooth.BLE.startBLEScan([{}],ScanOptions); bluetooth.BLE.startBLEScan([{}],ScanOptions);
...@@ -250,8 +238,8 @@ describe('bluetoothhostTest', function() { ...@@ -250,8 +238,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 100, interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -284,8 +272,8 @@ describe('bluetoothhostTest', function() { ...@@ -284,8 +272,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 100, interval: 100,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -315,8 +303,8 @@ describe('bluetoothhostTest', function() { ...@@ -315,8 +303,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 0, interval: 0,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -346,8 +334,8 @@ describe('bluetoothhostTest', function() { ...@@ -346,8 +334,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 500, interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -377,8 +365,8 @@ describe('bluetoothhostTest', function() { ...@@ -377,8 +365,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 500, interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -408,8 +396,8 @@ describe('bluetoothhostTest', function() { ...@@ -408,8 +396,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 500, interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_STICKY, matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY,
} }
); );
await sleep(1000); await sleep(1000);
...@@ -613,8 +601,8 @@ describe('bluetoothhostTest', function() { ...@@ -613,8 +601,8 @@ describe('bluetoothhostTest', function() {
[{}], [{}],
{ {
interval: 500, interval: 500,
dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY,
matchMode: MatchMode.MATCH_MODE_STICKY, matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY,
} }
); );
console.info('[bluetooth_js] BLE scan offC'); console.info('[bluetooth_js] BLE scan offC');
...@@ -627,3 +615,4 @@ describe('bluetoothhostTest', function() { ...@@ -627,3 +615,4 @@ describe('bluetoothhostTest', function() {
}) })
} }
...@@ -283,21 +283,15 @@ describe('bluetoothhostTest2', function() { ...@@ -283,21 +283,15 @@ describe('bluetoothhostTest2', function() {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0900', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_Pair_0900', 0, async function (done) {
let BondState=
{
BOND_STATE_INVALID : 0,
BOND_STATE_BONDING : 1,
BOND_STATE_BONDED : 2
};
function BondStateParam(data) { function BondStateParam(data) {
console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data) console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data)
+'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"); let result = bluetooth.pairDevice("11:22:55:66:33:44");
expect(BondState.BOND_STATE_INVALID == 0).assertTrue(); expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue();
expect(BondState.BOND_STATE_BONDING == 1).assertTrue(); expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue();
expect(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()
}) })
...@@ -308,3 +302,4 @@ describe('bluetoothhostTest2', function() { ...@@ -308,3 +302,4 @@ describe('bluetoothhostTest2', function() {
...@@ -17,27 +17,6 @@ import bluetooth from '@ohos.bluetooth'; ...@@ -17,27 +17,6 @@ import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ProfileId = {
PROFILE_A2DP_SOURCE : 1,
PROFILE_HANDS_FREE_AUDIO_GATEWAY : 4,
PROFILE_HID_HOST : 6,
PROFILE_PAN_NETWORK : 7
}
let PlayingState = {
STATE_NOT_PLAYING : 0x0000 ,
STATE_PLAYING : 0x0001,
}
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3
}
export default function bluetoothhostTest_host_1() { export default function bluetoothhostTest_host_1() {
describe('bluetoothhostTest_host_1', function () { describe('bluetoothhostTest_host_1', function () {
function sleep(delay) { function sleep(delay) {
...@@ -97,10 +76,10 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -97,10 +76,10 @@ describe('bluetoothhostTest_host_1', function () {
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0100', 0, async function (done) {
let connState = bluetooth.getBtConnectionState(); let connState = bluetooth.getBtConnectionState();
console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState)); console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState));
expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(connState).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState ); expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTING!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState ); expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTED!= connState );
expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState ); expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_DISCONNECTING!= connState );
done(); done();
}) })
...@@ -119,7 +98,7 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -119,7 +98,7 @@ describe('bluetoothhostTest_host_1', function () {
'deviceId: ' + data.deviceId + 'state:'+ data.state); 'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null); expect(true).assertEqual(data !=null);
} }
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
a2dpSrc.on('connectionStateChange', StateChangeParam); a2dpSrc.on('connectionStateChange', StateChangeParam);
a2dpSrc.connect('11:22:33:44:55:77'); a2dpSrc.connect('11:22:33:44:55:77');
...@@ -145,7 +124,7 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -145,7 +124,7 @@ describe('bluetoothhostTest_host_1', function () {
'deviceId: ' + data.deviceId + 'state:'+ data.state); 'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null); expect(true).assertEqual(data !=null);
} }
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
a2dpSrc.on('connectionStateChange', StateChangeParam); a2dpSrc.on('connectionStateChange', StateChangeParam);
await sleep(6000); await sleep(6000);
...@@ -166,7 +145,7 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -166,7 +145,7 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0400', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0400', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let conn = a2dpSrc.disconnect('test'); let conn = a2dpSrc.disconnect('test');
console.info('[bluetooth_js]a2dp disconnect1 result:' + JSON.stringify(conn)); console.info('[bluetooth_js]a2dp disconnect1 result:' + JSON.stringify(conn));
...@@ -184,9 +163,9 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -184,9 +163,9 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0500', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0500', 0, async function (done) {
let a2dpSrcConn = bluetooth.getProfileConnState(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrcConn = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn)); console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn));
expect(a2dpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(a2dpSrcConn).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -200,7 +179,7 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -200,7 +179,7 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0600', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0600', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
let conn = a2dpSrc.connect('test'); let conn = a2dpSrc.connect('test');
console.info('[bluetooth_js]a2dp invaild connect:' + JSON.stringify(conn)); console.info('[bluetooth_js]a2dp invaild connect:' + JSON.stringify(conn));
expect(conn).assertFalse(); expect(conn).assertFalse();
...@@ -217,10 +196,10 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -217,10 +196,10 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0700', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0700', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let ret = a2dpSrc.getDeviceState('11:22:33:44:55:66'); let ret = a2dpSrc.getDeviceState('11:22:33:44:55:66');
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -234,10 +213,10 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -234,10 +213,10 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0800', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0800', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let ret = a2dpSrc.getDeviceState('test'); let ret = a2dpSrc.getDeviceState('test');
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -251,12 +230,12 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -251,12 +230,12 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0900', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0900', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let state = a2dpSrc.getPlayingState('11:22:33:44:55:66'); let state = a2dpSrc.getPlayingState('11:22:33:44:55:66');
console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state)); console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state));
expect(state).assertEqual(PlayingState.STATE_NOT_PLAYING); expect(state).assertEqual(bluetooth.PlayingState.STATE_NOT_PLAYING);
expect(true).assertEqual(state!=PlayingState.STATE_PLAYING); expect(true).assertEqual(state!=bluetooth.PlayingState.STATE_PLAYING);
done(); done();
}) })
...@@ -270,7 +249,7 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -270,7 +249,7 @@ describe('bluetoothhostTest_host_1', function () {
* @tc.level Level 1 * @tc.level Level 1
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_1000', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_1000', 0, async function (done) {
let a2dpSrc = bluetooth.getProfile(ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc)); console.info('[bluetooth_js]a2dp get profile result:' + JSON.stringify(a2dpSrc));
let retArray = a2dpSrc.getConnectionDevices(); let retArray = a2dpSrc.getConnectionDevices();
expect(true).assertEqual(retArray.length>=0); expect(true).assertEqual(retArray.length>=0);
...@@ -282,3 +261,4 @@ describe('bluetoothhostTest_host_1', function () { ...@@ -282,3 +261,4 @@ describe('bluetoothhostTest_host_1', function () {
} }
...@@ -16,20 +16,6 @@ ...@@ -16,20 +16,6 @@
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ProfileId = {
PROFILE_A2DP_SOURCE : 1,
PROFILE_HANDS_FREE_AUDIO_GATEWAY : 4,
PROFILE_HID_HOST : 6,
PROFILE_PAN_NETWORK : 7
}
let ProfileConnectionState=
{
STATE_CONNECTING : 1,
STATE_CONNECTED : 2,
STATE_DISCONNECTED : 0,
STATE_DISCONNECTING : 3,
};
export default function bluetoothhostTest_host_3() { export default function bluetoothhostTest_host_3() {
describe('bluetoothhostTest_host_3', function () { describe('bluetoothhostTest_host_3', function () {
...@@ -89,9 +75,9 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -89,9 +75,9 @@ describe('bluetoothhostTest_host_3', function () {
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1100', 0, async function (done) {
let hfpSrcConn = let hfpSrcConn =
bluetooth.getProfileConnState(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
console.info('[bluetooth_js]get hfp result:' + JSON.stringify(hfpSrcConn)); console.info('[bluetooth_js]get hfp result:' + JSON.stringify(hfpSrcConn));
expect(hfpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(hfpSrcConn).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -105,10 +91,10 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -105,10 +91,10 @@ describe('bluetoothhostTest_host_3', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1200', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpSrc.getDeviceState('11:22:33:44:55:66'); let ret = hfpSrc.getDeviceState('11:22:33:44:55:66');
console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret)); console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret));
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -122,10 +108,10 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -122,10 +108,10 @@ describe('bluetoothhostTest_host_3', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1300', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let ret = hfpSrc.getDeviceState('bluetooth1'); let ret = hfpSrc.getDeviceState('bluetooth1');
console.info('[bluetooth_js]hfp get valid mac DeviceState:' + JSON.stringify(ret)); console.info('[bluetooth_js]hfp get valid mac DeviceState:' + JSON.stringify(ret));
expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED);
done(); done();
}) })
...@@ -144,7 +130,7 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -144,7 +130,7 @@ describe('bluetoothhostTest_host_3', function () {
'deviceId: ' + data.deviceId + 'state:'+ data.state); 'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null); expect(true).assertEqual(data !=null);
} }
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpSrc.on('connectionStateChange', StateChangeParam); hfpSrc.on('connectionStateChange', StateChangeParam);
hfpSrc.connect('11:22:33:44:55:66'); hfpSrc.connect('11:22:33:44:55:66');
await sleep(6000); await sleep(6000);
...@@ -167,7 +153,7 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -167,7 +153,7 @@ describe('bluetoothhostTest_host_3', function () {
'deviceId: ' + data.deviceId + 'state:'+ data.state); 'deviceId: ' + data.deviceId + 'state:'+ data.state);
expect(true).assertEqual(data !=null); expect(true).assertEqual(data !=null);
} }
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpSrc.on('connectionStateChange', StateChangeParam); hfpSrc.on('connectionStateChange', StateChangeParam);
await sleep(10000); await sleep(10000);
let conn = hfpSrc.disconnect('11:22:33:44:55:66'); let conn = hfpSrc.disconnect('11:22:33:44:55:66');
...@@ -187,7 +173,7 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -187,7 +173,7 @@ describe('bluetoothhostTest_host_3', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1600', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let conn1 = hfpSrc.connect('test'); let conn1 = hfpSrc.connect('test');
console.info('[bluetooth_js]hfp vaild MAC disconnect :' + JSON.stringify(conn1)); console.info('[bluetooth_js]hfp vaild MAC disconnect :' + JSON.stringify(conn1));
expect(conn1).assertFalse(); expect(conn1).assertFalse();
...@@ -204,7 +190,7 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -204,7 +190,7 @@ describe('bluetoothhostTest_host_3', function () {
* @tc.level Level 3 * @tc.level Level 3
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1700', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
console.info('[bluetooth_js]hfp get profile result:' + JSON.stringify(hfpSrc)); console.info('[bluetooth_js]hfp get profile result:' + JSON.stringify(hfpSrc));
let conn = hfpSrc.disconnect('test'); let conn = hfpSrc.disconnect('test');
console.info('[bluetooth_js]hfp disconnect1 result:' + JSON.stringify(conn)); console.info('[bluetooth_js]hfp disconnect1 result:' + JSON.stringify(conn));
...@@ -222,7 +208,7 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -222,7 +208,7 @@ describe('bluetoothhostTest_host_3', function () {
* @tc.level Level 1 * @tc.level Level 1
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_HFP_Conn_1800', 0, async function (done) {
let hfpSrc = bluetooth.getProfile(ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
let retArray = hfpSrc.getConnectionDevices(); let retArray = hfpSrc.getConnectionDevices();
console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray));
expect(true).assertEqual(retArray.length>=0); expect(true).assertEqual(retArray.length>=0);
...@@ -234,3 +220,4 @@ describe('bluetoothhostTest_host_3', function () { ...@@ -234,3 +220,4 @@ describe('bluetoothhostTest_host_3', function () {
} }
...@@ -14,17 +14,26 @@ ...@@ -14,17 +14,26 @@
*/ */
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanMode = const PERMISSION_USER_SET = 1;
{ const PERMISSION_USER_NAME1 = "ohos.permission.LOCATION";
SCAN_MODE_NONE : 0, const PERMISSION_USER_NAME2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
SCAN_MODE_CONNECTABLE : 1, let tokenID = undefined;
SCAN_MODE_GENERAL_DISCOVERABLE : 2, async function grantPerm() {
SCAN_MODE_LIMITED_DISCOVERABLE : 3, console.info("====grant Permission start====");
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4, let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, 100);
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5, tokenID = appInfo.accessTokenId;
} console.info("accessTokenId" + appInfo.accessTokenId + " bundleName:" + appInfo.bundleName);
let atManager = abilityAccessCtrl.createAtManager();
let result = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME1, PERMISSION_USER_SET);
console.info("tokenId" + tokenID + " result:" + result);
let result1 = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME2, PERMISSION_USER_SET);
console.info("tokenId" + tokenID + " result1:" + result1);
console.info("====grant Permission end====");
}
export default function bluetoothhostTest3() { export default function bluetoothhostTest3() {
describe('bluetoothhostTest3', function() { describe('bluetoothhostTest3', function() {
function sleep(delay) { function sleep(delay) {
...@@ -57,8 +66,11 @@ describe('bluetoothhostTest3', function() { ...@@ -57,8 +66,11 @@ describe('bluetoothhostTest3', function() {
console.info('[bluetooth_js] enable success'); console.info('[bluetooth_js] enable success');
} }
} }
beforeAll(function () {
beforeAll(async function (done) {
console.info('beforeAll called') console.info('beforeAll called')
await grantPerm();
done()
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
console.info('beforeEach called') console.info('beforeEach called')
...@@ -109,11 +121,11 @@ describe('bluetoothhostTest3', function() { ...@@ -109,11 +121,11 @@ describe('bluetoothhostTest3', function() {
* @tc.level Level 1 * @tc.level Level 1
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300', 0, async function (done) {
let result1 = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE,10); let result1 = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE,10);
expect(result1).assertTrue(); expect(result1).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE);
let result = bluetooth.startBluetoothDiscovery(); let result = bluetooth.startBluetoothDiscovery();
await sleep(2000); await sleep(2000);
console.info('[bluetooth_js] startDiscovery1'+result); console.info('[bluetooth_js] startDiscovery1'+result);
...@@ -126,3 +138,4 @@ describe('bluetoothhostTest3', function() { ...@@ -126,3 +138,4 @@ describe('bluetoothhostTest3', function() {
}) })
} }
...@@ -15,15 +15,7 @@ ...@@ -15,15 +15,7 @@
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let ScanMode =
{
SCAN_MODE_NONE : 0,
SCAN_MODE_CONNECTABLE : 1,
SCAN_MODE_GENERAL_DISCOVERABLE : 2,
SCAN_MODE_LIMITED_DISCOVERABLE : 3,
SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE : 4,
SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE : 5,
}
export default function bluetoothhostTest2() { export default function bluetoothhostTest2() {
describe('bluetoothhostTest2', function() { describe('bluetoothhostTest2', function() {
function sleep(delay) { function sleep(delay) {
...@@ -82,11 +74,11 @@ describe('bluetoothhostTest2', function() { ...@@ -82,11 +74,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0100 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_NONE,0); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_NONE,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0100 newscanmode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0100 newscanmode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_NONE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_NONE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -107,11 +99,11 @@ describe('bluetoothhostTest2', function() { ...@@ -107,11 +99,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 newscanmode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0200 newscanmode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -132,11 +124,11 @@ describe('bluetoothhostTest2', function() { ...@@ -132,11 +124,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0200 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,40000); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE,40000);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0200 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0200 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -157,11 +149,11 @@ describe('bluetoothhostTest2', function() { ...@@ -157,11 +149,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0400 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,40000); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,40000);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0400 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0400 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -181,11 +173,11 @@ describe('bluetoothhostTest2', function() { ...@@ -181,11 +173,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0500 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,0); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0500 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0500 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -206,11 +198,11 @@ describe('bluetoothhostTest2', function() { ...@@ -206,11 +198,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0600 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,0); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0600 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0600 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -231,11 +223,11 @@ describe('bluetoothhostTest2', function() { ...@@ -231,11 +223,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0700 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,20000); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE,20000);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0700 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0700 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -256,11 +248,11 @@ describe('bluetoothhostTest2', function() { ...@@ -256,11 +248,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -281,11 +273,11 @@ describe('bluetoothhostTest2', function() { ...@@ -281,11 +273,11 @@ describe('bluetoothhostTest2', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) {
let oldScanMode = bluetooth.getBluetoothScanMode(); let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode)); console.info('[bluetooth_js] ScanMode_0900 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,30000); let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,30000);
expect(result).assertTrue(); expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode(); let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0900 getScanMode = '+ JSON.stringify(getScanMode)); console.info('[bluetooth_js] ScanMode_0900 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE); expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0); result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue(); expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode(); let getOldScanMode = bluetooth.getBluetoothScanMode();
...@@ -317,3 +309,4 @@ describe('bluetoothhostTest2', function() { ...@@ -317,3 +309,4 @@ describe('bluetoothhostTest2', function() {
}) })
} }
...@@ -71,11 +71,8 @@ describe('bluetoothhostTest4', function() { ...@@ -71,11 +71,8 @@ describe('bluetoothhostTest4', function() {
* @tc.level Level 1 * @tc.level Level 1
*/ */
it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100', 0, async function (done) {
let SppType = {
SPP_RFCOMM : 0
}
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: SppType.SPP_RFCOMM}; secure: true, type: bluetooth.SppType.SPP_RFCOMM};
let serverNumber = -1; let serverNumber = -1;
function serverSocket(code, number) { function serverSocket(code, number) {
if (code) { if (code) {
...@@ -392,3 +389,4 @@ describe('bluetoothhostTest4', function() { ...@@ -392,3 +389,4 @@ describe('bluetoothhostTest4', function() {
} }
...@@ -15,17 +15,7 @@ ...@@ -15,17 +15,7 @@
import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let BluetoothState=
{
STATE_OFF : 0,
STATE_TURNING_ON : 1,
STATE_ON : 2,
STATE_TURNING_OFF : 3,
STATE_BLE_TURNING_ON : 4,
STATE_BLE_ON : 5,
STATE_BLE_TURNING_OFF : 6,
}
export default function bluetoothhostTest() { export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() { describe('bluetoothhostTest', function() {
function sleep(delay) { function sleep(delay) {
...@@ -88,7 +78,7 @@ describe('bluetoothhostTest', function() { ...@@ -88,7 +78,7 @@ describe('bluetoothhostTest', function() {
await bluetooth.on('stateChange', onReceiveEvent); await bluetooth.on('stateChange', onReceiveEvent);
let state = bluetooth.getState(); let state = bluetooth.getState();
console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state)); console.info('[bluetooth_js] get bluetooth state001'+ JSON.stringify(state));
if(state!=BluetoothState.STATE_ON) if(state!=bluetooth.BluetoothState.STATE_ON)
{ {
let enable = bluetooth.enableBluetooth(); let enable = bluetooth.enableBluetooth();
await sleep(5000); await sleep(5000);
...@@ -96,7 +86,7 @@ describe('bluetoothhostTest', function() { ...@@ -96,7 +86,7 @@ describe('bluetoothhostTest', function() {
expect(enable).assertTrue(); expect(enable).assertTrue();
let state1 = bluetooth.getState(); let state1 = bluetooth.getState();
console.info('[bluetooth_js] enable state001 '+ JSON.stringify(state1)); console.info('[bluetooth_js] enable state001 '+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_ON); expect(state1).assertEqual(bluetooth.BluetoothState.STATE_ON);
} }
let disable = bluetooth.disableBluetooth(); let disable = bluetooth.disableBluetooth();
await sleep(3000); await sleep(3000);
...@@ -104,7 +94,7 @@ describe('bluetoothhostTest', function() { ...@@ -104,7 +94,7 @@ describe('bluetoothhostTest', function() {
expect(disable).assertTrue(); expect(disable).assertTrue();
let state2 = bluetooth.getState(); let state2 = bluetooth.getState();
console.info('[bluetooth_js] disable state001 '+ JSON.stringify(state2)); console.info('[bluetooth_js] disable state001 '+ JSON.stringify(state2));
expect(state2).assertEqual(BluetoothState.STATE_OFF); expect(state2).assertEqual(bluetooth.BluetoothState.STATE_OFF);
await bluetooth.off('stateChange', onReceiveEvent); await bluetooth.off('stateChange', onReceiveEvent);
done() done()
}) })
...@@ -121,15 +111,15 @@ describe('bluetoothhostTest', function() { ...@@ -121,15 +111,15 @@ describe('bluetoothhostTest', function() {
it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) { it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) {
let state = bluetooth.getState(); let state = bluetooth.getState();
console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state)); console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state));
expect(state).assertEqual(BluetoothState.STATE_ON); expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON);
if(state==BluetoothState.STATE_ON) { if(state==bluetooth.BluetoothState.STATE_ON) {
let enable1=bluetooth.enableBluetooth(); let enable1=bluetooth.enableBluetooth();
await sleep(3000); await sleep(3000);
console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1)); console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1));
expect(enable1).assertFalse(); expect(enable1).assertFalse();
let state1 = bluetooth.getState(); let state1 = bluetooth.getState();
console.info('[bluetooth_js] bt open state2='+ JSON.stringify(state1)); console.info('[bluetooth_js] bt open state2='+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_ON); expect(state1).assertEqual(bluetooth.BluetoothState.STATE_ON);
}else{ }else{
console.info('[bluetooth_js]bluetooth open fail'); console.info('[bluetooth_js]bluetooth open fail');
} }
...@@ -152,17 +142,18 @@ describe('bluetoothhostTest', function() { ...@@ -152,17 +142,18 @@ describe('bluetoothhostTest', function() {
expect(result1).assertTrue(); expect(result1).assertTrue();
let state = bluetooth.getState(); let state = bluetooth.getState();
console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state)); console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state));
expect(state).assertEqual(BluetoothState.STATE_OFF); expect(state).assertEqual(bluetooth.BluetoothState.STATE_OFF);
if(state == BluetoothState.STATE_OFF) { if(state == bluetooth.BluetoothState.STATE_OFF) {
let result2= bluetooth.disableBluetooth(); let result2= bluetooth.disableBluetooth();
console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2)); console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2));
expect(result2).assertFalse(); expect(result2).assertFalse();
let state1 = bluetooth.getState(); let state1 = bluetooth.getState();
console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1)); console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1));
expect(state1).assertEqual(BluetoothState.STATE_OFF); expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF);
} }
done(); done();
}) })
}) })
} }
...@@ -28,12 +28,11 @@ if (info != "false") ...@@ -28,12 +28,11 @@ if (info != "false")
{ {
nfcATagSessionTest(); nfcATagSessionTest();
nfcControllerTest(); nfcControllerTest();
ConnectedTagTest();
nfcIsoDepTagTest(); nfcIsoDepTagTest();
nfcMifareClassicTag(); nfcMifareClassicTag();
nfcMifareUltralightTag(); nfcMifareUltralightTag();
nfcTagABFVTest();
nfcNDEFTagTest(); nfcNDEFTagTest();
ConnectedTagTest(); nfcTagABFVTest();
} }
} }
...@@ -34,11 +34,18 @@ let aTag = { ...@@ -34,11 +34,18 @@ let aTag = {
], ],
"tagRfDiscId": 1, "tagRfDiscId": 1,
}; };
let getAtag = null ;
export default function nfcATagSessionTest() { export default function nfcATagSessionTest() {
describe('nfcATagSessionTest', function () { describe('nfcATagSessionTest', function () {
beforeAll(function () { beforeAll(function () {
console.info('[NFC_test]beforeAll called') console.info('[NFC_test]beforeAll called')
try {
getAtag = tag.getNfcATag(aTag)
console.info('Nfcget Connected data' + getAtag)
} catch (error) {
console.info('Nfcget Connected error' + error)
}
}) })
beforeEach(function() { beforeEach(function() {
console.info('[NFC_test]beforeEach called') console.info('[NFC_test]beforeEach called')
...@@ -59,13 +66,19 @@ export default function nfcATagSessionTest() { ...@@ -59,13 +66,19 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0100', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0100', 0, function () {
let NfcConnected; if (getAtag != null && getAtag != undefined) {
try{ let NfcConnected;
NfcConnected = tag.getNfcATag(aTag).connectTag(); try {
console.info("NfcConnected:" +NfcConnected); NfcConnected = getAtag.connectTag();
expect(NfcConnected).assertFalse(); console.info("NfcConnected:" + NfcConnected);
}catch(error){ expect(NfcConnected).assertFalse();
console.info('NfcConnected error' + error) } catch (error) {
console.info('NfcConnected error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag1 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -79,12 +92,18 @@ export default function nfcATagSessionTest() { ...@@ -79,12 +92,18 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0200', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0200', 0, function () {
try{ if (getAtag != null && getAtag != undefined) {
tag.getNfcATag(aTag).reset(); try {
expect(true).assertTrue(); getAtag.reset();
console.info('reset1 pass' ) expect(true).assertTrue();
}catch(error){ console.info('reset1 pass' )
console.info('reset1 error' + error) } catch (error) {
console.info('reset1 error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag2 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -98,13 +117,19 @@ export default function nfcATagSessionTest() { ...@@ -98,13 +117,19 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0300', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0300', 0, function () {
let isNfcConnected; if (getAtag != null && getAtag != undefined) {
try{ let isNfcConnected;
isNfcConnected = tag.getNfcATag(aTag).isTagConnected(); try {
console.info("isNfcConnected:" +isNfcConnected); isNfcConnected = getAtag.isTagConnected();
expect(isNfcConnected).assertFalse(); console.info("isNfcConnected:" +isNfcConnected);
}catch(error){ expect(isNfcConnected).assertFalse();
console.info('isNfcConnected error' + error) } catch (error) {
console.info('isNfcConnected error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag3 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -118,14 +143,20 @@ export default function nfcATagSessionTest() { ...@@ -118,14 +143,20 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0400', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0400', 0, function () {
let mazSendLen; if (getAtag != null && getAtag != undefined) {
try{ let mazSendLen;
mazSendLen = tag.getNfcATag(aTag).getMaxSendLength(); try {
console.info("getMaxSendLength:" +mazSendLen); mazSendLen = getAtag.getMaxSendLength();
expect(true).assertTrue(mazSendLen >= 0); console.info("getMaxSendLength:" + mazSendLen);
console.info('getMaxSendLength pass' ) expect(mazSendLen >= 0).assertTrue();
}catch(error){ console.info('getMaxSendLength pass' )
console.info('getMaxSendLength error' + error) } catch (error) {
console.info('getMaxSendLength error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag4 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -139,13 +170,19 @@ export default function nfcATagSessionTest() { ...@@ -139,13 +170,19 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0500', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0500', 0, function () {
let settime; if (getAtag != null && getAtag != undefined) {
try{ let settime;
settime = tag.getNfcATag(aTag).setSendDataTimeout(1000); try {
console.info("setSendDataTimeout:" +settime); settime = getAtag.setSendDataTimeout(1000);
expect(true).assertTrue(settime >= 0); console.info("setSendDataTimeout:" + settime);
}catch(error){ expect(settime >= 0).assertTrue();
console.info('setSendDataTimeout error' + error) } catch (error) {
console.info('setSendDataTimeout error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag5 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -159,14 +196,20 @@ export default function nfcATagSessionTest() { ...@@ -159,14 +196,20 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0600', 0, function () { it('SUB_Communication_NFC_nfcAtage_js_0600', 0, function () {
let gettime; if (getAtag != null && getAtag != undefined) {
try{ let gettime;
gettime = tag.getNfcATag(aTag).getSendDataTimeout(); try {
console.info("getMaxSendLength:" +gettime + 'aTag is--<-!!!->' + JSON.stringify(gettime)); gettime = getAtag.getSendDataTimeout();
expect(true).assertTrue(gettime >= 0); console.info("getMaxSendLength:" + gettime + 'aTag is--<-!!!->' + JSON.stringify(gettime));
console.info('getMaxSendLength pass' ) expect(gettime >= 0).assertTrue();
}catch(error){ console.info('getMaxSendLength pass' )
console.info('getMaxSendLength error' + error) } catch (error) {
console.info('getMaxSendLength error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]getAtag6 = null & = undefined: ");
expect(true).assertFalse();
} }
}) })
...@@ -180,19 +223,118 @@ export default function nfcATagSessionTest() { ...@@ -180,19 +223,118 @@ export default function nfcATagSessionTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0700', 0, async function (done) { it('SUB_Communication_NFC_nfcAtage_js_0700', 0, async function (done) {
if (getAtag != null && getAtag != undefined) {
let sendDatas = [0x01, 0x02, 0x03, 0x04];
await getAtag.sendData(sendDatas).then((data) => {
console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data));
expect(data >= 0).assertTrue();
done();
}).catch((err)=> {
console.log("nfcAtage sendData1 err: " + err);
expect(true).assertFalse();
});
sleep(3500);
} else {
console.info("[NFC_test]getAtag7 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcAtage_js_0800
* @tc.name testsendData
* @tc.desc Test sendData api by callback.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcAtage_js_0800', 0, async function (done) {
if (getAtag != null && getAtag != undefined) {
let sendDatas = [0x01, 0x02, 0x03, 0x04];
getAtag.sendData(sendDatas, (err, data)=> {
if (err) {
console.log("nfcAtage sendData2 data err: " + err);
expect(true).assertFalse();
} else {
sleep(2500);
console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data));
expect(data >= 0).assertTrue();
}
});
sleep(500);
done();
} else {
console.info("[NFC_test]getAtag8 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcAtage_js_0900
* @tc.name testreset
* @tc.desc Test reset api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcAtage_js_0900', 0, function () {
try {
tag.getNfcA(aTag).resetConnection();
expect(true).assertTrue();
console.info('reset1 pass' )
} catch (error) {
console.info('reset1 error' + error)
expect(true).assertTrue();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcAtage_js_1000
* @tc.name testsetSendDataTimeout
* @tc.desc Test setSendDataTimeout api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcAtage_js_1000', 0, function () {
let settime;
try {
settime = tag.getNfcATag(aTag).getTimeout(1000);
console.info("setSendDataTimeout:" +settime);
expect(settime >= 0).assertTrue();
} catch (error) {
console.info('setSendDataTimeout error' + error)
expect(true).assertTrue();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcAtage_js_1100
* @tc.name testsendData
* @tc.desc Test sendData api by peomise.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcAtage_js_1100', 0, async function (done) {
let sendDatas = [0x01, 0x02, 0x03, 0x04]; let sendDatas = [0x01, 0x02, 0x03, 0x04];
await tag.getNfcATag(aTag).sendData(sendDatas).then((data) => { await tag.getNfcATag(aTag).transmit(sendDatas).then((data) => {
console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data)); console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data));
expect(true).assertTrue(data >= 0); expect(data >= 0).assertTrue();
done(); done();
}).catch((err)=> { }).catch((err)=> {
console.log("nfcAtage sendData1 err: " + err); console.log("nfcAtage sendData1 err: " + err);
expect(true).assertTrue();
}); });
sleep(3500); sleep(3500);
}) })
/** /**
* @tc.number SUB_Communication_NFC_nfcAtage_js_0800 * @tc.number SUB_Communication_NFC_nfcAtage_js_1200
* @tc.name testsendData * @tc.name testsendData
* @tc.desc Test sendData api by callback. * @tc.desc Test sendData api by callback.
* @tc.size MEDIUM * @tc.size MEDIUM
...@@ -200,22 +342,46 @@ export default function nfcATagSessionTest() { ...@@ -200,22 +342,46 @@ export default function nfcATagSessionTest() {
* @tc.type Function * @tc.type Function
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcAtage_js_0800', 0, async function (done) { it('SUB_Communication_NFC_nfcAtage_js_1200', 0, async function (done) {
let sendDatas = [0x01, 0x02, 0x03, 0x04]; let sendDatas = [0x01, 0x02, 0x03, 0x04];
tag.getNfcATag(aTag).sendData(sendDatas, (err, data)=> { tag.getNfcATag(aTag).transmit(sendDatas, (err, data)=> {
if (err) { if (err) {
console.log("nfcAtage sendData2 data err: " + err); console.log("nfcAtage sendData2 data err: " + err);
expect(true).assertFalse();
} else { } else {
sleep(2500); sleep(2500);
console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data)); console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data));
expect(true).assertTrue(data >= 0); expect(data >= 0).assertTrue();
} }
}); });
sleep(500); sleep(500);
done(); done();
}) })
/**
* @tc.number SUB_Communication_NFC_nfcAtage_js_1300
* @tc.name testgetMaxSendLength
* @tc.desc Test getMaxSendLength api.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcAtage_js_1300', 0, function () {
let mazSendLen;
try {
mazSendLen = tag.getNfcATag(aTag).getMaxTransmitSize();
console.info("getMaxTransmitSize:" +mazSendLen);
expect(mazSendLen >= 0).assertTrue();
console.info('getMaxTransmitSize pass' )
} catch (error) {
console.info('getMaxTransmitSize error' + error)
expect(true).assertFalse();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
...@@ -58,11 +58,10 @@ export default function ConnectedTagTest() { ...@@ -58,11 +58,10 @@ export default function ConnectedTagTest() {
if (!isAccessToken) { if (!isAccessToken) {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
} } else {
else{
let inittag = connectedTag.init(); let inittag = connectedTag.init();
expect(inittag).assertTrue(); expect(inittag).assertTrue();
console.info("mifareUltralight readMultiplePages1 err: " + inittag ); console.info("ConnectedTag readMultiplePages1 err: " + inittag );
} }
}) })
...@@ -81,14 +80,13 @@ export default function ConnectedTagTest() { ...@@ -81,14 +80,13 @@ export default function ConnectedTagTest() {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
done(); done();
} } else {
else{
await connectedTag.readNdefTag().then(result => { await connectedTag.readNdefTag().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(true).assertTrue(result != null); expect(result != null).assertTrue();
done(); done();
}).catch((err)=> { }).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err); console.info("ConnectedTag readMultiplePages1 err: " + err);
expect(true).assertEqual(true); expect(true).assertEqual(true);
done(); done();
}); });
...@@ -111,8 +109,7 @@ export default function ConnectedTagTest() { ...@@ -111,8 +109,7 @@ export default function ConnectedTagTest() {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
done(); done();
} } else {
else{
connectedTag.readNdefTag((err, result)=> { connectedTag.readNdefTag((err, result)=> {
if (err) { if (err) {
expect().assertFail(); expect().assertFail();
...@@ -141,14 +138,13 @@ export default function ConnectedTagTest() { ...@@ -141,14 +138,13 @@ export default function ConnectedTagTest() {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
done(); done();
} } else {
else{
await connectedTag.writeNdefTag().then(result => { await connectedTag.writeNdefTag().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(true).assertTrue(result != null); expect(result != null).assertTrue();
done(); done();
}).catch((err)=> { }).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err); console.info("ConnectedTag readMultiplePages1 err: " + err);
expect(true).assertEqual(true); expect(true).assertEqual(true);
done(); done();
}); });
...@@ -170,8 +166,7 @@ export default function ConnectedTagTest() { ...@@ -170,8 +166,7 @@ export default function ConnectedTagTest() {
if (!isAccessToken) { if (!isAccessToken) {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
} } else {
else{
connectedTag.writeNdefTag((err, result)=> { connectedTag.writeNdefTag((err, result)=> {
if (err) { if (err) {
expect().assertFail(); expect().assertFail();
...@@ -199,8 +194,7 @@ export default function ConnectedTagTest() { ...@@ -199,8 +194,7 @@ export default function ConnectedTagTest() {
if (!isAccessToken) { if (!isAccessToken) {
console.info("The device does not support active label chips.") console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
} } else {
else{
let recvNfcRfNotifyFunc = result => { let recvNfcRfNotifyFunc = result => {
console.info("nfc state receive state ->" + result); console.info("nfc state receive state ->" + result);
expect(result != null).assertTrue(); expect(result != null).assertTrue();
...@@ -219,6 +213,27 @@ export default function ConnectedTagTest() { ...@@ -219,6 +213,27 @@ export default function ConnectedTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcConnectedTag_js_0700', 0, function () { it('SUB_Communication_NFC_nfcConnectedTag_js_0700', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
} else {
let uninittag = connectedTag.uninit();
expect(uninittag).assertTrue();
console.info("ConnectedTag readMultiplePages1 err: " + uninittag );
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0800
* @tc.name Test initialize connectedTag
* @tc.desc Initializes the active label chip.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0800', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag"); var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken); console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) { if (!isAccessToken) {
...@@ -226,14 +241,155 @@ export default function ConnectedTagTest() { ...@@ -226,14 +241,155 @@ export default function ConnectedTagTest() {
expect(isAccessToken).assertFalse() expect(isAccessToken).assertFalse()
} }
else{ else{
let uninittag = connectedTag.uninit(); let inittag = connectedTag.initialize();
expect(inittag).assertTrue();
console.info("mifareUltralight readMultiplePages1 err: " + inittag );
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0900
* @tc.name Test uninitialize connectedTag
* @tc.desc uninitialize active label chip resources.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0900', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
let uninittag = connectedTag.uninitialize();
expect(uninittag).assertTrue(); expect(uninittag).assertTrue();
console.info("mifareUltralight readMultiplePages1 err: " + uninittag ); console.info("mifareUltralight readMultiplePages1 err: " + uninittag );
} }
}) })
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_1000
* @tc.name Test read connectedTag
* @tc.desc Reads the content of the active tag.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_1000', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
await connectedTag.read().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(result != null).assertTrue();
done();
}).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_1100
* @tc.name Test read connectedTag
* @tc.desc Reads the content of the active tag.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_1100', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
connectedTag.read((err, result)=> {
if (err) {
expect().assertFail();
console.info("isoDep isExtendedApduSupported err: " + err);
} else {
expect(result!=null).assertEqual(data);
console.info("isoDep isExtendedApduSupported data: " + result);
}
});
}
done();
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_1200
* @tc.name Test write connectedTag
* @tc.desc Write Content to Active Tags
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_1200', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
await connectedTag.write().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(result != null).assertTrue();
done();
}).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_1200
* @tc.name Test write connectedTag
* @tc.desc Write Content to Active Tags
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_1200', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
connectedTag.write((err, result)=> {
if (err) {
expect().assertFail();
console.info("isoDep isExtendedApduSupported err: " + err);
} else {
expect(result!=null).assertEqual(data);
console.info("isoDep isExtendedApduSupported data: " + result);
}
});
}
done();
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
...@@ -34,11 +34,17 @@ let NfcState={ ...@@ -34,11 +34,17 @@ let NfcState={
export default function nfcControllerTest() { export default function nfcControllerTest() {
describe('nfcControllerTest', function () { describe('nfcControllerTest', function () {
beforeEach(function () { beforeAll(function () {
console.info("[NFC_test]beforeEach start" ); console.info('[NFC_test]beforeAll called')
}) })
afterEach(async function () { beforeEach(function() {
console.info("[NFC_test]afterEach start" ); console.info('[NFC_test]beforeEach called')
})
afterEach(function () {
console.info('[NFC_test]afterEach called')
})
afterAll(function () {
console.info('[NFC_test]afterAll called')
}) })
/** /**
...@@ -124,3 +130,4 @@ export default function nfcControllerTest() { ...@@ -124,3 +130,4 @@ export default function nfcControllerTest() {
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import cardEmulation from '@ohos.nfc.cardEmulation';
function sleep(delay) { // delay x ms function sleep(delay) { // delay x ms
let start = (new Date()).getTime(); let start = (new Date()).getTime();
...@@ -63,14 +64,21 @@ let isoDepTaginfo = { ...@@ -63,14 +64,21 @@ let isoDepTaginfo = {
], ],
"tagRfDiscId": 1, "tagRfDiscId": 1,
}; };
let CardType = {
PAYMENT : "payment",
OTHER : "other",
};
let IsoDepTag ; let IsoDepTag ;
export default function nfcIsoDepTagTest() { export default function nfcIsoDepTagTest() {
describe('nfcIsoDepTagTest', function () { describe('nfcIsoDepTagTest', function () {
beforeAll(function () { beforeAll(function () {
console.info('[NFC_test]beforeAll called') console.info('[NFC_test]beforeAll called')
try{ try {
IsoDepTag = tag.getIsoDep(isoDepTaginfo); IsoDepTag = tag.getIsoDep(isoDepTaginfo);
}catch(error){ } catch (error) {
console.info('getIsoDep is ->' + error) console.info('getIsoDep is ->' + error)
} }
}) })
...@@ -93,9 +101,14 @@ export default function nfcIsoDepTagTest() { ...@@ -93,9 +101,14 @@ export default function nfcIsoDepTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, function () { it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, function () {
let ResponseFlags = IsoDepTag.getHistoricalBytes(); if (IsoDepTag != null && IsoDepTag != undefined) {
expect(ResponseFlags).assertInstanceOf('Array') let ResponseFlags = IsoDepTag.getHistoricalBytes();
console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags); expect(ResponseFlags).assertInstanceOf('Array')
console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags);
} else {
console.info("[NFC_test]IsoDepTag1 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -107,9 +120,14 @@ export default function nfcIsoDepTagTest() { ...@@ -107,9 +120,14 @@ export default function nfcIsoDepTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, function () { it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, function () {
let HiLayerResponse = IsoDepTag.getHiLayerResponse(); if (IsoDepTag != null && IsoDepTag != undefined) {
expect(HiLayerResponse).assertInstanceOf('Array') let HiLayerResponse = IsoDepTag.getHiLayerResponse();
console.info('[nfc_js] test ResponseFlags data>:' + HiLayerResponse); expect(HiLayerResponse).assertInstanceOf('Array')
console.info('[nfc_js] test ResponseFlags data2>:' + HiLayerResponse);
} else {
console.info("[NFC_test]IsoDepTag2 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -121,15 +139,20 @@ export default function nfcIsoDepTagTest() { ...@@ -121,15 +139,20 @@ export default function nfcIsoDepTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, async function (done) { it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, async function (done) {
await IsoDepTag.isExtendedApduSupported().then((data) => { if (IsoDepTag != null && IsoDepTag != undefined) {
expect(false).assertEqual(data); await IsoDepTag.isExtendedApduSupported().then((data) => {
console.info("isoDep isExtendedApduSupported data: " + data); expect(false).assertEqual(data);
done(); console.info("isoDep isExtendedApduSupported data: " + data);
}).catch((err)=> { done();
console.info("isoDep isExtendedApduSupported err: " + err); }).catch((err)=> {
expect().assertFail(); console.info("isoDep isExtendedApduSupported err: " + err);
done(); expect(true).assertFalse();
}); done();
});
} else {
console.info("[NFC_test]IsoDepTag3 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -141,16 +164,21 @@ export default function nfcIsoDepTagTest() { ...@@ -141,16 +164,21 @@ export default function nfcIsoDepTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfcIsoDep_js_0400', 0, async function (done) { it('SUB_Communication_NFC_nfcIsoDep_js_0400', 0, async function (done) {
IsoDepTag.isExtendedApduSupported((err, data)=> { if (IsoDepTag != null && IsoDepTag != undefined) {
if (err) { IsoDepTag.isExtendedApduSupported((err, data)=> {
expect().assertFail(); if (err) {
console.info("isoDep isExtendedApduSupported err: " + err); expect(true).assertFalse();
} else { console.info("isoDep isExtendedApduSupported err: " + err);
expect(false).assertEqual(data); } else {
console.info("isoDep isExtendedApduSupported data: " + data); expect(false).assertEqual(data);
} console.info("isoDep isExtendedApduSupported data: " + data);
}); }
done(); });
done();
} else {
console.info("[NFC_test]IsoDepTag4 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -162,13 +190,63 @@ export default function nfcIsoDepTagTest() { ...@@ -162,13 +190,63 @@ export default function nfcIsoDepTagTest() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_nfccardEmulationnfc_js_0500', 0, function () { it('SUB_Communication_NFC_nfccardEmulationnfc_js_0500', 0, function () {
if (IsoDepTag != null && IsoDepTag != undefined) {
let cardEmulationnfc ;
try {
cardEmulationnfc = cardEmulation.isSupported(FeatureType.ESE);
console.info('cardEmulationnfc type ->' + cardEmulationnfc )
expect(cardEmulationnfc).assertFalse();
} catch (error) {
console.info('cardEmulationnfc error' + error)
expect(true).assertFalse();
}
} else {
console.info("[NFC_test]IsoDepTag5 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0600
* @tc.name Test cardEmulationnfc
* @tc.desc hasHceCapability to support a certain type of card emulation.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_0600', 0, function () {
let cardEmulationnfc ;
try {
cardEmulationnfc = cardEmulation.hasHceCapability();
console.info('cardEmulationnfc hasHceCapability type ->' + cardEmulationnfc )
expect(cardEmulationnfc).assertFalse();
} catch (error) {
console.info('cardEmulationnfc error' + error)
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0700
* @tc.name Test cardEmulationnfc
* @tc.desc Whether to support a certain type of card isDefaultService.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_0700', 0, function () {
let cardEmulationnfc ; let cardEmulationnfc ;
try{ let elementName = {
cardEmulationnfc = cardEmulation.isSupported(FeatureType.ESE); "bundleName": "com.test.cardemulation",
console.info('cardEmulationnfc type ->' + cardEmulationnfc ) "abilityName": "com.test.cardemulation.MainAbility",
};
try {
cardEmulationnfc = cardEmulation.isDefaultService(elementName, CardType.PAYMENT);
console.info('cardEmulationnfc isDefaultService type ->' + cardEmulationnfc )
expect(cardEmulationnfc).assertFalse(); expect(cardEmulationnfc).assertFalse();
}catch(error){ } catch (error) {
console.info('cardEmulationnfc error' + error) console.info('cardEmulationnfc error' + error)
expect(true).assertFalse();
} }
}) })
...@@ -176,3 +254,4 @@ export default function nfcIsoDepTagTest() { ...@@ -176,3 +254,4 @@ export default function nfcIsoDepTagTest() {
}) })
} }
...@@ -52,10 +52,10 @@ export default function nfcMifareUltralightTag() { ...@@ -52,10 +52,10 @@ export default function nfcMifareUltralightTag() {
console.info('[NFC_test]beforeAll called') console.info('[NFC_test]beforeAll called')
}) })
beforeEach(function() { beforeEach(function() {
try{ try {
MifareUltralightTag = tag.getMifareUltralight(mifareUltralightTaginfo); MifareUltralightTag = tag.getMifareUltralight(mifareUltralightTaginfo);
console.info(' mifareUltralight is' + mifareUltralight) console.info(' mifareUltralight is' + mifareUltralight)
}catch(error){ } catch (error) {
console.info(' mifareUltralight error' + error) console.info(' mifareUltralight error' + error)
} }
console.info('[NFC_test]beforeEach called') console.info('[NFC_test]beforeEach called')
...@@ -77,19 +77,22 @@ export default function nfcMifareUltralightTag() { ...@@ -77,19 +77,22 @@ export default function nfcMifareUltralightTag() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_mifareUltralight_0100', 0, async function (done) { it('SUB_Communication_NFC_mifareUltralight_0100', 0, async function (done) {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let pageIndex = 1;
let pageIndex = 1; await MifareUltralightTag.readMultiplePages(pageIndex).then((data) => {
await MifareUltralightTag.readMultiplePages(pageIndex).then((data) => { console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); expect(data >= 0).assertTrue();
expect(true).assertTrue(data >= 0); done();
done(); }).catch((err)=> {
}).catch((err)=> { console.info("mifareUltralight readMultiplePages1 err: " + err);
console.info("mifareUltralight readMultiplePages1 err: " + err); expect(true).assertEqual(true);
expect(true).assertEqual(true); done();
done(); });
}); sleep(3000);
sleep(3000); } else {
console.info("[NFC_test]mifareUltralight1 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -102,18 +105,23 @@ export default function nfcMifareUltralightTag() { ...@@ -102,18 +105,23 @@ export default function nfcMifareUltralightTag() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_mifareUltralight_0200', 0, async function (done) { it('SUB_Communication_NFC_mifareUltralight_0200', 0, async function (done) {
let pageIndex = 1; if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
MifareUltralightTag.readMultiplePages(pageIndex, (err, data)=> { let pageIndex = 1;
if (err) { MifareUltralightTag.readMultiplePages(pageIndex, (err, data)=> {
console.info("mifareUltralight readMultiplePages2 err: " + err); if (err) {
expect(true).assertEqual(true); console.info("mifareUltralight readMultiplePages2 err: " + err);
} else { expect(true).assertEqual(true);
console.info("mifareUltralight readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data)); } else {
expect(true).assertTrue(data >= 0); console.info("mifareUltralight readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data));
} expect(data >= 0).assertTrue();
}); }
sleep(3000); });
done(); sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight2 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -126,18 +134,23 @@ export default function nfcMifareUltralightTag() { ...@@ -126,18 +134,23 @@ export default function nfcMifareUltralightTag() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_mifareUltralight_0300', 0, async function (done) { it('SUB_Communication_NFC_mifareUltralight_0300', 0, async function (done) {
let pageIndex = 1; if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let rawData = [0x01, 0x02]; let pageIndex = 1;
await MifareUltralightTag.writeSinglePage(pageIndex, rawData).then((data) => { let rawData = [0x01, 0x02];
console.log("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); await MifareUltralightTag.writeSinglePage(pageIndex, rawData).then((data) => {
expect(true).assertTrue(data >= 0); console.log("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data));
done(); expect(data >= 0).assertTrue();
}).catch((err)=> { done();
console.log("mifareUltralight writeSinglePages1 err: " + err); }).catch((err)=> {
expect(true).assertEqual(true); console.log("mifareUltralight writeSinglePages1 err: " + err);
done(); expect(true).assertEqual(true);
}); done();
sleep(3000); });
sleep(3000);
} else {
console.info("[NFC_test]mifareUltralight3 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -150,19 +163,24 @@ export default function nfcMifareUltralightTag() { ...@@ -150,19 +163,24 @@ export default function nfcMifareUltralightTag() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_mifareUltralight_0400', 0, async function (done) { it('SUB_Communication_NFC_mifareUltralight_0400', 0, async function (done) {
let pageIndex = 1; if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let rawData = [0x01, 0x02]; let pageIndex = 1;
MifareUltralightTag.writeSinglePage(pageIndex, rawData, (err, data)=> { let rawData = [0x01, 0x02];
if (err) { MifareUltralightTag.writeSinglePage(pageIndex, rawData, (err, data)=> {
console.log("mifareUltralight writeSinglePages2 err: " + err); if (err) {
expect(true).assertEqual(true); console.log("mifareUltralight writeSinglePages2 err: " + err);
} else { expect(true).assertEqual(true);
console.log("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); } else {
expect(true).assertTrue(data >= 0); console.log("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data));
} expect(data >= 0).assertTrue();
}); }
sleep(3000); });
done(); sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight4 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
/** /**
...@@ -175,9 +193,14 @@ export default function nfcMifareUltralightTag() { ...@@ -175,9 +193,14 @@ export default function nfcMifareUltralightTag() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () { it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () {
let getType = MifareUltralightTag.getType(); if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
console.info("mifareUltralight getType: " + getType); let getType = MifareUltralightTag.getType();
expect(true).assertTrue(getType >= -1); console.info("mifareUltralight getType: " + getType);
expect(getType >= -1).assertTrue();
} else {
console.info("[NFC_test]mifareUltralight5 = null & = undefined: ");
expect(true).assertFalse();
}
}) })
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
...@@ -185,3 +208,4 @@ export default function nfcMifareUltralightTag() { ...@@ -185,3 +208,4 @@ export default function nfcMifareUltralightTag() {
} }
...@@ -122,14 +122,19 @@ export default function nfcTagABFVTest() { ...@@ -122,14 +122,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0100', 0, function () { it('SUB_Communication_NFC_nfctage_js_0100', 0, function () {
let NfcATag ; let NfcATag ;
try{ try {
NfcATag = tag.getNfcATag(aTag); NfcATag = tag.getNfcATag(aTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0100 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcATag != null && NfcATag != undefined) {
expect(NfcATag != null).assertTrue();
expect(NfcATag instanceof Object).assertTrue();
console.info('aTag is--<-!!!->' + JSON.stringify(NfcATag));
} else {
console.info("[NFC_test]NfcATag1 = null & = undefined: ");
expect(true).assertFalse();
} }
expect(NfcATag != null).assertTrue();
expect(NfcATag instanceof Object).assertTrue();
console.info('aTag is--<-!!!->' + JSON.stringify(NfcATag));
}) })
/** /**
...@@ -142,14 +147,19 @@ export default function nfcTagABFVTest() { ...@@ -142,14 +147,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0200', 0, function () { it('SUB_Communication_NFC_nfctage_js_0200', 0, function () {
let NfcBTag ; let NfcBTag ;
try{ try {
NfcBTag = tag.getNfcBTag(bTag); NfcBTag = tag.getNfcBTag(bTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcBTag != null && NfcBTag != undefined) {
expect(NfcBTag != null).assertTrue();
expect(NfcBTag instanceof Object).assertTrue();
console.info('bTag is--<-!!!->' + JSON.stringify(NfcBTag));
} else {
console.info("[NFC_test]NfcBTag1 = null & = undefined: ");
expect(true).assertFalse();
} }
expect(NfcBTag != null).assertTrue();
expect(NfcBTag instanceof Object).assertTrue();
console.info('bTag is--<-!!!->' + JSON.stringify(NfcBTag));
}) })
/** /**
...@@ -162,14 +172,19 @@ export default function nfcTagABFVTest() { ...@@ -162,14 +172,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0300', 0, function () { it('SUB_Communication_NFC_nfctage_js_0300', 0, function () {
let NfcFTag ; let NfcFTag ;
try{ try {
NfcFTag = tag.getNfcFTag(fTag); NfcFTag = tag.getNfcFTag(fTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcFTag != null && NfcFTag != undefined) {
expect(NfcFTag != null).assertTrue();
expect(NfcFTag instanceof Object).assertTrue();
console.info('fTag is--<-!!!->' + JSON.stringify(NfcFTag));
} else {
console.info("[NFC_test]NfcFTag1 = null & = undefined: ");
expect(true).assertFalse();
} }
expect(NfcFTag != null).assertTrue();
expect(NfcFTag instanceof Object).assertTrue();
console.info('fTag is--<-!!!->' + JSON.stringify(NfcFTag));
}) })
/** /**
...@@ -182,14 +197,19 @@ export default function nfcTagABFVTest() { ...@@ -182,14 +197,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0400', 0, function () { it('SUB_Communication_NFC_nfctage_js_0400', 0, function () {
let NfcVTag ; let NfcVTag ;
try{ try {
NfcVTag = tag.getNfcVTag(vTag); NfcVTag = tag.getNfcVTag(vTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0400 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcVTag != null && NfcVTag != undefined) {
expect(NfcVTag != null).assertTrue();
expect(NfcVTag instanceof Object).assertTrue();
console.info('vTag is--<-!!!->' + JSON.stringify(NfcVTag));
} else {
console.info("[NFC_test]NfcVTag1 = null & = undefined: ");
expect(true).assertFalse();
} }
expect(NfcVTag != null).assertTrue();
expect(NfcVTag instanceof Object).assertTrue();
console.info('vTag is--<-!!!->' + JSON.stringify(NfcVTag));
}) })
/** /**
...@@ -202,14 +222,19 @@ export default function nfcTagABFVTest() { ...@@ -202,14 +222,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0500', 0, function () { it('SUB_Communication_NFC_nfctage_js_0500', 0, function () {
let NfcATag ; let NfcATag ;
try{ try {
NfcATag = tag.getNfcATag(aTag); NfcATag = tag.getNfcATag(aTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0500 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcATag != null && NfcATag != undefined) {
let sak = NfcATag.getSak();
expect(sak).assertInstanceOf('Number');
console.info('[nfc_js] test sak data>:' + sak);
} else {
console.info("[NFC_test]NfcATag2 = null & = undefined: ");
expect(true).assertFalse();
} }
let sak = NfcATag.getSak();
expect(sak).assertInstanceOf('Number');
console.info('[nfc_js] test sak data>:' + sak);
}) })
/** /**
...@@ -222,14 +247,19 @@ export default function nfcTagABFVTest() { ...@@ -222,14 +247,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0600', 0, function () { it('SUB_Communication_NFC_nfctage_js_0600', 0, function () {
let NfcATag ; let NfcATag ;
try{ try {
NfcATag = tag.getNfcATag(aTag); NfcATag = tag.getNfcATag(aTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0600 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcATag != null && NfcATag != undefined) {
let Atqa = NfcATag.getAtqa();
expect(Atqa).assertInstanceOf('Array');
console.info('[nfc_js] test Atqa data>:' + Atqa);
} else {
console.info("[NFC_test]NfcATag3 = null & = undefined: ");
expect(true).assertFalse();
} }
let Atqa = NfcATag.getAtqa();
expect(Atqa).assertInstanceOf('Array');
console.info('[nfc_js] test Atqa data>:' + Atqa);
}) })
/** /**
...@@ -242,14 +272,19 @@ export default function nfcTagABFVTest() { ...@@ -242,14 +272,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0700', 0, function () { it('SUB_Communication_NFC_nfctage_js_0700', 0, function () {
let NfcBTag ; let NfcBTag ;
try{ try {
NfcBTag = tag.getNfcBTag(bTag); NfcBTag = tag.getNfcBTag(bTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0700 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcBTag != null && NfcBTag != undefined) {
let AppData = NfcBTag.getRespAppData();
expect(AppData).assertInstanceOf('Array');
console.info('[nfc_js] test AppData data>:' + AppData);
} else {
console.info("[NFC_test]NfcBTag2 = null & = undefined: ");
expect(true).assertFalse();
} }
let AppData = NfcBTag.getRespAppData();
expect(AppData).assertInstanceOf('Array');
console.info('[nfc_js] test AppData data>:' + AppData);
}) })
/** /**
...@@ -262,14 +297,19 @@ export default function nfcTagABFVTest() { ...@@ -262,14 +297,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0800', 0, function () { it('SUB_Communication_NFC_nfctage_js_0800', 0, function () {
let NfcBTag ; let NfcBTag ;
try{ try {
NfcBTag = tag.getNfcBTag(bTag); NfcBTag = tag.getNfcBTag(bTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0800 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcBTag != null && NfcBTag != undefined) {
let Protocol = NfcBTag.getRespProtocol();
expect(Protocol).assertInstanceOf('Array');
console.info('[nfc_js] test Protocol data>:' + Protocol);
} else {
console.info("[NFC_test]NfcBTag3 = null & = undefined: ");
expect(true).assertFalse();
} }
let Protocol = NfcBTag.getRespProtocol();
expect(Protocol).assertInstanceOf('Array');
console.info('[nfc_js] test Protocol data>:' + Protocol);
}) })
/** /**
...@@ -282,14 +322,19 @@ export default function nfcTagABFVTest() { ...@@ -282,14 +322,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_0900', 0, function () { it('SUB_Communication_NFC_nfctage_js_0900', 0, function () {
let NfcFTag ; let NfcFTag ;
try{ try {
NfcFTag = tag.getNfcFTag(fTag); NfcFTag = tag.getNfcFTag(fTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_0900 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcFTag != null && NfcFTag != undefined) {
let SystemCode = NfcFTag.getSystemCode();
expect(SystemCode).assertInstanceOf('Array');
console.info('[nfc_js] test SystemCode data>:' + SystemCode);
} else {
console.info("[NFC_test]NfcFTag2 = null & = undefined: ");
expect(true).assertFalse();
} }
let SystemCode = NfcFTag.getSystemCode();
expect(SystemCode).assertInstanceOf('Array');
console.info('[nfc_js] test SystemCode data>:' + SystemCode);
}) })
/** /**
...@@ -302,14 +347,19 @@ export default function nfcTagABFVTest() { ...@@ -302,14 +347,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_1000', 0, function () { it('SUB_Communication_NFC_nfctage_js_1000', 0, function () {
let NfcFTag ; let NfcFTag ;
try{ try {
NfcFTag = tag.getNfcFTag(fTag); NfcFTag = tag.getNfcFTag(fTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_1000 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcFTag != null && NfcFTag != undefined) {
let Pmm = NfcFTag.getPmm();
expect(Pmm).assertInstanceOf('Array');
console.info('[nfc_js] test Pmm data>:' + Pmm);
} else {
console.info("[NFC_test]NfcFTag3 = null & = undefined: ");
expect(true).assertFalse();
} }
let Pmm = NfcFTag.getPmm();
expect(Pmm).assertInstanceOf('Array');
console.info('[nfc_js] test Pmm data>:' + Pmm);
}) })
/** /**
...@@ -322,14 +372,19 @@ export default function nfcTagABFVTest() { ...@@ -322,14 +372,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_1100', 0, function () { it('SUB_Communication_NFC_nfctage_js_1100', 0, function () {
let NfcVTag ; let NfcVTag ;
try{ try {
NfcVTag = tag.getNfcVTag(vTag); NfcVTag = tag.getNfcVTag(vTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_1100 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcVTag != null && NfcVTag != undefined) {
let ResponseFlags = NfcVTag.getResponseFlags();
expect(ResponseFlags).assertInstanceOf('Number');
console.info('[nfc_js] test ResponseFlags3 data>:' + ResponseFlags);
} else {
console.info("[NFC_test]NfcVTag2 = null & = undefined: ");
expect(true).assertFalse();
} }
let ResponseFlags = NfcVTag.getResponseFlags();
expect(ResponseFlags).assertInstanceOf('Number');
console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags);
}) })
/** /**
...@@ -342,14 +397,19 @@ export default function nfcTagABFVTest() { ...@@ -342,14 +397,19 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_1200', 0, function () { it('SUB_Communication_NFC_nfctage_js_1200', 0, function () {
let NfcVTag ; let NfcVTag ;
try{ try {
NfcVTag = tag.getNfcVTag(vTag); NfcVTag = tag.getNfcVTag(vTag);
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_1200 error' + error) console.info('Nfcget tagABFV error' + error)
}
if (NfcVTag != null && NfcVTag != undefined) {
let DsfId = NfcVTag.getDsfId();
expect(DsfId).assertInstanceOf('Number');
console.info('[nfc_js] test DsfId data>:' + DsfId);
} else {
console.info("[NFC_test]NfcVTag3 = null & = undefined: ");
expect(true).assertFalse();
} }
let DsfId = NfcVTag.getDsfId();
expect(DsfId).assertInstanceOf('Number');
console.info('[nfc_js] test DsfId data>:' + DsfId);
}) })
/** /**
...@@ -362,18 +422,99 @@ export default function nfcTagABFVTest() { ...@@ -362,18 +422,99 @@ export default function nfcTagABFVTest() {
*/ */
it('SUB_Communication_NFC_nfctage_js_1300', 0, function () { it('SUB_Communication_NFC_nfctage_js_1300', 0, function () {
let TagInfo ; let TagInfo ;
try{ try {
TagInfo = tag.getTagInfo(Want); TagInfo = tag.getTagInfo(Want);
console.info('SUB_Communication_NFC_nfctage_js1111111' + TagInfo) console.info('Nfcget tagABFV gettaginfo is: ' + TagInfo)
expect(TagInfo instanceof Object).assertTrue(); expect(TagInfo instanceof Object).assertTrue();
}catch(error){ }catch(error){
console.info('SUB_Communication_NFC_nfctage_js_1300 error' + error) console.info('Nfcget taginfo error' + error)
expect(true).assertTrue(); expect(true).assertTrue();
} }
console.info('[nfc_js] test TagInfo data>:' + TagInfo); console.info('[nfc_js] test TagInfo data>:' + TagInfo);
}) })
/**
* @tc.number SUB_Communication_NFC_nfctage_js_1400
* @tc.name Test getNfcATag
* @tc.desc This interface is used to obtain the NFC A tag object.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_1400', 0, function () {
let NfcATag ;
try {
NfcATag = tag.getNfcA(aTag);
} catch (error) {
console.info('nfc gertaga error' + error)
}
expect(NfcATag != null).assertTrue();
expect(NfcATag instanceof Object).assertTrue();
console.info('aTag is--<-!!!->' + JSON.stringify(NfcATag));
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_1500
* @tc.name Test getNfcBTag
* @tc.desc This interface is used to obtain the NFC B tag object.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_1500', 0, function () {
let NfcBTag ;
try {
NfcBTag = tag.getNfcB(bTag);
} catch (error) {
console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error)
}
expect(NfcBTag != null).assertTrue();
expect(NfcBTag instanceof Object).assertTrue();
console.info('bTag is--<-!!!->' + JSON.stringify(NfcBTag));
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_1600
* @tc.name Test getNfcFTag
* @tc.desc This interface is used to obtain the NFC F tag object.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_1600', 0, function () {
let NfcFTag ;
try {
NfcFTag = tag.getNfcF(fTag);
} catch (error) {
console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error)
}
expect(NfcFTag != null).assertTrue();
expect(NfcFTag instanceof Object).assertTrue();
console.info('fTag is--<-!!!->' + JSON.stringify(NfcFTag));
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_1700
* @tc.name Test getNfcVTag
* @tc.desc This interface is used to obtain the NFC V tag object.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_1700', 0, function () {
let NfcVTag ;
try {
NfcVTag = tag.getNfcV(vTag);
} catch (error) {
console.info('SUB_Communication_NFC_nfctage_js_0400 error' + error)
}
expect(NfcVTag != null).assertTrue();
expect(NfcVTag instanceof Object).assertTrue();
console.info('vTag is--<-!!!->' + JSON.stringify(NfcVTag));
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册