diff --git a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js index c9686491f327b33d6c6d299ebc50766e65a1305b..c748666b308e74e1c2ac504df965038e8d7ebbb9 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js @@ -89,7 +89,7 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[3] = 8; let setting={ interval:150, - txPower:60, + txPower:-10, connectable:true, } let advData={ @@ -145,7 +145,7 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[3] = 8; let setting={ interval:20, - txPower:60, + txPower:-10, connectable:true, } let advData={ @@ -200,8 +200,8 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ - interval:16385, - txPower:60, + interval:10485, + txPower:-10, connectable:true, } let advData={ @@ -256,8 +256,8 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[2] = 7; serviceValueBuffer[3] = 8; let setting={ - interval:16400, - txPower:60, + interval:10500, + txPower:-10, connectable:true, } let advData={ @@ -313,7 +313,7 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[3] = 8; let setting={ interval:19, - txPower:60, + txPower:-10, connectable:true, } let advData={ @@ -705,7 +705,7 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[3] = 8; let setting={ interval:1000, - txPower:70, + txPower:-7, connectable:true, } let advData={ @@ -761,7 +761,7 @@ describe('bluetoothBLETest2', function() { serviceValueBuffer[3] = 8; let setting={ interval:1000, - txPower:70, + txPower:-7, connectable:true, } let advData={ @@ -976,3 +976,4 @@ describe('bluetoothBLETest2', function() { }) } + diff --git a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js index 2e47397577895531a8e42a11b4a19cc35023b06b..91d39d7060daf6a088c00e2b9ef78c8e02d2f870 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -376,34 +376,39 @@ describe('bluetoothBLETest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadCharacteristic_0100', 0, async function (done) { - let descriptors = []; - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBuffer}; - descriptors[0] = descriptor; - let arrayBufferCCC = new ArrayBuffer(8); - let cccValue = new Uint8Array(arrayBufferCCC); - cccValue[0] = 32; - let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', - characteristicValue: arrayBufferCCC, descriptors:descriptors}; - await gattClient.readCharacteristicValue(characteristic).then((data) => { - if (object != null) { - expect(true).assertEqual(true); - } else { + try { + let descriptors = []; + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + descriptors[0] = descriptor; + let arrayBufferCCC = new ArrayBuffer(8); + let cccValue = new Uint8Array(arrayBufferCCC); + cccValue[0] = 32; + let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', + characteristicValue: arrayBufferCCC, descriptors:descriptors}; + await gattClient.readCharacteristicValue(characteristic).then((data) => { console.info('[bluetooth_js] readCharacValue promise data:' + JSON.stringify(data)); - expect(null).assertFail(); - } - done(); - }).catch(err => { - console.error(`bluetooth readCharacteValue promise has error: ${err}`); - expect(true).assertEqual(true); - done(); - }) + expect(true).assertEqual(data.length>=0); + done(); + }).catch(err => { + console.error(`bluetooth readCharacteValue01 promise has error: ${err}`); + expect(true).assertEqual(true); + 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() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue:arrayBuffer}; let arrayBufferCCC = new ArrayBuffer(8); @@ -464,8 +470,7 @@ describe('bluetoothBLETest', function() { let ret = gattServer.sendResponse(serverResponse); console.info('[bluetooth_js] sendResponse ret : ' + ret); expect(ret).assertEqual(false); - } - + } let gattServer = bluetooth.BLE.createGattServer(); await gattServer.on("characteristicRead", ReadCharacteristicReq); await gattServer.off("characteristicRead"); @@ -482,27 +487,28 @@ describe('bluetoothBLETest', function() { * @tc.level Level 2 */ it('SUB_COMMUNICATION_BLUETOOTH_BLE_ReadDescriptor_0100', 0, async function (done) { - let arrayBuffer = new ArrayBuffer(8); - let desValue = new Uint8Array(arrayBuffer); - desValue[0] = 11; - let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', - descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', - descriptorValue: arrayBuffer}; - await gattClient.readDescriptorValue(descriptor).then((object) => { - if (object != null) { - console.error('readDescriptorValue promise object:'+JSON.stringify(object)); + try { + let arrayBuffer = new ArrayBuffer(8); + let desValue = new Uint8Array(arrayBuffer); + desValue[0] = 11; + let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', + descriptorValue: arrayBuffer}; + 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); - - } else { - console.info('[bluetooth_js]readDescripValue null:' + JSON.stringify(object)); - expect(null).assertFail(); - } - done(); - }).catch(err => { - console.error('[bluetooth_js]readDescrValue promise err:'+JSON.stringify(err)); - expect(true).assertEqual(true); - done(); - }) + done(); + }) + } catch (error) { + console.error('[bluetooth_js]readDescrValue01 error code:'+JSON.stringify(error.code)); + expect(error.code).assertEqual(undefined); + done() + } }) /** @@ -528,6 +534,7 @@ describe('bluetoothBLETest', function() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; gattClient.readDescriptorValue(descriptor,readDesc); done() @@ -584,6 +591,7 @@ describe('bluetoothBLETest', function() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; descriptors[0] = descriptor; let arrayBufferCCC = new ArrayBuffer(8); @@ -659,6 +667,7 @@ describe('bluetoothBLETest', function() { let desValue = new Uint8Array(arrayBuffer); desValue[0] = 11; let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; let ret = gattClient.writeDescriptorValue(descriptor); console.info('[bluetooth_js] bluetooth writeDescriptorValue ret : ' + ret); @@ -737,9 +746,11 @@ describe('bluetoothBLETest', function() { let descNotifyValue = new Uint8Array(arrayBufferNotify); descNotifyValue[0] = 1 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBufferNotify}; descriptors[0] = descriptor; @@ -773,9 +784,11 @@ describe('bluetoothBLETest', function() { let descNotifyValue = new Uint8Array(arrayBufferNotify); descNotifyValue[0] = 1 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBufferNotify}; descriptors[0] = descriptor; @@ -831,6 +844,7 @@ describe('bluetoothBLETest', function() { let descNotifyValue = new Uint8Array(arrayBufferNotify); descNotifyValue[0] = 1 let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', + characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', descriptorUuid: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer}; let descriptorNotify = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', @@ -870,3 +884,4 @@ describe('bluetoothBLETest', function() { } + diff --git a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js index 77adbf950877cadced522516f0829a23d48a9f7a..66aae7b887f09c78c25a50b7b435086b06a5412a 100644 --- a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -15,18 +15,6 @@ import bluetooth from '@ohos.bluetooth'; 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() { describe('bluetoothhostTest', function() { @@ -190,8 +178,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 100, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -218,8 +206,8 @@ describe('bluetoothhostTest', function() { } let ScanOptions= { interval: 100, - dutyMode: ScanDuty.SCAN_MODE_BALANCED, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_BALANCED, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent) bluetooth.BLE.startBLEScan([{}],ScanOptions); @@ -250,8 +238,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 100, - dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -284,8 +272,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 100, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -315,8 +303,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 0, - dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -346,8 +334,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -377,8 +365,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: MatchMode.MATCH_MODE_AGGRESSIVE, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, } ); await sleep(1000); @@ -408,8 +396,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, - matchMode: MatchMode.MATCH_MODE_STICKY, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, } ); await sleep(1000); @@ -613,8 +601,8 @@ describe('bluetoothhostTest', function() { [{}], { interval: 500, - dutyMode: ScanDuty.SCAN_MODE_LOW_LATENCY, - matchMode: MatchMode.MATCH_MODE_STICKY, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_LATENCY, + matchMode: bluetooth.MatchMode.MATCH_MODE_STICKY, } ); console.info('[bluetooth_js] BLE scan offC'); @@ -627,3 +615,4 @@ describe('bluetoothhostTest', function() { }) } + diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js index f81a29a43cb4715b19fe1c43519091fd1f4d25b7..696c5a89355440f35b14ca50ff6804cade6cd90b 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -283,21 +283,15 @@ describe('bluetoothhostTest2', function() { * @tc.level Level 3 */ 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) { console.info("[bluetooth_js] bondStateChange on:" + JSON.stringify(data) +'bondStateChange deviceId:' + data.deviceId + 'bondStateChange state:' + data.state); } bluetooth.BLE.on('bondStateChange', BondStateParam); let result = bluetooth.pairDevice("11:22:55:66:33:44"); - expect(BondState.BOND_STATE_INVALID == 0).assertTrue(); - expect(BondState.BOND_STATE_BONDING == 1).assertTrue(); - expect(BondState.BOND_STATE_BONDED == 2).assertTrue(); + expect(bluetooth.BondState.BOND_STATE_INVALID == 0).assertTrue(); + expect(bluetooth.BondState.BOND_STATE_BONDING == 1).assertTrue(); + expect(bluetooth.BondState.BOND_STATE_BONDED == 2).assertTrue(); bluetooth.BLE.off('bondStateChange', BondStateParam); done() }) @@ -308,3 +302,4 @@ describe('bluetoothhostTest2', function() { + diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js index c548b0ace0059a0fe28346e82fb65ea85fc9f018..c4b8f2e62203cb0c507de07d7b341dfe86b3ccac 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js @@ -17,27 +17,6 @@ import bluetooth from '@ohos.bluetooth'; 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() { describe('bluetoothhostTest_host_1', function () { function sleep(delay) { @@ -97,10 +76,10 @@ describe('bluetoothhostTest_host_1', function () { it('SUB_COMMUNICATION_BLUETOOTH_BR_A2DP_Conn_0100', 0, async function (done) { let connState = bluetooth.getBtConnectionState(); console.info('[bluetooth_js] get bt connection state result' + JSON.stringify(connState)); - expect(connState).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); - expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTING!= connState ); - expect(true).assertTrue(ProfileConnectionState.STATE_CONNECTED!= connState ); - expect(true).assertTrue(ProfileConnectionState.STATE_DISCONNECTING!= connState ); + expect(connState).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); + expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTING!= connState ); + expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_CONNECTED!= connState ); + expect(true).assertTrue(bluetooth.ProfileConnectionState.STATE_DISCONNECTING!= connState ); done(); }) @@ -119,7 +98,7 @@ describe('bluetoothhostTest_host_1', function () { 'deviceId: ' + data.deviceId + 'state:'+ data.state); 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)); a2dpSrc.on('connectionStateChange', StateChangeParam); a2dpSrc.connect('11:22:33:44:55:77'); @@ -145,7 +124,7 @@ describe('bluetoothhostTest_host_1', function () { 'deviceId: ' + data.deviceId + 'state:'+ data.state); 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)); a2dpSrc.on('connectionStateChange', StateChangeParam); await sleep(6000); @@ -166,7 +145,7 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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)); let conn = a2dpSrc.disconnect('test'); console.info('[bluetooth_js]a2dp disconnect1 result:' + JSON.stringify(conn)); @@ -184,9 +163,9 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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)); - expect(a2dpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(a2dpSrcConn).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); done(); }) @@ -200,7 +179,7 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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'); console.info('[bluetooth_js]a2dp invaild connect:' + JSON.stringify(conn)); expect(conn).assertFalse(); @@ -217,10 +196,10 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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)); let ret = a2dpSrc.getDeviceState('11:22:33:44:55:66'); - expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); done(); }) @@ -234,10 +213,10 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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)); let ret = a2dpSrc.getDeviceState('test'); - expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); done(); }) @@ -251,12 +230,12 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 3 */ 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)); let state = a2dpSrc.getPlayingState('11:22:33:44:55:66'); console.info('[bluetooth_js]a2dp getPlayingState result:' + JSON.stringify(state)); - expect(state).assertEqual(PlayingState.STATE_NOT_PLAYING); - expect(true).assertEqual(state!=PlayingState.STATE_PLAYING); + expect(state).assertEqual(bluetooth.PlayingState.STATE_NOT_PLAYING); + expect(true).assertEqual(state!=bluetooth.PlayingState.STATE_PLAYING); done(); }) @@ -270,7 +249,7 @@ describe('bluetoothhostTest_host_1', function () { * @tc.level Level 1 */ 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)); let retArray = a2dpSrc.getConnectionDevices(); expect(true).assertEqual(retArray.length>=0); @@ -282,3 +261,4 @@ describe('bluetoothhostTest_host_1', function () { } + diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js index ea5c7ef36eaa80e8027599b18d90508f464a4346..d23024e7c7949af0ae5a5f4441d47d36d56ddfc8 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js @@ -16,20 +16,6 @@ import bluetooth from '@ohos.bluetooth'; 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() { 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) { 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)); - expect(hfpSrcConn).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(hfpSrcConn).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); done(); }) @@ -105,10 +91,10 @@ describe('bluetoothhostTest_host_3', function () { * @tc.level Level 3 */ 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'); console.info('[bluetooth_js]hfp getDeviceState:' + JSON.stringify(ret)); - expect(ret).assertEqual(ProfileConnectionState.STATE_DISCONNECTED); + expect(ret).assertEqual(bluetooth.ProfileConnectionState.STATE_DISCONNECTED); done(); }) @@ -122,10 +108,10 @@ describe('bluetoothhostTest_host_3', function () { * @tc.level Level 3 */ 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'); 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(); }) @@ -144,7 +130,7 @@ describe('bluetoothhostTest_host_3', function () { 'deviceId: ' + data.deviceId + 'state:'+ data.state); 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.connect('11:22:33:44:55:66'); await sleep(6000); @@ -167,7 +153,7 @@ describe('bluetoothhostTest_host_3', function () { 'deviceId: ' + data.deviceId + 'state:'+ data.state); 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); await sleep(10000); let conn = hfpSrc.disconnect('11:22:33:44:55:66'); @@ -187,7 +173,7 @@ describe('bluetoothhostTest_host_3', function () { * @tc.level Level 3 */ 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'); console.info('[bluetooth_js]hfp vaild MAC disconnect :' + JSON.stringify(conn1)); expect(conn1).assertFalse(); @@ -204,7 +190,7 @@ describe('bluetoothhostTest_host_3', function () { * @tc.level Level 3 */ 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)); let conn = hfpSrc.disconnect('test'); console.info('[bluetooth_js]hfp disconnect1 result:' + JSON.stringify(conn)); @@ -222,7 +208,7 @@ describe('bluetoothhostTest_host_3', function () { * @tc.level Level 1 */ 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(); console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); expect(true).assertEqual(retArray.length>=0); @@ -234,3 +220,4 @@ describe('bluetoothhostTest_host_3', function () { } + diff --git a/communication/bluetooth_standard/signature/openharmony_sx.p7b b/communication/bluetooth_standard/signature/openharmony_sx.p7b index 5f165bc5913d474d4e5bd0e5a2f3b492f5087a63..c95c429c5d230624c1e408e2f49dbc8833681ae6 100644 Binary files a/communication/bluetooth_standard/signature/openharmony_sx.p7b and b/communication/bluetooth_standard/signature/openharmony_sx.p7b differ diff --git a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js index fba4907f4199ac65283dadcaa77af010895ad898..16f8ea8311584ec4ebfdced79b89479b1706821e 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js @@ -14,17 +14,26 @@ */ 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' -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, - } +const PERMISSION_USER_SET = 1; +const PERMISSION_USER_NAME1 = "ohos.permission.LOCATION"; +const PERMISSION_USER_NAME2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; +let tokenID = undefined; +async function grantPerm() { + console.info("====grant Permission start===="); + let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, 100); + 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() { describe('bluetoothhostTest3', function() { function sleep(delay) { @@ -57,8 +66,11 @@ describe('bluetoothhostTest3', function() { console.info('[bluetooth_js] enable success'); } } - beforeAll(function () { + + beforeAll(async function (done) { console.info('beforeAll called') + await grantPerm(); + done() }) beforeEach(async function(done) { console.info('beforeEach called') @@ -109,11 +121,11 @@ describe('bluetoothhostTest3', function() { * @tc.level Level 1 */ 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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(); await sleep(2000); console.info('[bluetooth_js] startDiscovery1'+result); @@ -126,3 +138,4 @@ describe('bluetoothhostTest3', function() { }) } + diff --git a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js index 960f2c7e3a6d2481d7cacba96447547445b3dc2b..a18e3d25e32951c6d4ca0eb4637825f18e69c2b2 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js @@ -15,15 +15,7 @@ import bluetooth from '@ohos.bluetooth'; 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() { describe('bluetoothhostTest2', function() { function sleep(delay) { @@ -82,11 +74,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0100', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -107,11 +99,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0200', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -132,11 +124,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0300', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -157,11 +149,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0400', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -181,11 +173,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0500', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -206,11 +198,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0600', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -231,11 +223,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0700', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -256,11 +248,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0800', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -281,11 +273,11 @@ describe('bluetoothhostTest2', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_ScanMode_0900', 0, async function (done) { let oldScanMode = bluetooth.getBluetoothScanMode(); 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(); let getScanMode = bluetooth.getBluetoothScanMode(); 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); expect(result).assertTrue(); let getOldScanMode = bluetooth.getBluetoothScanMode(); @@ -317,3 +309,4 @@ describe('bluetoothhostTest2', function() { }) } + diff --git a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js index 35f8c03f6179208f6a4c8dc6a89937c2bffe5ff1..a9b1974e9517cb326237567dd1cb354e387b46bf 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js @@ -71,11 +71,8 @@ describe('bluetoothhostTest4', function() { * @tc.level Level 1 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_SPP_0100', 0, async function (done) { - let SppType = { - SPP_RFCOMM : 0 - } let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', - secure: true, type: SppType.SPP_RFCOMM}; + secure: true, type: bluetooth.SppType.SPP_RFCOMM}; let serverNumber = -1; function serverSocket(code, number) { if (code) { @@ -392,3 +389,4 @@ describe('bluetoothhostTest4', function() { } + diff --git a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js index 21120def33c4339641e060ee540937ce5770499d..e5566ea1087a5670588aaf4947d62c06291e4079 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js @@ -15,17 +15,7 @@ import bluetooth from '@ohos.bluetooth'; 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() { describe('bluetoothhostTest', function() { function sleep(delay) { @@ -88,7 +78,7 @@ describe('bluetoothhostTest', function() { await bluetooth.on('stateChange', onReceiveEvent); let state = bluetooth.getState(); 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(); await sleep(5000); @@ -96,7 +86,7 @@ describe('bluetoothhostTest', function() { expect(enable).assertTrue(); let state1 = bluetooth.getState(); 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(); await sleep(3000); @@ -104,7 +94,7 @@ describe('bluetoothhostTest', function() { expect(disable).assertTrue(); let state2 = bluetooth.getState(); 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); done() }) @@ -121,15 +111,15 @@ describe('bluetoothhostTest', function() { it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) { let state = bluetooth.getState(); console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state)); - expect(state).assertEqual(BluetoothState.STATE_ON); - if(state==BluetoothState.STATE_ON) { + expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON); + if(state==bluetooth.BluetoothState.STATE_ON) { let enable1=bluetooth.enableBluetooth(); await sleep(3000); console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1)); expect(enable1).assertFalse(); let state1 = bluetooth.getState(); console.info('[bluetooth_js] bt open state2='+ JSON.stringify(state1)); - expect(state1).assertEqual(BluetoothState.STATE_ON); + expect(state1).assertEqual(bluetooth.BluetoothState.STATE_ON); }else{ console.info('[bluetooth_js]bluetooth open fail'); } @@ -152,17 +142,18 @@ describe('bluetoothhostTest', function() { expect(result1).assertTrue(); let state = bluetooth.getState(); console.info('[bluetooth_js] getState1 off = '+ JSON.stringify(state)); - expect(state).assertEqual(BluetoothState.STATE_OFF); - if(state == BluetoothState.STATE_OFF) { + expect(state).assertEqual(bluetooth.BluetoothState.STATE_OFF); + if(state == bluetooth.BluetoothState.STATE_OFF) { let result2= bluetooth.disableBluetooth(); console.info('[bluetooth_js]disable result1'+ JSON.stringify(result2)); expect(result2).assertFalse(); let state1 = bluetooth.getState(); console.info('[bluetooth_js] getState4 off = '+ JSON.stringify(state1)); - expect(state1).assertEqual(BluetoothState.STATE_OFF); + expect(state1).assertEqual(bluetooth.BluetoothState.STATE_OFF); } done(); }) }) } + diff --git a/communication/nfc_Controller/src/main/js/test/List.test.js b/communication/nfc_Controller/src/main/js/test/List.test.js index 4a2351772b508c55d98eba94ac8a2c45e1244f6e..eee4d6bc73cb482a60b1c6242c1da254fff4887d 100644 --- a/communication/nfc_Controller/src/main/js/test/List.test.js +++ b/communication/nfc_Controller/src/main/js/test/List.test.js @@ -28,12 +28,11 @@ if (info != "false") { nfcATagSessionTest(); nfcControllerTest(); + ConnectedTagTest(); nfcIsoDepTagTest(); nfcMifareClassicTag(); nfcMifareUltralightTag(); - nfcTagABFVTest(); nfcNDEFTagTest(); - ConnectedTagTest(); + nfcTagABFVTest(); } } - diff --git a/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js b/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js index f00c92715fbbc23440af62682caf38b4a1f554e7..16aedd625e796de0f73d4619e1aae1937899f2ad 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js @@ -34,11 +34,18 @@ let aTag = { ], "tagRfDiscId": 1, }; +let getAtag = null ; export default function nfcATagSessionTest() { describe('nfcATagSessionTest', function () { beforeAll(function () { 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() { console.info('[NFC_test]beforeEach called') @@ -59,13 +66,19 @@ export default function nfcATagSessionTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0100', 0, function () { - let NfcConnected; - try{ - NfcConnected = tag.getNfcATag(aTag).connectTag(); - console.info("NfcConnected:" +NfcConnected); - expect(NfcConnected).assertFalse(); - }catch(error){ - console.info('NfcConnected error' + error) + if (getAtag != null && getAtag != undefined) { + let NfcConnected; + try { + NfcConnected = getAtag.connectTag(); + console.info("NfcConnected:" + NfcConnected); + expect(NfcConnected).assertFalse(); + } 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0200', 0, function () { - try{ - tag.getNfcATag(aTag).reset(); - expect(true).assertTrue(); - console.info('reset1 pass' ) - }catch(error){ - console.info('reset1 error' + error) + if (getAtag != null && getAtag != undefined) { + try { + getAtag.reset(); + expect(true).assertTrue(); + console.info('reset1 pass' ) + } 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0300', 0, function () { - let isNfcConnected; - try{ - isNfcConnected = tag.getNfcATag(aTag).isTagConnected(); - console.info("isNfcConnected:" +isNfcConnected); - expect(isNfcConnected).assertFalse(); - }catch(error){ - console.info('isNfcConnected error' + error) + if (getAtag != null && getAtag != undefined) { + let isNfcConnected; + try { + isNfcConnected = getAtag.isTagConnected(); + console.info("isNfcConnected:" +isNfcConnected); + expect(isNfcConnected).assertFalse(); + } 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0400', 0, function () { - let mazSendLen; - try{ - mazSendLen = tag.getNfcATag(aTag).getMaxSendLength(); - console.info("getMaxSendLength:" +mazSendLen); - expect(true).assertTrue(mazSendLen >= 0); - console.info('getMaxSendLength pass' ) - }catch(error){ - console.info('getMaxSendLength error' + error) + if (getAtag != null && getAtag != undefined) { + let mazSendLen; + try { + mazSendLen = getAtag.getMaxSendLength(); + console.info("getMaxSendLength:" + mazSendLen); + expect(mazSendLen >= 0).assertTrue(); + console.info('getMaxSendLength pass' ) + } 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0500', 0, function () { - let settime; - try{ - settime = tag.getNfcATag(aTag).setSendDataTimeout(1000); - console.info("setSendDataTimeout:" +settime); - expect(true).assertTrue(settime >= 0); - }catch(error){ - console.info('setSendDataTimeout error' + error) + if (getAtag != null && getAtag != undefined) { + let settime; + try { + settime = getAtag.setSendDataTimeout(1000); + console.info("setSendDataTimeout:" + settime); + expect(settime >= 0).assertTrue(); + } 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcAtage_js_0600', 0, function () { - let gettime; - try{ - gettime = tag.getNfcATag(aTag).getSendDataTimeout(); - console.info("getMaxSendLength:" +gettime + 'aTag is--<-!!!->' + JSON.stringify(gettime)); - expect(true).assertTrue(gettime >= 0); - console.info('getMaxSendLength pass' ) - }catch(error){ - console.info('getMaxSendLength error' + error) + if (getAtag != null && getAtag != undefined) { + let gettime; + try { + gettime = getAtag.getSendDataTimeout(); + console.info("getMaxSendLength:" + gettime + 'aTag is--<-!!!->' + JSON.stringify(gettime)); + expect(gettime >= 0).assertTrue(); + console.info('getMaxSendLength pass' ) + } 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() { * @tc.level Level 2 */ 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]; - 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)); - expect(true).assertTrue(data >= 0); + expect(data >= 0).assertTrue(); done(); }).catch((err)=> { console.log("nfcAtage sendData1 err: " + err); + expect(true).assertTrue(); }); sleep(3500); }) /** - * @tc.number SUB_Communication_NFC_nfcAtage_js_0800 + * @tc.number SUB_Communication_NFC_nfcAtage_js_1200 * @tc.name testsendData * @tc.desc Test sendData api by callback. * @tc.size MEDIUM @@ -200,22 +342,46 @@ export default function nfcATagSessionTest() { * @tc.type Function * @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]; - tag.getNfcATag(aTag).sendData(sendDatas, (err, data)=> { + tag.getNfcATag(aTag).transmit(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(true).assertTrue(data >= 0); + expect(data >= 0).assertTrue(); } }); sleep(500); 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*************"); }) } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js index 8a270e5513dbd409953168e1a5bddc5b3fdd05eb..18f02e8c7e6b30bd57fc9196b933338245cd27c4 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js @@ -58,11 +58,10 @@ export default function ConnectedTagTest() { if (!isAccessToken) { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() - } - else{ + } else { let inittag = connectedTag.init(); expect(inittag).assertTrue(); - console.info("mifareUltralight readMultiplePages1 err: " + inittag ); + console.info("ConnectedTag readMultiplePages1 err: " + inittag ); } }) @@ -81,14 +80,13 @@ export default function ConnectedTagTest() { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() done(); - } - else{ + } else { await connectedTag.readNdefTag().then(result => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); - expect(true).assertTrue(result != null); + console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); + console.info("ConnectedTag readMultiplePages1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -111,8 +109,7 @@ export default function ConnectedTagTest() { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() done(); - } - else{ + } else { connectedTag.readNdefTag((err, result)=> { if (err) { expect().assertFail(); @@ -141,14 +138,13 @@ export default function ConnectedTagTest() { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() done(); - } - else{ + } else { await connectedTag.writeNdefTag().then(result => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); - expect(true).assertTrue(result != null); + console.info("ConnectedTag readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(result != null).assertTrue(); done(); }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); + console.info("ConnectedTag readMultiplePages1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -170,8 +166,7 @@ export default function ConnectedTagTest() { if (!isAccessToken) { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() - } - else{ + } else { connectedTag.writeNdefTag((err, result)=> { if (err) { expect().assertFail(); @@ -199,8 +194,7 @@ export default function ConnectedTagTest() { if (!isAccessToken) { console.info("The device does not support active label chips.") expect(isAccessToken).assertFalse() - } - else{ + } else { let recvNfcRfNotifyFunc = result => { console.info("nfc state receive state ->" + result); expect(result != null).assertTrue(); @@ -219,6 +213,27 @@ export default function ConnectedTagTest() { * @tc.level Level 2 */ 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"); console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken); if (!isAccessToken) { @@ -226,14 +241,155 @@ export default function ConnectedTagTest() { expect(isAccessToken).assertFalse() } 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(); 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*************"); }) } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.Controller.js b/communication/nfc_Controller/src/main/js/test/nfc.Controller.js index aa279b8e17f8b869ef01273b8f566cdb49d8cc3f..5d24aad2d79c38685a8e868f4afca47cf7eaae35 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.Controller.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.Controller.js @@ -34,11 +34,17 @@ let NfcState={ export default function nfcControllerTest() { describe('nfcControllerTest', function () { - beforeEach(function () { - console.info("[NFC_test]beforeEach start" ); + beforeAll(function () { + console.info('[NFC_test]beforeAll called') }) - afterEach(async function () { - console.info("[NFC_test]afterEach start" ); + beforeEach(function() { + 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() { + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js b/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js index 1d7cef83d01ffb9ef9ca36d8c0f1de6db58ac45e..8ab4a87052a8c53186891653add415b4b0cd7558 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js @@ -16,6 +16,7 @@ import tag from '@ohos.nfc.tag'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import cardEmulation from '@ohos.nfc.cardEmulation'; function sleep(delay) { // delay x ms let start = (new Date()).getTime(); @@ -63,14 +64,21 @@ let isoDepTaginfo = { ], "tagRfDiscId": 1, }; + +let CardType = { + PAYMENT : "payment", + OTHER : "other", +}; + let IsoDepTag ; + export default function nfcIsoDepTagTest() { describe('nfcIsoDepTagTest', function () { beforeAll(function () { console.info('[NFC_test]beforeAll called') - try{ + try { IsoDepTag = tag.getIsoDep(isoDepTaginfo); - }catch(error){ + } catch (error) { console.info('getIsoDep is ->' + error) } }) @@ -93,9 +101,14 @@ export default function nfcIsoDepTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, function () { - let ResponseFlags = IsoDepTag.getHistoricalBytes(); - expect(ResponseFlags).assertInstanceOf('Array') - console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags); + if (IsoDepTag != null && IsoDepTag != undefined) { + let ResponseFlags = IsoDepTag.getHistoricalBytes(); + 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, function () { - let HiLayerResponse = IsoDepTag.getHiLayerResponse(); - expect(HiLayerResponse).assertInstanceOf('Array') - console.info('[nfc_js] test ResponseFlags data>:' + HiLayerResponse); + if (IsoDepTag != null && IsoDepTag != undefined) { + let HiLayerResponse = IsoDepTag.getHiLayerResponse(); + 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() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, async function (done) { - await IsoDepTag.isExtendedApduSupported().then((data) => { - expect(false).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + data); - done(); - }).catch((err)=> { - console.info("isoDep isExtendedApduSupported err: " + err); - expect().assertFail(); - done(); - }); + if (IsoDepTag != null && IsoDepTag != undefined) { + await IsoDepTag.isExtendedApduSupported().then((data) => { + expect(false).assertEqual(data); + console.info("isoDep isExtendedApduSupported data: " + data); + done(); + }).catch((err)=> { + console.info("isoDep isExtendedApduSupported err: " + err); + expect(true).assertFalse(); + done(); + }); + } else { + console.info("[NFC_test]IsoDepTag3 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -141,16 +164,21 @@ export default function nfcIsoDepTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcIsoDep_js_0400', 0, async function (done) { - IsoDepTag.isExtendedApduSupported((err, data)=> { - if (err) { - expect().assertFail(); - console.info("isoDep isExtendedApduSupported err: " + err); - } else { - expect(false).assertEqual(data); - console.info("isoDep isExtendedApduSupported data: " + data); - } - }); - done(); + if (IsoDepTag != null && IsoDepTag != undefined) { + IsoDepTag.isExtendedApduSupported((err, data)=> { + if (err) { + expect(true).assertFalse(); + console.info("isoDep isExtendedApduSupported err: " + err); + } else { + expect(false).assertEqual(data); + console.info("isoDep isExtendedApduSupported data: " + data); + } + }); + done(); + } else { + console.info("[NFC_test]IsoDepTag4 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -162,13 +190,63 @@ export default function nfcIsoDepTagTest() { * @tc.level Level 2 */ 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 ; - try{ - cardEmulationnfc = cardEmulation.isSupported(FeatureType.ESE); - console.info('cardEmulationnfc type ->' + cardEmulationnfc ) + let elementName = { + "bundleName": "com.test.cardemulation", + "abilityName": "com.test.cardemulation.MainAbility", + }; + try { + cardEmulationnfc = cardEmulation.isDefaultService(elementName, CardType.PAYMENT); + console.info('cardEmulationnfc isDefaultService type ->' + cardEmulationnfc ) expect(cardEmulationnfc).assertFalse(); - }catch(error){ + } catch (error) { console.info('cardEmulationnfc error' + error) + expect(true).assertFalse(); } }) @@ -176,3 +254,4 @@ export default function nfcIsoDepTagTest() { }) } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js b/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js index 20e74d9a47beda6be232a3a26bcacc86dcf0a1a5..cfea7489591866d6c48a8338e9a767d41fc374ec 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js @@ -58,7 +58,7 @@ export default function nfcMifareClassicTag() { console.info('[NFC_test]beforeAll called') try{ MifareClassicTag = tag.getMifareClassic(mifareclassicTaginfo); - }catch(error){ + } catch (error) { console.info('beforeAll mifareClassic error' + error) } }) @@ -70,9 +70,7 @@ export default function nfcMifareClassicTag() { }) afterAll(function () { console.info('[NFC_test]afterAll called') - }) - - + }) /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0100 @@ -84,20 +82,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0100', 0, async function (done) { - let sectorIndex = 1; - let key = [0x04, 0x05]; - await MifareClassicTag.authenticateSector(sectorIndex, key, true).then((data) => { - console.info("mifareClassic authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); - expect(data).assertTrue(); - done(); - }).catch((err)=> { - console.info("mifareClassic authenticateSector1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let sectorIndex = 1; + let key = [0x04, 0x05]; + await MifareClassicTag.authenticateSector(sectorIndex, key, true).then((data) => { + console.info("mifareClassic authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); + expect(data).assertTrue(); + done(); + }).catch((err)=> { + console.info("mifareClassic authenticateSector1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag1 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0200 @@ -109,21 +111,25 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0200', 0, async function (done) { - let sectorIndex = 1; - let key = [0x04, 0x05]; - MifareClassicTag.authenticateSector(sectorIndex, key, true, (err, data)=> { - if (err) { - console.info("mifareClassic authenticateSector2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); - expect(data).assertTrue(); - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let sectorIndex = 1; + let key = [0x04, 0x05]; + MifareClassicTag.authenticateSector(sectorIndex, key, true, (err, data)=> { + if (err) { + console.info("mifareClassic authenticateSector2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); + expect(data).assertTrue(); + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag2 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0300 @@ -135,19 +141,23 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0300', 0, async function (done) { - let blockIndex = 1; - await MifareClassicTag.readSingleBlock(blockIndex).then((data) => { - console.info("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Array') - done(); - }).catch((err)=> { - console.info("mifareClassic readSingleBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + await MifareClassicTag.readSingleBlock(blockIndex).then((data) => { + console.info("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Array') + done(); + }).catch((err)=> { + console.info("mifareClassic readSingleBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag3 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0400 @@ -159,19 +169,23 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0400', 0, async function (done) { - let blockIndex = 1; - MifareClassicTag.readSingleBlock(blockIndex, (err, data)=> { - if (err) { - console.info("mifareClassic readSingleBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Array') - } - }); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + MifareClassicTag.readSingleBlock(blockIndex, (err, data)=> { + if (err) { + console.info("mifareClassic readSingleBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Array') + } + }); + done(); + } else { + console.info("[NFC_test]MifareClassicTag4 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0500 @@ -183,20 +197,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0500', 0, async function (done) { - let blockIndex = 1; - let rawData = [0x0a, 0x14]; - await MifareClassicTag.writeSingleBlock(blockIndex, rawData).then((data) => { - console.info("mifareClassic writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); - expect(data).assertTrue(); - done(); - }).catch((err)=> { - console.info("mifareClassic writeSingleBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let rawData = [0x0a, 0x14]; + await MifareClassicTag.writeSingleBlock(blockIndex, rawData).then((data) => { + console.info("mifareClassic writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); + expect(data).assertTrue(); + done(); + }).catch((err)=> { + console.info("mifareClassic writeSingleBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag5 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0600 @@ -208,21 +226,25 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0600', 0, async function (done) { - let blockIndex = 1; - let rawData = [0x0a, 0x14]; - MifareClassicTag.writeSingleBlock(blockIndex, rawData, (err, data)=> { - if (err) { - console.info("mifareClassic writeSingleBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); - expect(data).assertTrue(); - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let rawData = [0x0a, 0x14]; + MifareClassicTag.writeSingleBlock(blockIndex, rawData, (err, data)=> { + if (err) { + console.info("mifareClassic writeSingleBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); + expect(data).assertTrue(); + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag6 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0700 @@ -234,20 +256,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0700', 0, async function (done) { - let blockIndex = 1; - let value = 0x20; - await MifareClassicTag.incrementBlock(blockIndex, value).then((data) => { - console.info("mifareClassic incrementBlock1 data: " + data + "json7:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - done(); - }).catch((err)=> { - console.info("mifareClassic incrementBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let value = 0x20; + await MifareClassicTag.incrementBlock(blockIndex, value).then((data) => { + console.info("mifareClassic incrementBlock1 data: " + data + "json7:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + done(); + }).catch((err)=> { + console.info("mifareClassic incrementBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag7 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0800 @@ -259,21 +285,25 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0800', 0, async function (done) { - let blockIndex = 1; - let value = 0x20; - MifareClassicTag.incrementBlock(blockIndex, value, (err, data)=> { - if (err) { - console.info("mifareClassic incrementBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let value = 0x20; + MifareClassicTag.incrementBlock(blockIndex, value, (err, data)=> { + if (err) { + console.info("mifareClassic incrementBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag8 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_0900 @@ -285,20 +315,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_0900', 0, async function (done) { - let blockIndex = 1; - let value = 0x20; - await MifareClassicTag.decrementBlock(blockIndex, value).then((data) => { - console.info("mifareClassic decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - done(); - }).catch((err)=> { - console.info("mifareClassic decrementBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let value = 0x20; + await MifareClassicTag.decrementBlock(blockIndex, value).then((data) => { + console.info("mifareClassic decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + done(); + }).catch((err)=> { + console.info("mifareClassic decrementBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag9 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1000 @@ -310,21 +344,25 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1000', 0, async function (done) { - let blockIndex = 1; - let value = 0x20; - MifareClassicTag.decrementBlock(blockIndex, value, (err, data)=> { - if (err) { - console.info("mifareClassic decrementBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + let value = 0x20; + MifareClassicTag.decrementBlock(blockIndex, value, (err, data)=> { + if (err) { + console.info("mifareClassic decrementBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag10 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1100 @@ -336,19 +374,23 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1100', 0, async function (done) { - let blockIndex = 1; - await MifareClassicTag.transferToBlock(blockIndex).then((data) => { - console.info("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - done(); - }).catch((err)=> { - console.info("mifareClassic transferToBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + await MifareClassicTag.transferToBlock(blockIndex).then((data) => { + console.info("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + done(); + }).catch((err)=> { + console.info("mifareClassic transferToBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag11 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1200 @@ -360,20 +402,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1200', 0, async function (done) { - let blockIndex = 1; - MifareClassicTag.transferToBlock(blockIndex, (err, data)=> { - if (err) { - console.info("mifareClassic transferToBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + MifareClassicTag.transferToBlock(blockIndex, (err, data)=> { + if (err) { + console.info("mifareClassic transferToBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag12 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1300 @@ -385,19 +431,23 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1300', 0, async function (done) { - let blockIndex = 1; - await MifareClassicTag.restoreFromBlock(blockIndex).then((data) => { - console.info("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - done(); - }).catch((err)=> { - console.info("mifareClassic restoreFromBlock1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + await MifareClassicTag.restoreFromBlock(blockIndex).then((data) => { + console.info("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + done(); + }).catch((err)=> { + console.info("mifareClassic restoreFromBlock1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]MifareClassicTag13 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1400 @@ -409,20 +459,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1400', 0, async function (done) { - let blockIndex = 1; - MifareClassicTag.restoreFromBlock(blockIndex, (err, data)=> { - if (err) { - console.info("mifareClassic restoreFromBlock2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); - expect(data).assertInstanceOf('Number') - } - }); - sleep(3000); - done(); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + let blockIndex = 1; + MifareClassicTag.restoreFromBlock(blockIndex, (err, data)=> { + if (err) { + console.info("mifareClassic restoreFromBlock2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); + expect(data).assertInstanceOf('Number') + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]MifareClassicTag14 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1500 @@ -434,11 +488,20 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1500', 0, function () { - let sectorCount = MifareClassicTag.getSectorCount(); - console.info("mifareClassic sectorCount: " + sectorCount); - expect(sectorCount).assertInstanceOf('Number') + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let sectorCount = MifareClassicTag.getSectorCount(); + console.info("mifareClassic sectorCount: " + sectorCount); + expect(sectorCount).assertInstanceOf('Number') + } catch (error) { + console.info('mifareClassic sectorCount error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag15 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1600 @@ -450,11 +513,21 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1600', 0, function () { - let blockCountInSector = MifareClassicTag.getBlockCountInSector(); - console.info("mifareClassic blockCountInSector: " + blockCountInSector); - expect(blockCountInSector).assertInstanceOf('Number') + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let sectorIndex = 1; + let blockCountInSector = MifareClassicTag.getBlockCountInSector(sectorIndex); + console.info("mifareClassic blockCountInSector: " + blockCountInSector); + expect(blockCountInSector).assertInstanceOf('Number') + } catch (error) { + console.info('mifareClassic blockCountInSector error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag16 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1700 @@ -466,11 +539,20 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1700', 0, function () { - let getType = MifareClassicTag.getType(); - console.info("mifareClassic getType: " + getType); - expect(true).assertTrue(getType >= -1); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let getType = MifareClassicTag.getType(); + console.info("mifareClassic getType: " + getType); + expect(getType >= -1).assertTrue(); + } catch (error) { + console.info('mifareClassic getType error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag17 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1800 @@ -482,11 +564,20 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1800', 0, function () { - let tagSize = MifareClassicTag.getTagSize(); - console.info("mifareClassic tagSize: " + tagSize); - expect(tagSize).assertInstanceOf('Number') - }) - + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let tagSize = MifareClassicTag.getTagSize(); + console.info("mifareClassic tagSize: " + tagSize); + expect(tagSize).assertInstanceOf('Number') + } catch (error) { + console.info('mifareClassic tagSize error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag18 = null & = undefined: "); + expect(true).assertFalse(); + } + }) /** * @tc.number SUB_Communication_NFC_mifareClassic_js_1900 @@ -498,11 +589,20 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_1900', 0, function () { - let isEmulatedTag = MifareClassicTag.isEmulatedTag(); - console.info("mifareClassic isEmulatedTag: " + isEmulatedTag); - expect(false).assertEqual(isEmulatedTag); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let isEmulatedTag = MifareClassicTag.isEmulatedTag(); + console.info("mifareClassic isEmulatedTag: " + isEmulatedTag); + expect(false).assertEqual(isEmulatedTag); + } catch (error) { + console.info('mifareClassic isEmulatedTag error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag19 = null & = undefined: "); + expect(true).assertFalse(); + } }) - /** * @tc.number SUB_Communication_NFC_mifareClassic_js_2000 @@ -514,12 +614,21 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_2000', 0, function () { - let sectorIndex = 1; - let blockIndex = MifareClassicTag.getBlockIndex(sectorIndex); - console.info("mifareClassic blockIndex: " + blockIndex); - expect(true).assertTrue(blockIndex >= 0); - }) - + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let sectorIndex = 1; + let blockIndex = MifareClassicTag.getBlockIndex(sectorIndex); + console.info("mifareClassic blockIndex: " + blockIndex); + expect(blockIndex >= 0).assertTrue(); + } catch (error) { + console.info('mifareClassic blockIndex error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag20 = null & = undefined: "); + expect(true).assertFalse(); + } + }) /** * @tc.number SUB_Communication_NFC_mifareClassic_js_2100 @@ -531,13 +640,24 @@ export default function nfcMifareClassicTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareClassic_js_2100', 0, function () { - let blockIndex = 1; - let sectorIndex = MifareClassicTag.getSectorIndex(blockIndex); - console.info("mifareClassic sectorIndex: " + sectorIndex); - expect(true).assertTrue(sectorIndex >= 0); + if (MifareClassicTag != null && MifareClassicTag != undefined) { + try{ + let blockIndex = 1; + let sectorIndex = MifareClassicTag.getSectorIndex(blockIndex); + console.info("mifareClassic sectorIndex: " + sectorIndex); + expect(sectorIndex >= 0).assertTrue(); + } catch (error) { + console.info('mifareClassic sectorIndex error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]MifareClassicTag21 = null & = undefined: "); + expect(true).assertFalse(); + } }) - + console.info("*************[nfc_test] start nfc js unit test end*************"); }) } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js index 7e8f9e5eb2a288de527ae607d6a0be10ec4d62ac..4c33bc7b52e948681b59063f4405ccae567b6820 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js @@ -52,10 +52,10 @@ export default function nfcMifareUltralightTag() { console.info('[NFC_test]beforeAll called') }) beforeEach(function() { - try{ + try { MifareUltralightTag = tag.getMifareUltralight(mifareUltralightTaginfo); console.info(' mifareUltralight is' + mifareUltralight) - }catch(error){ + } catch (error) { console.info(' mifareUltralight error' + error) } console.info('[NFC_test]beforeEach called') @@ -77,19 +77,22 @@ export default function nfcMifareUltralightTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareUltralight_0100', 0, async function (done) { - - - let pageIndex = 1; - await MifareUltralightTag.readMultiplePages(pageIndex).then((data) => { - console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); - expect(true).assertTrue(data >= 0); - done(); - }).catch((err)=> { - console.info("mifareUltralight readMultiplePages1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareUltralightTag != null && MifareUltralightTag != undefined) { + let pageIndex = 1; + await MifareUltralightTag.readMultiplePages(pageIndex).then((data) => { + console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(data >= 0).assertTrue(); + done(); + }).catch((err)=> { + console.info("mifareUltralight readMultiplePages1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]mifareUltralight1 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -102,18 +105,23 @@ export default function nfcMifareUltralightTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareUltralight_0200', 0, async function (done) { - let pageIndex = 1; - MifareUltralightTag.readMultiplePages(pageIndex, (err, data)=> { - if (err) { - console.info("mifareUltralight readMultiplePages2 err: " + err); - expect(true).assertEqual(true); - } else { - console.info("mifareUltralight readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data)); - expect(true).assertTrue(data >= 0); - } - }); - sleep(3000); - done(); + if (MifareUltralightTag != null && MifareUltralightTag != undefined) { + let pageIndex = 1; + MifareUltralightTag.readMultiplePages(pageIndex, (err, data)=> { + if (err) { + console.info("mifareUltralight readMultiplePages2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareUltralight readMultiplePages2 data: " + data + "json2:" + JSON.stringify(data)); + expect(data >= 0).assertTrue(); + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]mifareUltralight2 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -126,18 +134,23 @@ export default function nfcMifareUltralightTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareUltralight_0300', 0, async function (done) { - let pageIndex = 1; - let rawData = [0x01, 0x02]; - await MifareUltralightTag.writeSinglePage(pageIndex, rawData).then((data) => { - console.log("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); - expect(true).assertTrue(data >= 0); - done(); - }).catch((err)=> { - console.log("mifareUltralight writeSinglePages1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); + if (MifareUltralightTag != null && MifareUltralightTag != undefined) { + let pageIndex = 1; + let rawData = [0x01, 0x02]; + await MifareUltralightTag.writeSinglePage(pageIndex, rawData).then((data) => { + console.log("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(data >= 0).assertTrue(); + done(); + }).catch((err)=> { + console.log("mifareUltralight writeSinglePages1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]mifareUltralight3 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -150,19 +163,24 @@ export default function nfcMifareUltralightTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareUltralight_0400', 0, async function (done) { - let pageIndex = 1; - let rawData = [0x01, 0x02]; - MifareUltralightTag.writeSinglePage(pageIndex, rawData, (err, data)=> { - if (err) { - console.log("mifareUltralight writeSinglePages2 err: " + err); - expect(true).assertEqual(true); - } else { - console.log("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); - expect(true).assertTrue(data >= 0); - } - }); - sleep(3000); - done(); + if (MifareUltralightTag != null && MifareUltralightTag != undefined) { + let pageIndex = 1; + let rawData = [0x01, 0x02]; + MifareUltralightTag.writeSinglePage(pageIndex, rawData, (err, data)=> { + if (err) { + console.log("mifareUltralight writeSinglePages2 err: " + err); + expect(true).assertEqual(true); + } else { + console.log("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); + expect(data >= 0).assertTrue(); + } + }); + sleep(3000); + done(); + } else { + console.info("[NFC_test]mifareUltralight4 = null & = undefined: "); + expect(true).assertFalse(); + } }) /** @@ -175,9 +193,14 @@ export default function nfcMifareUltralightTag() { * @tc.level Level 2 */ it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () { - let getType = MifareUltralightTag.getType(); - console.info("mifareUltralight getType: " + getType); - expect(true).assertTrue(getType >= -1); + if (MifareUltralightTag != null && MifareUltralightTag != undefined) { + let getType = MifareUltralightTag.getType(); + 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*************"); @@ -185,3 +208,4 @@ export default function nfcMifareUltralightTag() { } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js b/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js index adcc9c35bc69bcf2928bcd142c43066d4e7749f1..30b9fbe9bf5fa32a380ba5aa2a03dc0b507d5890 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.NDEFTag.js @@ -94,10 +94,18 @@ let NdefFormatableTag = { "tagRfDiscId": 1, }; +let NdefTag ; + export default function nfcNDEFTagTest() { describe('nfcNDEFTagTest', function () { beforeAll(function () { console.info('[NFC_test]beforeAll called') + try { + NdefTag = tag.getNdef(NDEFTaginfo); + console.info("[NFC_test]NdefTag001 ->: "+ JSON.stringify(NdefTag)); + } catch (error) { + console.info('nfc TagTest getNdef error' + error) + } }) beforeEach(function() { console.info('[NFC_test]beforeEach called') @@ -118,29 +126,21 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0100', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - console.info("[NFC_test]NdefTag001 ->: "+ JSON.stringify(NdefTag)); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0100 error' + error) - } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - let ndefMessage ; - if (NdefTag!= undefined){ - console.info("ndefRecords is object1 " ); - try{ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; + try { ndefMessage = tag.ndef.createNdefMessage(rawData); expect(ndefMessage !=null).assertTrue(); expect(ndefMessage instanceof Object).assertTrue(); console.info("[NFC_test]ndef ndefMessage1: " + ndefMessage); - }catch(error){ + } catch (error) { console.info("[NFC_test]ndef ndefMessage1 error: " + error); } - }else{ - console.info("[NFC_test]ndef typeof1 ->: "+ typeof(NdefTag)); + } else { + console.info("[NFC_test]NdefTag1 = null & = undefined: "); + expect(true).assertFalse(); } sleep(3000); }) @@ -154,34 +154,29 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0200', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0200 error' + error) - } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - if (NdefTag!= undefined){ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; console.info("ndefRecords is object2" ); - try{ + try { let ndefMessage = tag.ndef.createNdefMessage(rawData); console.info("[NFC_test]ndefMessage result: "); if (ndefMessage != null && ndefMessage != undefined) { - console.info("[NFC_test]ndef 1111111111: " ); let ndefRecords = ndefMessage.getNdefRecords(); console.info("[NFC_test]ndef ndefRecords number: " + JSON.stringify(ndefRecords)); expect(ndefRecords).assertInstanceOf('Array') } else{ - console.info("[NFC_test]ndef 1222222222: " + error); + console.info("[NFC_test]ndef ndefMessage = null & = undefined: "); + expect(true).assertFalse(); } }catch(error){ console.info("ndef ndefMessage2 error: " + error); } - }else{ - console.info("[NFC_test]ndef typeof2 ->: "+ typeof(NdefTag) ); + } else { + console.info("[NFC_test]NdefTag2 = null & = undefined: "); + expect(true).assertFalse(); } sleep(3000); }) @@ -195,20 +190,14 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0300', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_03001 error' + error) - } - let ndefRecords = [ - {tnf: 0x01, rtdType: [0x54], id: [0x01, 0x02], payload: [0x00, 0xa4, 0x04]}, - {tnf: 0x02, rtdType: [0x55], id: [0x03, 0x04], payload: [0x00, 0xa4, 0x04]}, - ]; - let ndefMessage; - if (NdefTag != undefined){ + if (NdefTag != null && NdefTag != undefined) { + let ndefRecords = [ + {tnf: 0x01, rtdType: [0x54], id: [0x01, 0x02], payload: [0x00, 0xa4, 0x04]}, + {tnf: 0x02, rtdType: [0x55], id: [0x03, 0x04], payload: [0x00, 0xa4, 0x04]}, + ]; + let ndefMessage; console.info("ndefRecords is object3 " ); - try{ + try { ndefMessage = tag.ndef.createNdefMessage(ndefRecords); if (ndefMessage != null && ndefMessage != undefined) { console.info("[NFC_test]ndef ndefMessage1113: " + ndefMessage); @@ -216,14 +205,16 @@ export default function nfcNDEFTagTest() { expect(ndefMessage instanceof Object).assertTrue(); } else{ - console.info("[NFC_test]ndef ndefMessage111: " + error); + console.info("[NFC_test]ndef ndefMessage = null & = undefined: "); + expect(true).assertFalse(); } - - }catch(error){ + } catch (error) { console.info('SUB_Communication_NFC_nfcNDEF_js_03002 error' + error) + expect(true).assertFalse(); } - }else{ - console.info("[NFC_test]ndef typeof3 ->: "+ typeof(NdefTag) ); + } else { + console.info("[NFC_test]NdefTag3 = null & = undefined: "); + expect(true).assertFalse(); } sleep(3000); }) @@ -237,15 +228,14 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0400', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0400 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let ndefTagType = NdefTag.getNdefTagType(); + expect(NfcForumType.NFC_FORUM_TYPE_1).assertEqual(ndefTagType); + console.info("[NFC_test]ndef ndefTagType: " + ndefTagType); + } else { + console.info("[NFC_test]NdefTag4 = null & = undefined: "); + expect(true).assertFalse(); } - let ndefTagType = NdefTag.getNdefTagType(); - expect(NfcForumType.NFC_FORUM_TYPE_1).assertEqual(ndefTagType); - console.info("[NFC_test]ndef ndefTagType: " + ndefTagType); }) /** @@ -257,18 +247,18 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0500', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_05001 error' + error) - } - try{ - let getMessage = NdefTag.getNdefMessage(); - expect(ndefMessage != null).assertTrue(); - console.info('SUB_Communication_NFC_nfcNDEF_js_05004' + getMessage) - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_05001 error' + error) + if (NdefTag != null && NdefTag != undefined) { + try { + let getMessage = NdefTag.getNdefMessage(); + expect(getMessage != null).assertTrue(); + console.info('[NFC_test]ndef NdefMessage:' + getMessage) + } catch (error) { + console.info('ndef NdefMessage error' + error) + expect(true).assertFalse(); + } + } else { + console.info("[NFC_test]NdefTag5 = null & = undefined: "); + expect(true).assertFalse(); } }) @@ -281,7 +271,7 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0600', 0, async function (done) { - let NdefTag; + let NdefTag1; let NDEFTaginfo = { "uid": [0x01, 0x02, 0x03, 0x04], "technology": [1, 6], @@ -296,16 +286,21 @@ export default function nfcNDEFTagTest() { ], "tagRfDiscId": 1, }; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0600 error' + error) + try { + NdefTag1= tag.getNdef(NDEFTaginfo); + } catch (error) { + console.info('ndef getNdefTaginfo error' + error) + } + if (NdefTag1 != null && NdefTag1 != undefined) { + let data = NdefTag1.isNdefWritable(); + console.info("[NFC_test]ndef isNdefWritable data: " + data); + expect(data).assertTrue(); + done(); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag6 = null & = undefined: "); + expect(true).assertFalse(); } - let data = NdefTag.isNdefWritable(); - console.info("[NFC_test]ndef isNdefWritable data: " + data); - expect(data).assertTrue(); - done(); - sleep(3000); }) /** @@ -317,21 +312,20 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0700', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0800 error' + error) + if (NdefTag != null && NdefTag != undefined) { + await NdefTag.readNdef().then((data) => { + console.info("[NFC_test]ndef readNdef1 data: " + data); + done(); + }).catch((err)=> { + console.info("ndef readNdef1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag7 = null & = undefined: "); + expect(true).assertFalse(); } - await NdefTag.readNdef().then((data) => { - console.info("[NFC_test]ndef readNdef1 data: " + data); - done(); - }).catch((err)=> { - console.info("ndef readNdef1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); }) /** @@ -343,23 +337,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0800', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0800 error' + error) + if (NdefTag != null && NdefTag != undefined) { + NdefTag.readNdef((err, data)=> { + if (err) { + expect(true).assertEqual(true); + console.info("[NFC_test]ndef readNdef2 err: " + err); + } else { + expect(data!=true).assertTrue(); + console.info("[NFC_test]ndef readNdef2 data: " + data); + } + }); + done(); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag8 = null & = undefined: "); + expect(true).assertFalse(); } - NdefTag.readNdef((err, data)=> { - if (err) { - expect(true).assertEqual(true); - console.info("[NFC_test]ndef readNdef2 err: " + err); - } else { - expect(data!=true).assertTrue(); - console.info("[NFC_test]ndef readNdef2 data: " + data); - } - }); - done(); - sleep(3000); }) /** @@ -371,26 +364,25 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_0900', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0900 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; + let ndefMessage = tag.ndef.createNdefMessage(rawData); + await NdefTag.writeNdef(ndefMessage).then((data) => { + expect(data).assertInstanceOf('Number') + console.info("[NFC_test]ndef writeNdef1 data: " + data); + done(); + }).catch((err)=> { + console.info("[NFC_test]ndef writeNdef1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - let ndefMessage = tag.ndef.createNdefMessage(rawData); - await NdefTag.writeNdef(ndefMessage).then((data) => { - expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef writeNdef1 data: " + data); - done(); - }).catch((err)=> { - console.info("[NFC_test]ndef writeNdef1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); }) /** @@ -402,27 +394,26 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1000', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1000 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; + let ndefMessage = tag.ndef.createNdefMessage(rawData); + NdefTag.writeNdef(ndefMessage, (err, data)=> { + if (err) { + console.info("[NFC_test]ndef writeNdef2 err: " + err); + expect(true).assertEqual(true); + } else { + expect(data).assertInstanceOf('Number') + console.info("[NFC_test]ndef10 writeNdef2 data: " + data); + } + }); + done(); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - let ndefMessage = tag.ndef.createNdefMessage(rawData); - NdefTag.writeNdef(ndefMessage, (err, data)=> { - if (err) { - console.info("[NFC_test]ndef writeNdef2 err: " + err); - expect(true).assertEqual(true); - } else { - expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef writeNdef2 data: " + data); - } - }); - done(); - sleep(3000); }) /** @@ -433,17 +424,20 @@ export default function nfcNDEFTagTest() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_nfcNDEF_js_1100', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - console.info("[NFC_test]get NdefTag: " + NdefTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1100 error' + error) + it('SUB_Communication_NFC_nfcNDEF_js_1100', 0, function () { + if (NdefTag != null && NdefTag != undefined) { + try { + let canSetReadOnly = NdefTag.canSetReadOnly(); + console.info("[NFC_test]ndef canSetReadOnly: " + canSetReadOnly); + expect(canSetReadOnly).assertTrue(); + } catch (error) { + console.info('NdefTag NdefTag error' + error) + expect(true).assertTrue(); + } + } else { + console.info("[NFC_test]NdefTag11 = null & = undefined: "); + expect(true).assertFalse(); } - let canSetReadOnly = NdefTag.canSetReadOnly(); - console.info("[NFC_test]ndef canSetReadOnly: " + canSetReadOnly); - expect(canSetReadOnly).assertTrue(); }) /** @@ -455,22 +449,21 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1200', 0, async function (done) { - let NdefTag; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1200 error' + error) + if (NdefTag != null && NdefTag != undefined) { + await NdefTag.setReadOnly().then((data) => { + expect(data).assertInstanceOf('Number') + console.info("[NFC_test]ndef setReadOnly1 data: " + data); + done(); + }).catch((err)=> { + console.info("[NFC_test]ndef setReadOnly1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag12 = null & = undefined: "); + expect(true).assertFalse(); } - await NdefTag.setReadOnly().then((data) => { - expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef setReadOnly1 data: " + data); - done(); - }).catch((err)=> { - console.info("[NFC_test]ndef setReadOnly1 err: " + err); - expect(true).assertEqual(true); - done(); - }); - sleep(3000); }) /** @@ -482,23 +475,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1300', 0, async function (done) { - let NdefTag; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1300 error' + error) + if (NdefTag != null && NdefTag != undefined) { + NdefTag.setReadOnly((err, data)=> { + if (err) { + expect(true).assertEqual(true); + console.info("[NFC_test]ndef setReadOnly2 err: " + err); + } else { + expect(data).assertInstanceOf('Number') + console.info("[NFC_test]ndef setReadOnly2 data: " + data); + } + }); + done(); + sleep(3000); + } else { + console.info("[NFC_test]NdefTag13 = null & = undefined: "); + expect(true).assertFalse(); } - NdefTag.setReadOnly((err, data)=> { - if (err) { - expect(true).assertEqual(true); - console.info("[NFC_test]ndef setReadOnly2 err: " + err); - } else { - expect(data).assertInstanceOf('Number') - console.info("[NFC_test]ndef setReadOnly2 data: " + data); - } - }); - done(); - sleep(3000); }) /** @@ -509,16 +501,15 @@ export default function nfcNDEFTagTest() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_nfcNDEF_js_1400', 0, function () { - let NdefTag; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1400 error' + error) + it('SUB_Communication_NFC_nfcNDEF_js_1400', 0, function () { + if (NdefTag != null && NdefTag != undefined) { + let ndefTypeString = NdefTag.getNdefTagTypeString(NfcForumType.NFC_FORUM_TYPE_1); + console.info("[NFC_test]ndef ndefTypeString: " + JSON.stringify(ndefTypeString)); + expect(ndefTypeString.length >= 0).assertTrue(); + } else { + console.info("[NFC_test]NdefTag14 = null & = undefined: "); + expect(true).assertFalse(); } - let ndefTypeString = NdefTag.getNdefTagTypeString(NfcForumType.NFC_FORUM_TYPE_1); - console.info("[NFC_test]ndef ndefTypeString: " + JSON.stringify(ndefTypeString)); - expect(ndefTypeString.length >= 0).assertTrue(); }) @@ -531,21 +522,20 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1500', 0, async function () { - let NdefTag; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1600 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; + let ndefmessage = tag.ndef.createNdefMessage(rawData); + let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); + await NdefFormatable.format(ndefmessage).then(() => { + console.info("[NFC_test]ndefFormatable format1 "); + }).catch((err)=> { + console.info("[NFC_test]ndefFormatable format1 err: " + err); + expect(true).assertEqual(true); + }); + } else { + console.info("[NFC_test]NdefTag15 = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - let ndefmessage = tag.ndef.createNdefMessage(rawData); - let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); - await NdefFormatable.format(ndefmessage).then(() => { - console.info("[NFC_test]ndefFormatable format1 "); - }).catch((err)=> { - console.info("[NFC_test]ndefFormatable format1 err: " + err); - expect(true).assertEqual(true); - }); }) /** @@ -557,24 +547,23 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1600', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1700 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; + let ndefmessage = tag.ndef.createNdefMessage(rawData); + let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); + NdefFormatable.format(ndefmessage, (err, data)=> { + if (err) { + console.log("ndefFormatable format err: " + err); + expect(true).assertTrue(); + } else { + console.info("[NFC_test]ndefFormatable formatReadOnly2" ); + } + }); + done(); + } else { + console.info("[NFC_test]NdefTag16 = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - let ndefmessage = tag.ndef.createNdefMessage(rawData); - let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); - NdefFormatable.format(ndefmessage, (err, data)=> { - if (err) { - console.log("ndefFormatable format err: " + err); - expect(true).assertTrue(); - } else { - console.info("[NFC_test]ndefFormatable formatReadOnly2" ); - } - }); - done(); }) /** @@ -586,23 +575,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1700', 0, async function () { - let NdefTag; - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1800 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; + let ndefmessage = tag.ndef.createNdefMessage(rawData); + let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); + await NdefFormatable.formatReadOnly(ndefmessage).then(() => { + console.info("[NFC_test]ndefFormatable formatReadOnly1 " + data); + }).catch((err)=> { + console.info("[NFC_test]ndefFormatable formatReadOnly1 err: " + err); + expect(true).assertTrue(); + }); + } else { + console.info("[NFC_test]NdefTag17 = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - let ndefmessage = tag.ndef.createNdefMessage(rawData); - let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); - await NdefFormatable.formatReadOnly(ndefmessage).then(() => { - console.info("[NFC_test]ndefFormatable formatReadOnly1 " + data); - }).catch((err)=> { - console.info("[NFC_test]ndefFormatable formatReadOnly1 err: " + err); - expect(true).assertTrue(); - }); }) /** @@ -614,26 +602,25 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1800', 0, async function (done) { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_1900 error' + error) + if (NdefTag != null && NdefTag != undefined) { + let rawData = [ + 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 + ]; + let ndefmessage = tag.ndef.createNdefMessage(rawData); + let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); + NdefFormatable.formatReadOnly(ndefmessage, (err, data)=> { + if (err) { + console.log("ndefFormatable format err: " + err); + expect(true).assertTrue(); + } else { + console.info("[NFC_test]ndefFormatable formatReadOnly2" ); + } + }); + done(); + } else { + console.info("[NFC_test]NdefTag18 = null & = undefined: "); + expect(true).assertFalse(); } - let rawData = [ - 0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43 - ]; - let ndefmessage = tag.ndef.createNdefMessage(rawData); - let NdefFormatable = tag.getNdefFormatable(NdefFormatableTag); - NdefFormatable.formatReadOnly(ndefmessage, (err, data)=> { - if (err) { - console.log("ndefFormatable format err: " + err); - expect(true).assertTrue(); - } else { - console.info("[NFC_test]ndefFormatable formatReadOnly2" ); - } - }); - done(); }) @@ -646,27 +633,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_1900', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_0300 error' + error) - } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - if (NdefTag!= undefined){ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; console.info("makeUriRecord is object3" ); - try{ + try { let ndefMessage = tag.ndef.createNdefMessage(rawData); console.info("[NFC_test]ndefMessage result: " + JSON.stringify(ndefMessage)); let makeRecords = tag.ndef.makeUriRecord("D4010354787473"); console.info("[NFC_test]makeUriRecord result: " + JSON.stringify(makeRecords)); expect(JSON.stringify(makeRecords)!=null).assertTrue(); - - }catch(error){ + } catch (error) { console.info("ndef ndefMessage error: " + error); + expect(true).assertFalse(); } - }else{ - console.info("[NFC_test]ndef typeof2 ->: "+ typeof(NdefTag) ); + } else { + console.info("[NFC_test]NdefTag19 = null & = undefined: "); + expect(true).assertFalse(); } }) @@ -679,27 +661,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_2000', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_2000 error' + error) - } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - if (NdefTag!= undefined){ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; console.info("makeTextRecord is object4" ); - try{ + try { let ndefMessage = tag.ndef.createNdefMessage(rawData); console.info("[NFC_test]ndefMessage result1: " + JSON.stringify(ndefMessage)); let makeTRecords = tag.ndef.makeTextRecord("test112HW","test"); console.info("[NFC_test]makeTextRecord result1: " + JSON.stringify(makeTRecords)); expect(JSON.stringify(makeTRecords)!=null).assertTrue(); - - }catch(error){ + } catch (error) { console.info("ndef ndefMessage1 error: " + error); + expect(true).assertFalse(); } - }else{ - console.info("[NFC_test]ndef typeof1 ->: "+ typeof(NdefTag) ); + } else { + console.info("[NFC_test]NdefTag20 = null & = undefined: "); + expect(true).assertFalse(); } }) @@ -736,6 +713,7 @@ export default function nfcNDEFTagTest() { } }) + /** * @tc.number SUB_Communication_NFC_nfcNDEF_js_2200 * @tc.name Test makeExternalRecord NDEF @@ -745,26 +723,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_2200', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_2200 error' + error) - } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - if (NdefTag!= undefined){ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; console.info("makeExternalRecord is object6" ); - try{ + try { let ndefMessage = tag.ndef.createNdefMessage(rawData); console.info("[NFC_test]ndefMessage result3: " + JSON.stringify(ndefMessage)); let makeERecords = tag.ndef.makeExternalRecord("NFC","NFCtest",[0x01, 0x02]); console.info("[NFC_test]makeExternalRecord result13: " + JSON.stringify(makeERecords)); expect(makeERecords instanceof Object).assertTrue(); - }catch(error){ + } catch (error) { console.info("ndef ndefMessage3 error: " + error); + expect(true).assertFalse(); } - }else{ - console.info("[NFC_test]ndef typeof3 ->: "+ typeof(NdefTag) ); + } else { + console.info("[NFC_test]NdefTag22 = null & = undefined: "); + expect(true).assertFalse(); } }) @@ -777,26 +751,22 @@ export default function nfcNDEFTagTest() { * @tc.level Level 2 */ it('SUB_Communication_NFC_nfcNDEF_js_2300', 0, function () { - let NdefTag - try{ - NdefTag= tag.getNdef(NDEFTaginfo); - }catch(error){ - console.info('SUB_Communication_NFC_nfcNDEF_js_2300 error' + error) - } - let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; - if (NdefTag!= undefined){ + if (NdefTag != null && NdefTag != undefined) { + let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; console.info("messageToBytes is object7" ); - try{ + try { let ndefMessage = tag.ndef.createNdefMessage(rawData); console.info("[NFC_test]ndefMessage result4: " + JSON.stringify(ndefMessage)); let makeERecords = tag.ndef.messageToBytes(ndefMessage); console.info("[NFC_test]messageToBytes result4: " + JSON.stringify(makeERecords)); expect(makeERecords).assertInstanceOf('Array') - }catch(error){ + } catch (error) { console.info("ndef ndefMessage4 error: " + error); + expect(true).assertFalse(); } }else{ - console.info("[NFC_test]ndef typeof4 ->: "+ typeof(NdefTag) ); + console.info("[NFC_test]NdefTag23 = null & = undefined: "); + expect(true).assertFalse(); } }) @@ -804,3 +774,4 @@ export default function nfcNDEFTagTest() { }) } + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js index a20618adeb25de12480c3f81f4b0d7413627f071..c88a4ecc6d44669fcf10eae6e4717c40d58b50c5 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js @@ -122,14 +122,19 @@ export default function nfcTagABFVTest() { */ it('SUB_Communication_NFC_nfctage_js_0100', 0, function () { let NfcATag ; - try{ + try { NfcATag = tag.getNfcATag(aTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0200', 0, function () { let NfcBTag ; - try{ + try { NfcBTag = tag.getNfcBTag(bTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0300', 0, function () { let NfcFTag ; - try{ + try { NfcFTag = tag.getNfcFTag(fTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0400', 0, function () { let NfcVTag ; - try{ + try { NfcVTag = tag.getNfcVTag(vTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0500', 0, function () { let NfcATag ; - try{ + try { NfcATag = tag.getNfcATag(aTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0600', 0, function () { let NfcATag ; - try{ + try { NfcATag = tag.getNfcATag(aTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0700', 0, function () { let NfcBTag ; - try{ + try { NfcBTag = tag.getNfcBTag(bTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0800', 0, function () { let NfcBTag ; - try{ + try { NfcBTag = tag.getNfcBTag(bTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_0900', 0, function () { let NfcFTag ; - try{ + try { NfcFTag = tag.getNfcFTag(fTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_1000', 0, function () { let NfcFTag ; - try{ + try { NfcFTag = tag.getNfcFTag(fTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_1100', 0, function () { let NfcVTag ; - try{ + try { NfcVTag = tag.getNfcVTag(vTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_1200', 0, function () { let NfcVTag ; - try{ + try { NfcVTag = tag.getNfcVTag(vTag); }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() { */ it('SUB_Communication_NFC_nfctage_js_1300', 0, function () { let TagInfo ; - try{ + try { TagInfo = tag.getTagInfo(Want); - console.info('SUB_Communication_NFC_nfctage_js1111111' + TagInfo) + console.info('Nfcget tagABFV gettaginfo is: ' + TagInfo) expect(TagInfo instanceof Object).assertTrue(); }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_1300 error' + error) + console.info('Nfcget taginfo error' + error) expect(true).assertTrue(); } 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*************"); }) } +