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 3a99beaa0218600721f782cf28f3d2e823ff9254..d9c0529922292def517963d51b9e2cf16f53659e 100644 --- a/communication/nfc_Controller/src/main/js/test/List.test.js +++ b/communication/nfc_Controller/src/main/js/test/List.test.js @@ -13,18 +13,22 @@ * limitations under the License. */ +import nfcATagSessionTest from './nfc.ATagSession.js' import nfcControllerTest from './nfc.Controller.js' import nfcIsoDepTagTest from './nfc.IsoDepTag.js' import nfcMifareClassicTag from './nfc.MifareClassicTag.js' -import nfcTagABFVTest from './nfc.tagABFV.js' +import nfcMifareUltralightTag from './nfc.MifareUltralightTag.js' +import nfcTagABFVTest from './nfc.TagABFV.js' import parameter from '@ohos.systemparameter'; let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false"); export default function testsuite() { if (info != "false") { + nfcATagSessionTest(); nfcControllerTest(); nfcIsoDepTagTest(); nfcMifareClassicTag(); + nfcMifareUltralightTag(); 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 new file mode 100644 index 0000000000000000000000000000000000000000..f58361ee59c4f5292292b1f5ffcfb9e2392bba85 --- /dev/null +++ b/communication/nfc_Controller/src/main/js/test/nfc.ATagSession.js @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import tag from '@ohos.nfc.tag'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +function sleep(delay) { // delay x ms + let start = (new Date()).getTime(); + while ((new Date()).getTime() - start < delay) { + continue; + } +} + +let aTag = { + "uid": [0x01, 0x02, 0x03, 0x04], + "technology": [1], + "extrasData": [ + { + "Sak": 0x08, "Atqa": "B000", + }, + ], + "tagRfDiscId": 1, +}; + +export default function nfcATagSessionTest() { + describe('nfcATagSessionTest', function () { + beforeAll(function () { + console.info('[NFC_test]beforeAll called') + }) + beforeEach(function() { + console.info('[NFC_test]beforeEach called') + }) + afterEach(function () { + console.info('[NFC_test]afterEach called') + }) + afterAll(function () { + console.info('[NFC_test]afterAll called') + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0100 + * @tc.name testconnectTag + * @tc.desc Test connectTag api. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_nfcAtage_js_0001', 0, function () { + let NfcConnected; + try{ + NfcConnected = tag.getNfcATag(aTag).connectTag(); + console.info("NfcConnected:" +NfcConnected); + expect(NfcConnected).assertFalse(); + }catch(error){ + console.info('NfcConnected error' + error) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0002 + * @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_0002', 0, function () { + try{ + tag.getNfcATag(aTag).reset(); + expect(true).assertTrue(); + console.info('reset1 pass' ) + }catch(error){ + console.info('reset1 error' + error) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0003 + * @tc.name testisTagConnected + * @tc.desc Test isTagConnected api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_nfcAtage_js_0003', 0, function () { + let isNfcConnected; + try{ + isNfcConnected = tag.getNfcATag(aTag).isTagConnected(); + console.info("isNfcConnected:" +isNfcConnected); + expect(isNfcConnected).assertFalse(); + }catch(error){ + console.info('isNfcConnected error' + error) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0004 + * @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_0004', 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) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0005 + * @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_0005', 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) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0006 + * @tc.name testgetSendDataTimeout + * @tc.desc Test getSendDataTimeout api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_nfcAtage_js_0006', 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) + } + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0007 + * @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_0007', 0, async function (done) { + let sendDatas = [0x01, 0x02, 0x03, 0x04]; + await tag.getNfcATag(aTag).sendData(sendDatas).then((data) => { + console.log("nfcAtage sendData1 data: " + data + "json1:" + JSON.stringify(data)); + expect(true).assertTrue(data >= 0); + done(); + }).catch((err)=> { + console.log("nfcAtage sendData1 err: " + err); + }); + sleep(3500); + }) + + /** + * @tc.number SUB_Communication_NFC_nfcAtage_js_0008 + * @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_0008', 0, async function (done) { + let sendDatas = [0x01, 0x02, 0x03, 0x04]; + tag.getNfcATag(aTag).sendData(sendDatas, (err, data)=> { + if (err) { + console.log("nfcAtage sendData2 data err: " + err); + } else { + sleep(2500); + console.log("nfcAtage sendData2 data: " + data + "json2:" + JSON.stringify(data)); + expect(true).assertTrue(data >= 0); + } + }); + sleep(500); + 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 4820a80afcd63303aa63457a4df283a21f915dc0..dba8023bb0f2bd5a040056923b25a4cca11be1a5 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.Controller.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.Controller.js @@ -60,7 +60,7 @@ export default function nfcControllerTest() { let openNfcswitch = controller.openNfc(); sleep(5000); console.info('[nfc_js] open Nfc switch ->' + openNfcswitch); - expect(openNfcswitch===undefined || openNfcswitch===true).assertTrue(); + expect(openNfcswitch).assertTrue(); }catch(error) { console.info('[nfc_js] Failed to enable the switch ->' + error); expect(error != null).assertTrue(); @@ -139,7 +139,7 @@ export default function nfcControllerTest() { try { let closeNfc = controller.closeNfc(); console.info('[nfc_js] clocse Nfc switch ->' + closeNfc); - expect(closeNfc===undefined || closeNfc===true).assertTrue(); + expect(closeNfc).assertTrue(); }catch(error) { console.info('[nfc_js] Failed to disable the switch ->' + error ); expect(error!=null).assertTrue(); 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 14bdee9946772142d47228052f6b2d3a1a8c55c8..d889a1df708f2477d8b1dd30ad4d71d4f5059f2e 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.IsoDepTag.js @@ -79,7 +79,7 @@ export default function nfcIsoDepTagTest() { }) /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 + * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0100 * @tc.name Test getHistoricalBytes IsoDep * @tc.desc Obtains the history bytes of a label. * @tc.size since 9 @@ -93,7 +93,7 @@ export default function nfcIsoDepTagTest() { }) /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 + * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0200 * @tc.name Test getHiLayerResponse IsoDep * @tc.desc HiLayer response byte for obtaining the tag. * @tc.size since 9 @@ -107,7 +107,7 @@ export default function nfcIsoDepTagTest() { }) /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 + * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0300 * @tc.name Test isExtendedApduSupported IsoDep * @tc.desc Check whether extended APDUs are supported.Promise * @tc.size since 9 @@ -127,7 +127,7 @@ export default function nfcIsoDepTagTest() { }) /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 + * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0400 * @tc.name Test isExtendedApduSupported IsoDep * @tc.desc Check whether extended APDUs are supported.callback * @tc.size since 9 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 495a9237cadd9f47109f1aca23c0955478812d28..9f8d8363e0deacae9c8fa9330e0852dba40546d4 100644 --- a/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareClassicTag.js @@ -24,6 +24,19 @@ function sleep(delay) { // delay x ms } } +let MifareClassicType = { + TYPE_UNKNOWN : -1, + TYPE_CLASSIC : 0, + TYPE_PLUS : 1, + TYPE_PRO : 2, +} + +let MifareTagSize = { + MC_SIZE_MINI : 320, + MC_SIZE_1K : 1024, + MC_SIZE_2K : 2048, + MC_SIZE_4K : 4096, +} let mifareclassicTaginfo = { "uid": [0x01, 0x02, 0x03, 0x04], @@ -39,14 +52,14 @@ let mifareclassicTaginfo = { "tagRfDiscId": 1, }; let mifareClassic = null; -export default function nfcControllerTest1() { - describe('nfcControllerTest1', function () { +export default function nfcMifareClassicTag() { + describe('nfcMifareClassicTag', function () { beforeAll(function () { console.info('[NFC_test]beforeAll called') try{ mifareClassic = tag.getMifareClassic(mifareclassicTaginfo); }catch(error){ - console.log('beforeAll mifareClassic error' + error) + console.info('beforeAll mifareClassic error' + error) } }) beforeEach(function() { @@ -62,7 +75,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0001 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0100 * @tc.name testauthenticateSector * @tc.desc Test authenticateSector api by callback. * @tc.size MEDIUM @@ -70,15 +83,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0001', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0100', 0, async function (done) { let sectorIndex = 1; let key = [0x04, 0x05]; await mifareClassic.authenticateSector(sectorIndex, key, true).then((data) => { - console.log("mifareClassic authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); + console.info("mifareClassic authenticateSector1 data: " + data + "json1:" + JSON.stringify(data)); expect(data).assertTrue(); done(); }).catch((err)=> { - console.log("mifareClassic authenticateSector1 err: " + err); + console.info("mifareClassic authenticateSector1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -87,7 +100,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0002 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0200 * @tc.name testauthenticateSector * @tc.desc Test authenticateSector api. * @tc.size MEDIUM @@ -95,15 +108,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0002', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0200', 0, async function (done) { let sectorIndex = 1; let key = [0x04, 0x05]; mifareClassic.authenticateSector(sectorIndex, key, true, (err, data)=> { if (err) { - console.log("mifareClassic authenticateSector2 err: " + err); + console.info("mifareClassic authenticateSector2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); + console.info("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data)); expect(data).assertTrue(); } }); @@ -113,7 +126,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0003 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0300 * @tc.name testreadSingleBlock * @tc.desc Test readSingleBlock api. * @tc.size MEDIUM @@ -121,20 +134,20 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0003', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0300', 0, async function (done) { let mifareClassic; try{ mifareClassic = tag.getMifareClassic(mifareclassicTaginfo); }catch(error){ - console.log('beforeAll mifareClassic error' + error) + console.info('beforeAll mifareClassic error' + error) } let blockIndex = 1; await mifareClassic.readSingleBlock(blockIndex).then((data) => { - console.log("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); + console.info("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data)); expect(data).assertInstanceOf('Array') done(); }).catch((err)=> { - console.log("mifareClassic readSingleBlock1 err: " + err); + console.info("mifareClassic readSingleBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -143,7 +156,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0004 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0400 * @tc.name testreadSingleBlock * @tc.desc Test readSingleBlock api. * @tc.size MEDIUM @@ -151,14 +164,14 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0004', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0400', 0, async function (done) { let blockIndex = 1; mifareClassic.readSingleBlock(blockIndex, (err, data)=> { if (err) { - console.log("mifareClassic readSingleBlock2 err: " + err); + console.info("mifareClassic readSingleBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); + console.info("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data)); expect(data).assertInstanceOf('Array') } }); @@ -167,7 +180,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0005 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0500 * @tc.name testwriteSingleBlock * @tc.desc Test writeSingleBlock api. * @tc.size MEDIUM @@ -175,15 +188,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0005', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0500', 0, async function (done) { let blockIndex = 1; let rawData = [0x0a, 0x14]; await mifareClassic.writeSingleBlock(blockIndex, rawData).then((data) => { - console.log("mifareClassic writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); + console.info("mifareClassic writeSingleBlock1 data: " + data + "json5:" + JSON.stringify(data)); expect(data).assertTrue(); done(); }).catch((err)=> { - console.log("mifareClassic writeSingleBlock1 err: " + err); + console.info("mifareClassic writeSingleBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -192,7 +205,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0006 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0600 * @tc.name testwriteSingleBlock * @tc.desc Test writeSingleBlock api. * @tc.size MEDIUM @@ -200,15 +213,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0006', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0600', 0, async function (done) { let blockIndex = 1; let rawData = [0x0a, 0x14]; mifareClassic.writeSingleBlock(blockIndex, rawData, (err, data)=> { if (err) { - console.log("mifareClassic writeSingleBlock2 err: " + err); + console.info("mifareClassic writeSingleBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); + console.info("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data)); expect(data).assertTrue(); } }); @@ -218,7 +231,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0007 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0700 * @tc.name testincrementBlock * @tc.desc Test incrementBlock api. * @tc.size MEDIUM @@ -226,15 +239,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0007', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0700', 0, async function (done) { let blockIndex = 1; let value = 0x20; await mifareClassic.incrementBlock(blockIndex, value).then((data) => { - console.log("mifareClassic incrementBlock1 data: " + data + "json7:" + JSON.stringify(data)); + console.info("mifareClassic incrementBlock1 data: " + data + "json7:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.log("mifareClassic incrementBlock1 err: " + err); + console.info("mifareClassic incrementBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -243,7 +256,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0008 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0800 * @tc.name testincrementBlock * @tc.desc Test incrementBlock api. * @tc.size MEDIUM @@ -251,15 +264,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0008', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0800', 0, async function (done) { let blockIndex = 1; let value = 0x20; mifareClassic.incrementBlock(blockIndex, value, (err, data)=> { if (err) { - console.log("mifareClassic incrementBlock2 err: " + err); + console.info("mifareClassic incrementBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); + console.info("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') } }); @@ -269,7 +282,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0009 + * @tc.number SUB_Communication_NFC_mifareClassic_js_0900 * @tc.name testdecrementBlock * @tc.desc Test decrementBlock api. * @tc.size MEDIUM @@ -277,15 +290,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0009', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_0900', 0, async function (done) { let blockIndex = 1; let value = 0x20; await mifareClassic.decrementBlock(blockIndex, value).then((data) => { - console.log("mifareClassic decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); + console.info("mifareClassic decrementBlock1 data: " + data + "json9:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.log("mifareClassic decrementBlock1 err: " + err); + console.info("mifareClassic decrementBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -294,7 +307,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0010 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1000 * @tc.name testdecrementBlock * @tc.desc Test decrementBlock api. * @tc.size MEDIUM @@ -302,15 +315,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0010', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_1000', 0, async function (done) { let blockIndex = 1; let value = 0x20; mifareClassic.decrementBlock(blockIndex, value, (err, data)=> { if (err) { - console.log("mifareClassic decrementBlock2 err: " + err); + console.info("mifareClassic decrementBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); + console.info("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') } }); @@ -320,7 +333,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0011 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1100 * @tc.name testtransferToBlock * @tc.desc Test transferToBlock api. * @tc.size MEDIUM @@ -328,14 +341,14 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0011', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_1100', 0, async function (done) { let blockIndex = 1; await mifareClassic.transferToBlock(blockIndex).then((data) => { - console.log("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data)); + console.info("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.log("mifareClassic transferToBlock1 err: " + err); + console.info("mifareClassic transferToBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -344,7 +357,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0012 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1200 * @tc.name testtransferToBlock * @tc.desc Test transferToBlock api. * @tc.size MEDIUM @@ -352,14 +365,14 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0012', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_1200', 0, async function (done) { let blockIndex = 1; mifareClassic.transferToBlock(blockIndex, (err, data)=> { if (err) { - console.log("mifareClassic transferToBlock2 err: " + err); + console.info("mifareClassic transferToBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); + console.info("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') } }); @@ -369,7 +382,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0013 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1300 * @tc.name testrestoreFromBlock * @tc.desc Test restoreFromBlock api. * @tc.size MEDIUM @@ -377,14 +390,14 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0013', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_1300', 0, async function (done) { let blockIndex = 1; await mifareClassic.restoreFromBlock(blockIndex).then((data) => { - console.log("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); + console.info("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') done(); }).catch((err)=> { - console.log("mifareClassic restoreFromBlock1 err: " + err); + console.info("mifareClassic restoreFromBlock1 err: " + err); expect(true).assertEqual(true); done(); }); @@ -393,7 +406,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0014 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1400 * @tc.name testrestoreFromBlock * @tc.desc Test restoreFromBlock api. * @tc.size MEDIUM @@ -401,14 +414,14 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0014', 0, async function (done) { + it('SUB_Communication_NFC_mifareClassic_js_1400', 0, async function (done) { let blockIndex = 1; mifareClassic.restoreFromBlock(blockIndex, (err, data)=> { if (err) { - console.log("mifareClassic restoreFromBlock2 err: " + err); + console.info("mifareClassic restoreFromBlock2 err: " + err); expect(true).assertEqual(true); } else { - console.log("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); + console.info("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data)); expect(data).assertInstanceOf('Number') } }); @@ -418,7 +431,7 @@ export default function nfcControllerTest1() { /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0015 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1500 * @tc.name testgetSectorCount * @tc.desc Test getSectorCount api. * @tc.size MEDIUM @@ -426,15 +439,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0015', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_1500', 0, function () { let sectorCount = mifareClassic.getSectorCount(); - console.log("mifareClassic sectorCount: " + sectorCount); + console.info("mifareClassic sectorCount: " + sectorCount); expect(sectorCount).assertInstanceOf('Number') }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0016 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1600 * @tc.name testgetBlockCountInSector * @tc.desc Test getBlockCountInSector api. * @tc.size MEDIUM @@ -442,15 +455,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0016', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_1600', 0, function () { let blockCountInSector = mifareClassic.getBlockCountInSector(); - console.log("mifareClassic blockCountInSector: " + blockCountInSector); + console.info("mifareClassic blockCountInSector: " + blockCountInSector); expect(blockCountInSector).assertInstanceOf('Number') }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0017 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1700 * @tc.name testgetType * @tc.desc Test getType api. * @tc.size MEDIUM @@ -458,15 +471,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0017', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_1700', 0, function () { let getType = mifareClassic.getType(); - console.log("mifareClassic getType: " + getType); + console.info("mifareClassic getType: " + getType); expect(true).assertTrue(getType >= -1); }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0018 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1800 * @tc.name testgetTagSize * @tc.desc Test getTagSize api. * @tc.size MEDIUM @@ -474,15 +487,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0018', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_1800', 0, function () { let tagSize = mifareClassic.getTagSize(); - console.log("mifareClassic tagSize: " + tagSize); + console.info("mifareClassic tagSize: " + tagSize); expect(tagSize).assertInstanceOf('Number') }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0019 + * @tc.number SUB_Communication_NFC_mifareClassic_js_1900 * @tc.name testisEmulatedTag * @tc.desc Test isEmulatedTag api. * @tc.size MEDIUM @@ -490,15 +503,15 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0019', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_1900', 0, function () { let isEmulatedTag = mifareClassic.isEmulatedTag(); - console.log("mifareClassic isEmulatedTag: " + isEmulatedTag); + console.info("mifareClassic isEmulatedTag: " + isEmulatedTag); expect(false).assertEqual(isEmulatedTag); }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0020 + * @tc.number SUB_Communication_NFC_mifareClassic_js_2000 * @tc.name testgetBlockIndex * @tc.desc Test getBlockIndex api. * @tc.size MEDIUM @@ -506,16 +519,16 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0020', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_2000', 0, function () { let sectorIndex = 1; let blockIndex = mifareClassic.getBlockIndex(sectorIndex); - console.log("mifareClassic blockIndex: " + blockIndex); + console.info("mifareClassic blockIndex: " + blockIndex); expect(true).assertTrue(blockIndex >= 0); }) /** - * @tc.number SUB_Communication_NFC_mifareClassic_js_0021 + * @tc.number SUB_Communication_NFC_mifareClassic_js_2100 * @tc.name testgetSectorIndex * @tc.desc Test getSectorIndex api. * @tc.size MEDIUM @@ -523,10 +536,10 @@ export default function nfcControllerTest1() { * @tc.type Function * @tc.level Level 2 */ - it('SUB_Communication_NFC_mifareClassic_js_0021', 0, function () { + it('SUB_Communication_NFC_mifareClassic_js_2100', 0, function () { let blockIndex = 1; let sectorIndex = mifareClassic.getSectorIndex(blockIndex); - console.log("mifareClassic sectorIndex: " + sectorIndex); + console.info("mifareClassic sectorIndex: " + sectorIndex); expect(true).assertTrue(sectorIndex >= 0); }) diff --git a/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js new file mode 100644 index 0000000000000000000000000000000000000000..6c77725d2e41fde5862c03d3d8902e775fa8558f --- /dev/null +++ b/communication/nfc_Controller/src/main/js/test/nfc.MifareUltralightTag.js @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import tag from '@ohos.nfc.tag'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +function sleep(delay) { // delay x ms + let start = (new Date()).getTime(); + while ((new Date()).getTime() - start < delay) { + continue; + } +} + +let mifareUltralightTaginfo = { + "uid": [0x01, 0x02, 0x03, 0x04], + "technology": [1, 9], + "extrasData": [ + { + "Sak": 0x08, "Atqa": "B000", + }, + { + "MifareUltralightC": "ture", + }, + ], + "tagRfDiscId": 1, +}; + +export default function nfcMifareUltralightTag() { + describe('nfcMifareUltralightTag', function () { + beforeAll(function () { + console.info('[NFC_test]beforeAll called') + }) + beforeEach(function() { + console.info('[NFC_test]beforeEach called') + }) + afterEach(function () { + console.info('[NFC_test]afterEach called') + }) + afterAll(function () { + console.info('[NFC_test]afterAll called') + }) + + /** + * @tc.number SUB_Communication_NFC_mifareUltralight_0100 + * @tc.name testreadMultiplePages + * @tc.desc Test readMultiplePages api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareUltralight_0100', 0, async function (done) { + let mifareUltralight; + try{ + mifareUltralight = tag.getMifareUltralight(mifareUltralightTaginfo); + console.info(' mifareUltralight is' + mifareUltralight) + }catch(error){ + console.info(' mifareUltralight error' + error) + } + let pageIndex = 1; + await mifareUltralight.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); + }) + + /** + * @tc.number SUB_Communication_NFC_mifareUltralight_0200 + * @tc.name testreadMultiplePages + * @tc.desc Test readMultiplePages api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareUltralight_0200', 0, async function (done) { + let mifareUltralight; + try{ + mifareUltralight = tag.getMifareUltralight(mifareUltralightTaginfo); + }catch(error){ + console.info(' mifareUltralight error' + error) + } + let pageIndex = 1; + mifareUltralight.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(); + }) + + /** + * @tc.number SUB_Communication_NFC_mifareUltralight_0300 + * @tc.name testwriteSinglePages + * @tc.desc Test writeSinglePages api by promise. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareUltralight_0300', 0, async function (done) { + let mifareUltralight; + try{ + mifareUltralight = tag.getMifareUltralight(mifareUltralightTaginfo); + }catch(error){ + console.info(' mifareUltralight error' + error) + } + let pageIndex = 1; + let datatype = [0x01, 0x02]; + await mifareUltralight.writeSinglePage(pageIndex, datatype).then((data) => { + console.info("mifareUltralight writeSinglePages1 data: " + data + "json1:" + JSON.stringify(data)); + expect(true).assertTrue(data >= 0); + done(); + }).catch((err)=> { + console.info("mifareUltralight writeSinglePages1 err: " + err); + expect(true).assertEqual(true); + done(); + }); + sleep(3000); + }) + + /** + * @tc.number SUB_Communication_NFC_mifareUltralight_0400 + * @tc.name testwriteSinglePages + * @tc.desc Test writeSinglePages api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareUltralight_0400', 0, async function (done) { + let mifareUltralight; + try{ + mifareUltralight = tag.getMifareUltralight(mifareUltralightTaginfo); + }catch(error){ + console.info(' mifareUltralight error' + error) + } + let pageIndex = 1; + let datatype = [0x01, 0x02]; + mifareUltralight.writeSinglePage(pageIndex, datatype, (err, data)=> { + if (err) { + console.info("mifareUltralight writeSinglePages2 err: " + err); + expect(true).assertEqual(true); + } else { + console.info("mifareUltralight writeSinglePages2 data: " + data + "json2:" + JSON.stringify(data)); + expect(true).assertTrue(data >= 0); + } + }); + sleep(3000); + done(); + }) + + /** + * @tc.number SUB_Communication_NFC_mifareUltralight_0500 + * @tc.name testgetType + * @tc.desc Gets the type of Mifare Ultralight label + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () { + let mifareUltralight; + try{ + mifareUltralight = tag.getMifareUltralight(mifareUltralightTaginfo); + }catch(error){ + console.info(' mifareUltralight error' + error) + } + let getType = mifareUltralight.getType(); + console.info("mifareUltralight getType: " + getType); + expect(true).assertTrue(getType >= -1); + }) + + console.info("*************[nfc_test] start nfc js unit test end*************"); + }) + +} + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js new file mode 100644 index 0000000000000000000000000000000000000000..9f8d8363e0deacae9c8fa9330e0852dba40546d4 --- /dev/null +++ b/communication/nfc_Controller/src/main/js/test/nfc.TagABFV.js @@ -0,0 +1,549 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import tag from '@ohos.nfc.tag'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +function sleep(delay) { // delay x ms + let start = (new Date()).getTime(); + while ((new Date()).getTime() - start < delay) { + continue; + } +} + +let MifareClassicType = { + TYPE_UNKNOWN : -1, + TYPE_CLASSIC : 0, + TYPE_PLUS : 1, + TYPE_PRO : 2, +} + +let MifareTagSize = { + MC_SIZE_MINI : 320, + MC_SIZE_1K : 1024, + MC_SIZE_2K : 2048, + MC_SIZE_4K : 4096, +} + +let mifareclassicTaginfo = { + "uid": [0x01, 0x02, 0x03, 0x04], + "technology": [1, 8], + "extrasData": [ + { + "Sak": 0x08, "Atqa": "B000", + }, + { + + }, + ], + "tagRfDiscId": 1, +}; +let mifareClassic = null; +export default function nfcMifareClassicTag() { + describe('nfcMifareClassicTag', function () { + beforeAll(function () { + console.info('[NFC_test]beforeAll called') + try{ + mifareClassic = tag.getMifareClassic(mifareclassicTaginfo); + }catch(error){ + console.info('beforeAll mifareClassic error' + error) + } + }) + beforeEach(function() { + console.info('[NFC_test]beforeEach called') + }) + afterEach(function () { + console.info('[NFC_test]afterEach called') + }) + afterAll(function () { + console.info('[NFC_test]afterAll called') + }) + + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0100 + * @tc.name testauthenticateSector + * @tc.desc Test authenticateSector api by callback. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0100', 0, async function (done) { + let sectorIndex = 1; + let key = [0x04, 0x05]; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0200 + * @tc.name testauthenticateSector + * @tc.desc Test authenticateSector api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0200', 0, async function (done) { + let sectorIndex = 1; + let key = [0x04, 0x05]; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0300 + * @tc.name testreadSingleBlock + * @tc.desc Test readSingleBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0300', 0, async function (done) { + let mifareClassic; + try{ + mifareClassic = tag.getMifareClassic(mifareclassicTaginfo); + }catch(error){ + console.info('beforeAll mifareClassic error' + error) + } + let blockIndex = 1; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0400 + * @tc.name testreadSingleBlock + * @tc.desc Test readSingleBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0400', 0, async function (done) { + let blockIndex = 1; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0500 + * @tc.name testwriteSingleBlock + * @tc.desc Test writeSingleBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0500', 0, async function (done) { + let blockIndex = 1; + let rawData = [0x0a, 0x14]; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0600 + * @tc.name testwriteSingleBlock + * @tc.desc Test writeSingleBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0600', 0, async function (done) { + let blockIndex = 1; + let rawData = [0x0a, 0x14]; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0700 + * @tc.name testincrementBlock + * @tc.desc Test incrementBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0700', 0, async function (done) { + let blockIndex = 1; + let value = 0x20; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0800 + * @tc.name testincrementBlock + * @tc.desc Test incrementBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0800', 0, async function (done) { + let blockIndex = 1; + let value = 0x20; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_0900 + * @tc.name testdecrementBlock + * @tc.desc Test decrementBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_0900', 0, async function (done) { + let blockIndex = 1; + let value = 0x20; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1000 + * @tc.name testdecrementBlock + * @tc.desc Test decrementBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1000', 0, async function (done) { + let blockIndex = 1; + let value = 0x20; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1100 + * @tc.name testtransferToBlock + * @tc.desc Test transferToBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1100', 0, async function (done) { + let blockIndex = 1; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1200 + * @tc.name testtransferToBlock + * @tc.desc Test transferToBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1200', 0, async function (done) { + let blockIndex = 1; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1300 + * @tc.name testrestoreFromBlock + * @tc.desc Test restoreFromBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1300', 0, async function (done) { + let blockIndex = 1; + await mifareClassic.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); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1400 + * @tc.name testrestoreFromBlock + * @tc.desc Test restoreFromBlock api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1400', 0, async function (done) { + let blockIndex = 1; + mifareClassic.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(); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1500 + * @tc.name testgetSectorCount + * @tc.desc Test getSectorCount api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1500', 0, function () { + let sectorCount = mifareClassic.getSectorCount(); + console.info("mifareClassic sectorCount: " + sectorCount); + expect(sectorCount).assertInstanceOf('Number') + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1600 + * @tc.name testgetBlockCountInSector + * @tc.desc Test getBlockCountInSector api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1600', 0, function () { + let blockCountInSector = mifareClassic.getBlockCountInSector(); + console.info("mifareClassic blockCountInSector: " + blockCountInSector); + expect(blockCountInSector).assertInstanceOf('Number') + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1700 + * @tc.name testgetType + * @tc.desc Test getType api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1700', 0, function () { + let getType = mifareClassic.getType(); + console.info("mifareClassic getType: " + getType); + expect(true).assertTrue(getType >= -1); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1800 + * @tc.name testgetTagSize + * @tc.desc Test getTagSize api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1800', 0, function () { + let tagSize = mifareClassic.getTagSize(); + console.info("mifareClassic tagSize: " + tagSize); + expect(tagSize).assertInstanceOf('Number') + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_1900 + * @tc.name testisEmulatedTag + * @tc.desc Test isEmulatedTag api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_1900', 0, function () { + let isEmulatedTag = mifareClassic.isEmulatedTag(); + console.info("mifareClassic isEmulatedTag: " + isEmulatedTag); + expect(false).assertEqual(isEmulatedTag); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_2000 + * @tc.name testgetBlockIndex + * @tc.desc Test getBlockIndex api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_2000', 0, function () { + let sectorIndex = 1; + let blockIndex = mifareClassic.getBlockIndex(sectorIndex); + console.info("mifareClassic blockIndex: " + blockIndex); + expect(true).assertTrue(blockIndex >= 0); + }) + + + /** + * @tc.number SUB_Communication_NFC_mifareClassic_js_2100 + * @tc.name testgetSectorIndex + * @tc.desc Test getSectorIndex api. + * @tc.size MEDIUM + * @ since 7 + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_Communication_NFC_mifareClassic_js_2100', 0, function () { + let blockIndex = 1; + let sectorIndex = mifareClassic.getSectorIndex(blockIndex); + console.info("mifareClassic sectorIndex: " + sectorIndex); + expect(true).assertTrue(sectorIndex >= 0); + }) + + console.info("*************[nfc_test] start nfc js unit test end*************"); + }) +} + diff --git a/communication/nfc_Controller/src/main/js/test/nfc.tagABFV.js b/communication/nfc_Controller/src/main/js/test/nfc.tagABFV.js deleted file mode 100644 index c14de85a90a437a48a960a6fff052cc400f3f9a9..0000000000000000000000000000000000000000 --- a/communication/nfc_Controller/src/main/js/test/nfc.tagABFV.js +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import tag from '@ohos.nfc.tag'; -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' - -function sleep(delay) { // delay x ms - let start = (new Date()).getTime(); - while ((new Date()).getTime() - start < delay) { - continue; - } -} - -let NdefRecord = { - NFC_A : 1, - NFC_B : 2, - ISO_DEP : 3, - NFC_F : 4, - NFC_V : 5, - NDEF : 6, - MIFARE_CLASSIC : 8, - MIFARE_ULTRALIGHT : 9, - NDEF_FORMATABLE : 10, -}; - -let NfcForumType = { - NFC_FORUM_TYPE_1 : 1, - NFC_FORUM_TYPE_2 : 2, - NFC_FORUM_TYPE_3 : 3, - NFC_FORUM_TYPE_4 : 4, - MIFARE_CLASSIC : 101, -}; - -let aTag = { - "uid": [0x01, 0x02, 0x03, 0x04], - "technology": [1], - "extrasData": [ - { - "Sak": 0x08, "Atqa": "B000", - }, - ], - "tagRfDiscId": 1, -}; - -let bTag = { - "uid": [0x01, 0x02, 0x03, 0x04], - "technology": [2], - "extrasData": [ - { - "AppData": "A0C0", "ProtocolInfo": "131F", - } - ], - "tagRfDiscId": 1, -}; - -let fTag = { - "uid": [0x01, 0x02, 0x03, 0x04], - "technology": [4], - "extrasData": [ - { - "SystemCode": "A0C0", "Pmm": "131F", - } - ], - "tagRfDiscId": 1, -}; - -let vTag = { - "uid": [0x01, 0x02, 0x03, 0x04], - "technology": [ 5 ], - "extrasData": [ - { - "ResponseFlags": 0x09, "DsfId": 0x13, - } - ], - "tagRfDiscId": 1, -}; - -export default function nfcTagABFVTest() { - describe('nfcTagABFVTest', function () { - beforeAll(function () { - console.info('[NFC_test]beforeAll called') - }) - beforeEach(function() { - console.info('[NFC_test]beforeEach called') - }) - afterEach(function () { - console.info('[NFC_test]afterEach called') - }) - afterAll(function () { - console.info('[NFC_test]afterAll called') - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test on_off_openNfcapi - * @tc.desc Test for getSak - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0100', 0, function () { - let nfcA ; - try{ - nfcA = tag.getNfcATag(aTag); - console.info('SUB_Communication_NFC_nfctage_js_0100 pass' ) - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0100 error' + error) - } - expect(nfcA != null).assertTrue(); - expect(nfcA instanceof Object).assertTrue(); - console.info('aTag is--<-!!!->' + JSON.stringify(nfcA)); - }) - - it('SUB_Communication_NFC_nfctage_js_0200', 0, function () { - let nfcB ; - try{ - nfcB = tag.getNfcBTag(bTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error) - } - expect(nfcB != null).assertTrue(); - expect(nfcB instanceof Object).assertTrue(); - console.info('bTag is--<-!!!->' + JSON.stringify(nfcB)); - }) - - it('SUB_Communication_NFC_nfctage_js_0300', 0, function () { - let nfcF ; - try{ - nfcF = tag.getNfcFTag(fTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - expect(nfcF != null).assertTrue(); - expect(nfcF instanceof Object).assertTrue(); - console.info('fTag is--<-!!!->' + JSON.stringify(nfcF)); - }) - - it('SUB_Communication_NFC_nfctage_js_0400', 0, function () { - let nfcV ; - try{ - nfcV = tag.getNfcVTag(vTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - expect(nfcV != null).assertTrue(); - expect(nfcV instanceof Object).assertTrue(); - console.info('vTag is--<-!!!->' + JSON.stringify(nfcV)); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getsak_taga - * @tc.desc Obtains the SAK value of the NFC-A tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0500', 0, function () { - let nfcA ; - try{ - nfcA = tag.getNfcATag(aTag); - console.info('SUB_Communication_NFC_nfctage_js_0100 pass' ) - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0100 error' + error) - } - let sak = nfcA.getSak(); - expect(sak).assertInstanceOf('Number'); - console.info('[nfc_js] test sak data>:' + sak); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getAtqa_taga - * @tc.desc Obtains the Atqa value of the NFC-A tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0600', 0, function () { - let nfcA ; - try{ - nfcA = tag.getNfcATag(aTag); - console.info('SUB_Communication_NFC_nfctage_js_0100 pass' ) - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0100 error' + error) - } - let Atqa = nfcA.getAtqa(); - expect(Atqa).assertInstanceOf('Array'); - console.info('[nfc_js] test Atqa data>:' + Atqa); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getAppData_tagB - * @tc.desc Obtains the AppData value of the NFC-B tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0700', 0, function () { - let nfcB ; - try{ - nfcB = tag.getNfcBTag(bTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error) - } - let AppData = nfcB.getRespAppData(); - expect(AppData).assertInstanceOf('Array'); - console.info('[nfc_js] test AppData data>:' + AppData); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getRespProtocol_tagB - * @tc.desc Obtains the Protocol value of the NFC-B tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0800', 0, function () { - let nfcB ; - try{ - nfcB = tag.getNfcBTag(bTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0200 error' + error) - } - let Protocol = nfcB.getRespProtocol(); - expect(Protocol).assertInstanceOf('Array'); - console.info('[nfc_js] test Protocol data>:' + Protocol); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getSystemCode_tagF - * @tc.desc Obtains the SystemCode value of the NFC-F tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_0900', 0, function () { - let nfcF ; - try{ - nfcF = tag.getNfcFTag(fTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - let SystemCode = nfcF.getSystemCode(); - expect(SystemCode).assertInstanceOf('Array'); - console.info('[nfc_js] test SystemCode data>:' + SystemCode); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getPmm_tagF - * @tc.desc Obtains the getPmm value of the NFC-F tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_1000', 0, function () { - let nfcF ; - try{ - nfcF = tag.getNfcFTag(fTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - let Pmm = nfcF.getPmm(); - expect(Pmm).assertInstanceOf('Array'); - console.info('[nfc_js] test Pmm data>:' + Pmm); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getResponseFlags_tagV - * @tc.desc Obtains the ResponseFlags value of the NFC-V tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_1100', 0, function () { - let nfcV ; - try{ - nfcV = tag.getNfcVTag(vTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - let ResponseFlags = nfcV.getResponseFlags(); - expect(ResponseFlags).assertInstanceOf('Number'); - console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags); - }) - - /** - * @tc.number SUB_Communication_NFC_nfctage_js_0010 - * @tc.name Test getDsfId_tagV - * @tc.desc Obtains the DsfId value of the NFC-V tag. - * @tc.size since 7 - * @tc.type Function - * @tc.level Level 2 - */ - it('SUB_Communication_NFC_nfctage_js_1200', 0, function () { - let nfcV ; - try{ - nfcV = tag.getNfcVTag(vTag); - }catch(error){ - console.info('SUB_Communication_NFC_nfctage_js_0300 error' + error) - } - let DsfId = nfcV.getDsfId(); - expect(DsfId).assertInstanceOf('Number'); - console.info('[nfc_js] test DsfId data>:' + DsfId); - }) - - console.info("*************[nfc_test] start nfc js unit test end*************"); - }) -} -