提交 8c567180 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 e07723ba
......@@ -14,11 +14,18 @@
*/
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 parameter from '@ohos.systemparameter';
let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
export default function testsuite() {
if (info != "false")
{
nfcControllerTest();
nfcIsoDepTagTest();
nfcMifareClassicTag();
nfcTagABFVTest();
}
}
......@@ -18,56 +18,6 @@ import tag from '@ohos.nfc.tag';
import controller from '@ohos.nfc.controller';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let aTag = {
"uid": "15273952",
"technology": [1, 2],
"extrasData": [
{
"sak": 0x08, "atqa": "B000"
},
{
"appData": "A0C0", "protocolInfo": "131F"
}
],
"tagRfDiscId": 1,
};
let vTag = {
"uid": "17293952",
"technology": [ 5 ],
"extrasData": [{"responseFlags": 0xA0, "dsfId": 0x13}],
"tagRfDiscId": 1,
};
let bTag = {
"uid": "15273952",
"technology": [1, 2],
"extrasData": [
{
"sak": 0x08, "atqa": "B000"
},
{
"appData": "A0C0", "protocolInfo": "131F"
}
],
"tagRfDiscId": 1,
};
let fTag = {
"uid": "15273952",
"technology": [2, 4],
"extrasData": [
{
"appData": "A0C0", "protInfo": "131F"
},
{
"systemCode": "A0C0", "pmm": "131F"
}
],
"tagRfDiscId": 1,
};
function sleep(delay) { // delay x ms
let start = (new Date()).getTime();
while ((new Date()).getTime() - start < delay) {
......@@ -195,63 +145,8 @@ export default function nfcControllerTest() {
expect(error!=null).assertTrue();
}
})
/**
* @tc.number SUB_COMMUNICATION_NFC_getTag_js_0700
* @tc.name Test getNfcATagapi
* @tc.desc Obtaining an NFC Type A Tag Object
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_NFC_getTag_js_0700', 0, function () {
let taga = tag.getNfcATag(aTag);
expect(taga !=null).assertTrue();
console.info('aTag is--<-!!!->' + JSON.stringify(taga));
})
/**
* @tc.number SUB_COMMUNICATION_NFC_getTag_js_0800
* @tc.name Test getNfcVTagapi
* @tc.desc Obtaining an NFC Type V Tag Object
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_NFC_getTag_js_0800', 0, function () {
let tagV = tag.getNfcVTag(vTag);
expect(vTag !=null).assertTrue();
console.info('vTag is--<-!!!->' + JSON.stringify(tagV));
})
/**
* @tc.number SUB_COMMUNICATION_NFC_getTag_js_0900
* @tc.name Test getNfcBTagapi
* @tc.desc Obtaining an NFC Type B Tag Object
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_NFC_getTag_js_0900', 0, function () {
let tagB = tag.getNfcBTag(bTag);
expect(tagB !=null).assertTrue();
console.info('bTag is--<-!!!->' + JSON.stringify(tagB));
})
/**
* @tc.number SUB_COMMUNICATION_NFC_getTag_js_1000
* @tc.name Test getNfcFTagapi
* @tc.desc Obtaining an NFC Type F Tag Object
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_COMMUNICATION_NFC_getTag_js_1000', 0, function () {
let tagF = tag.getNfcFTag(fTag);
expect(tagF !=null).assertTrue();
console.info('fTag is--<-!!!->' + JSON.stringify(tagF));
})
console.log("*************[nfc_test] start nfc js unit test end*************");
})
}
/*
* 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 isoDepTaginfo = {
"uid": [0x01, 0x02, 0x03, 0x04],
"technology": [1, 3],
"extrasData": [
{
"Sak": 0x08, "Atqa": "B000",
},
{
"HistoricalBytes": "4D54000500308693695B", "HiLayerResponse": "",
},
],
"tagRfDiscId": 1,
};
let isoDep ;
export default function nfcIsoDepTagTest() {
describe('nfcIsoDepTagTest', function () {
beforeAll(function () {
console.info('[NFC_test]beforeAll called')
try{
isoDep = tag.getIsoDep(isoDepTaginfo);
}catch(error){
console.info('getIsoDep is ->' + 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_nfctage_js_0010
* @tc.name Test getHistoricalBytes IsoDep
* @tc.desc Obtains the history bytes of a label.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, function () {
let ResponseFlags = isoDep.getHistoricalBytes();
expect(ResponseFlags).assertInstanceOf('Array')
console.info('[nfc_js] test ResponseFlags data>:' + ResponseFlags);
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0010
* @tc.name Test getHiLayerResponse IsoDep
* @tc.desc HiLayer response byte for obtaining the tag.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, function () {
let HiLayerResponse = isoDep.getHiLayerResponse();
expect(HiLayerResponse).assertInstanceOf('Array')
console.info('[nfc_js] test ResponseFlags data>:' + HiLayerResponse);
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0010
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported.Promise
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, async function (done) {
await isoDep.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();
});
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0010
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported.callback
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0400', 0, async function (done) {
isoDep.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();
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
/*
* 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 mifareclassicTaginfo = {
"uid": [0x01, 0x02, 0x03, 0x04],
"technology": [1, 8],
"extrasData": [
{
"Sak": 0x08, "Atqa": "B000",
},
{
},
],
"tagRfDiscId": 1,
};
let mifareClassic = null;
export default function nfcControllerTest1() {
describe('nfcControllerTest1', function () {
beforeAll(function () {
console.info('[NFC_test]beforeAll called')
try{
mifareClassic = tag.getMifareClassic(mifareclassicTaginfo);
}catch(error){
console.log('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_0001
* @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_0001', 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));
expect(data).assertTrue();
done();
}).catch((err)=> {
console.log("mifareClassic authenticateSector1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0002
* @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_0002', 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);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic authenticateSector2 data: " + data + "json2:" + JSON.stringify(data));
expect(data).assertTrue();
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0003
* @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_0003', 0, async function (done) {
let mifareClassic;
try{
mifareClassic = tag.getMifareClassic(mifareclassicTaginfo);
}catch(error){
console.log('beforeAll mifareClassic error' + error)
}
let blockIndex = 1;
await mifareClassic.readSingleBlock(blockIndex).then((data) => {
console.log("mifareClassic readSingleBlock1 data: " + data + "json3:" + JSON.stringify(data));
expect(data).assertInstanceOf('Array')
done();
}).catch((err)=> {
console.log("mifareClassic readSingleBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0004
* @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_0004', 0, async function (done) {
let blockIndex = 1;
mifareClassic.readSingleBlock(blockIndex, (err, data)=> {
if (err) {
console.log("mifareClassic readSingleBlock2 err: " + err);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic readSingleBlock2 data: " + data+ "json4:" + JSON.stringify(data));
expect(data).assertInstanceOf('Array')
}
});
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0005
* @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_0005', 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));
expect(data).assertTrue();
done();
}).catch((err)=> {
console.log("mifareClassic writeSingleBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0006
* @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_0006', 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);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic writeSingleBlock2 data: " + data + "json6:" + JSON.stringify(data));
expect(data).assertTrue();
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0007
* @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_0007', 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));
expect(data).assertInstanceOf('Number')
done();
}).catch((err)=> {
console.log("mifareClassic incrementBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0008
* @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_0008', 0, async function (done) {
let blockIndex = 1;
let value = 0x20;
mifareClassic.incrementBlock(blockIndex, value, (err, data)=> {
if (err) {
console.log("mifareClassic incrementBlock2 err: " + err);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic incrementBlock2 data: " + data + "json8:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0009
* @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_0009', 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));
expect(data).assertInstanceOf('Number')
done();
}).catch((err)=> {
console.log("mifareClassic decrementBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0010
* @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_0010', 0, async function (done) {
let blockIndex = 1;
let value = 0x20;
mifareClassic.decrementBlock(blockIndex, value, (err, data)=> {
if (err) {
console.log("mifareClassic decrementBlock2 err: " + err);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic decrementBlock2 data: " + data + "json10:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0011
* @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_0011', 0, async function (done) {
let blockIndex = 1;
await mifareClassic.transferToBlock(blockIndex).then((data) => {
console.log("mifareClassic transferToBlock1 data: " + data + "json9:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
done();
}).catch((err)=> {
console.log("mifareClassic transferToBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0012
* @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_0012', 0, async function (done) {
let blockIndex = 1;
mifareClassic.transferToBlock(blockIndex, (err, data)=> {
if (err) {
console.log("mifareClassic transferToBlock2 err: " + err);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic transferToBlock2 data: " + data + "json10:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0013
* @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_0013', 0, async function (done) {
let blockIndex = 1;
await mifareClassic.restoreFromBlock(blockIndex).then((data) => {
console.log("mifareClassic restoreFromBlock1 data: " + data + "json11:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
done();
}).catch((err)=> {
console.log("mifareClassic restoreFromBlock1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0014
* @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_0014', 0, async function (done) {
let blockIndex = 1;
mifareClassic.restoreFromBlock(blockIndex, (err, data)=> {
if (err) {
console.log("mifareClassic restoreFromBlock2 err: " + err);
expect(true).assertEqual(true);
} else {
console.log("mifareClassic restoreFromBlock2 data: " + data + "json12:" + JSON.stringify(data));
expect(data).assertInstanceOf('Number')
}
});
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0015
* @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_0015', 0, function () {
let sectorCount = mifareClassic.getSectorCount();
console.log("mifareClassic sectorCount: " + sectorCount);
expect(sectorCount).assertInstanceOf('Number')
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0016
* @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_0016', 0, function () {
let blockCountInSector = mifareClassic.getBlockCountInSector();
console.log("mifareClassic blockCountInSector: " + blockCountInSector);
expect(blockCountInSector).assertInstanceOf('Number')
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0017
* @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_0017', 0, function () {
let getType = mifareClassic.getType();
console.log("mifareClassic getType: " + getType);
expect(true).assertTrue(getType >= -1);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0018
* @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_0018', 0, function () {
let tagSize = mifareClassic.getTagSize();
console.log("mifareClassic tagSize: " + tagSize);
expect(tagSize).assertInstanceOf('Number')
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0019
* @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_0019', 0, function () {
let isEmulatedTag = mifareClassic.isEmulatedTag();
console.log("mifareClassic isEmulatedTag: " + isEmulatedTag);
expect(false).assertEqual(isEmulatedTag);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0020
* @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_0020', 0, function () {
let sectorIndex = 1;
let blockIndex = mifareClassic.getBlockIndex(sectorIndex);
console.log("mifareClassic blockIndex: " + blockIndex);
expect(true).assertTrue(blockIndex >= 0);
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0021
* @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_0021', 0, function () {
let blockIndex = 1;
let sectorIndex = mifareClassic.getSectorIndex(blockIndex);
console.log("mifareClassic sectorIndex: " + sectorIndex);
expect(true).assertTrue(sectorIndex >= 0);
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
/*
* 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*************");
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册