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

!6249 【communication】新增NFC L2测试用例2

Merge pull request !6249 from 权力/myfeature
...@@ -13,18 +13,22 @@ ...@@ -13,18 +13,22 @@
* limitations under the License. * limitations under the License.
*/ */
import nfcATagSessionTest from './nfc.ATagSession.js'
import nfcControllerTest from './nfc.Controller.js' import nfcControllerTest from './nfc.Controller.js'
import nfcIsoDepTagTest from './nfc.IsoDepTag.js' import nfcIsoDepTagTest from './nfc.IsoDepTag.js'
import nfcMifareClassicTag from './nfc.MifareClassicTag.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'; import parameter from '@ohos.systemparameter';
let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false"); let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
export default function testsuite() { export default function testsuite() {
if (info != "false") if (info != "false")
{ {
nfcATagSessionTest();
nfcControllerTest(); nfcControllerTest();
nfcIsoDepTagTest(); nfcIsoDepTagTest();
nfcMifareClassicTag(); nfcMifareClassicTag();
nfcMifareUltralightTag();
nfcTagABFVTest(); nfcTagABFVTest();
} }
} }
......
/*
* 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*************");
})
}
...@@ -60,7 +60,7 @@ export default function nfcControllerTest() { ...@@ -60,7 +60,7 @@ export default function nfcControllerTest() {
let openNfcswitch = controller.openNfc(); let openNfcswitch = controller.openNfc();
sleep(5000); sleep(5000);
console.info('[nfc_js] open Nfc switch ->' + openNfcswitch); console.info('[nfc_js] open Nfc switch ->' + openNfcswitch);
expect(openNfcswitch===undefined || openNfcswitch===true).assertTrue(); expect(openNfcswitch).assertTrue();
}catch(error) { }catch(error) {
console.info('[nfc_js] Failed to enable the switch ->' + error); console.info('[nfc_js] Failed to enable the switch ->' + error);
expect(error != null).assertTrue(); expect(error != null).assertTrue();
...@@ -139,7 +139,7 @@ export default function nfcControllerTest() { ...@@ -139,7 +139,7 @@ export default function nfcControllerTest() {
try { try {
let closeNfc = controller.closeNfc(); let closeNfc = controller.closeNfc();
console.info('[nfc_js] clocse Nfc switch ->' + closeNfc); console.info('[nfc_js] clocse Nfc switch ->' + closeNfc);
expect(closeNfc===undefined || closeNfc===true).assertTrue(); expect(closeNfc).assertTrue();
}catch(error) { }catch(error) {
console.info('[nfc_js] Failed to disable the switch ->' + error ); console.info('[nfc_js] Failed to disable the switch ->' + error );
expect(error!=null).assertTrue(); expect(error!=null).assertTrue();
......
...@@ -79,7 +79,7 @@ export default function nfcIsoDepTagTest() { ...@@ -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.name Test getHistoricalBytes IsoDep
* @tc.desc Obtains the history bytes of a label. * @tc.desc Obtains the history bytes of a label.
* @tc.size since 9 * @tc.size since 9
...@@ -93,7 +93,7 @@ export default function nfcIsoDepTagTest() { ...@@ -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.name Test getHiLayerResponse IsoDep
* @tc.desc HiLayer response byte for obtaining the tag. * @tc.desc HiLayer response byte for obtaining the tag.
* @tc.size since 9 * @tc.size since 9
...@@ -107,7 +107,7 @@ export default function nfcIsoDepTagTest() { ...@@ -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.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported.Promise * @tc.desc Check whether extended APDUs are supported.Promise
* @tc.size since 9 * @tc.size since 9
...@@ -127,7 +127,7 @@ export default function nfcIsoDepTagTest() { ...@@ -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.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported.callback * @tc.desc Check whether extended APDUs are supported.callback
* @tc.size since 9 * @tc.size since 9
......
/*
* 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*************");
})
}
/*
* 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*************");
})
}
/*
* 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.
先完成此消息的编辑!
想要评论请 注册