提交 07445e52 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 0b8d0c24
...@@ -20,6 +20,7 @@ import nfcMifareClassicTag from './nfc.MifareClassicTag.js' ...@@ -20,6 +20,7 @@ import nfcMifareClassicTag from './nfc.MifareClassicTag.js'
import nfcMifareUltralightTag from './nfc.MifareUltralightTag.js' import nfcMifareUltralightTag from './nfc.MifareUltralightTag.js'
import nfcTagABFVTest from './nfc.TagABFV.js' import nfcTagABFVTest from './nfc.TagABFV.js'
import nfcNDEFTagTest from './nfc.NDEFTag.js' import nfcNDEFTagTest from './nfc.NDEFTag.js'
import ConnectedTagTest from './nfc.ConnectedTag.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() {
...@@ -32,6 +33,7 @@ if (info != "false") ...@@ -32,6 +33,7 @@ if (info != "false")
nfcMifareUltralightTag(); nfcMifareUltralightTag();
nfcTagABFVTest(); nfcTagABFVTest();
nfcNDEFTagTest(); nfcNDEFTagTest();
ConnectedTagTest();
} }
} }
/*
* 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 connectedTag from '@ohos.connectedTag';
import parameter from '@ohos.systemparameter';
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 NfcRfType = {
NFC_RF_LEAVE : 0,
NFC_RF_ENTER : 1,
}
export default function ConnectedTagTest() {
describe('ConnectedTagTest', 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_nfcConnectedTag_js_0100
* @tc.name Test init connectedTag
* @tc.desc Initializes the active label chip.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0100', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
let inittag = connectedTag.init();
expect(inittag).assertTrue();
console.info("mifareUltralight readMultiplePages1 err: " + inittag );
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0200
* @tc.name Test init connectedTag
* @tc.desc Reads the content of the active tag.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0200', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
await connectedTag.readNdefTag().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(true).assertTrue(result != null);
done();
}).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0300
* @tc.name Test init connectedTag
* @tc.desc Reads the content of the active tag.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0300', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
connectedTag.readNdefTag((err, result)=> {
if (err) {
expect().assertFail();
console.info("isoDep isExtendedApduSupported err: " + err);
} else {
expect(result!=null).assertEqual(data);
console.info("isoDep isExtendedApduSupported data: " + result);
}
});
}
done();
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0400
* @tc.name Test writeNdefTag connectedTag
* @tc.desc Write Content to Active Tags
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0400', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
done();
}
else{
await connectedTag.writeNdefTag().then(result => {
console.info("mifareUltralight readMultiplePages1 data: " + data + "json1:" + JSON.stringify(data));
expect(true).assertTrue(result != null);
done();
}).catch((err)=> {
console.info("mifareUltralight readMultiplePages1 err: " + err);
expect(true).assertEqual(true);
done();
});
sleep(3000);
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0500
* @tc.name Test writeNdefTag connectedTag
* @tc.desc Write Content to Active Tags
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0500', 0, async function (done) {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
connectedTag.writeNdefTag((err, result)=> {
if (err) {
expect().assertFail();
console.info("isoDep isExtendedApduSupported err: " + err);
} else {
expect(result!=null).assertEqual(data);
console.info("isoDep isExtendedApduSupported data: " + result);
}
});
}
done();
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0600
* @tc.name Test on_off connectedTag
* @tc.desc Registers and cancels the NFC field strength status event.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0600', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
let recvNfcRfNotifyFunc = result => {
console.info("nfc state receive state ->" + result);
expect(result != null).assertTrue();
}
connectedTag.on('notify',recvNfcRfNotifyFunc)
connectedTag.off('notify',recvNfcRfNotifyFunc)
}
})
/**
* @tc.number SUB_Communication_NFC_nfcConnectedTag_js_0700
* @tc.name Test uninit connectedTag
* @tc.desc Unloads active label chip resources.
* @tc.size since 8
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcConnectedTag_js_0700', 0, function () {
var isAccessToken = canIUse("SystemCapability.Communication.ConnectedTag");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (!isAccessToken) {
console.info("The device does not support active label chips.")
expect(isAccessToken).assertFalse()
}
else{
let uninittag = connectedTag.uninit();
expect(uninittag).assertTrue();
console.info("mifareUltralight readMultiplePages1 err: " + uninittag );
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
...@@ -17,6 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from ...@@ -17,6 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import wifi from '@ohos.wifi' import wifi from '@ohos.wifi'
import wifiext from '@ohos.wifiext'
function sleep(delay) { function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay)) return new Promise(resovle => setTimeout(resovle, delay))
...@@ -37,6 +38,12 @@ let wifiSecurityType = { ...@@ -37,6 +38,12 @@ let wifiSecurityType = {
WIFI_SEC_TYPE_SAE: 4, WIFI_SEC_TYPE_SAE: 4,
} }
let PowerModel = {
SLEEPING : 0,
GENERAL : 1,
THROUGH_WALL : 2,
}
let connState = { let connState = {
SCANNING: 0, SCANNING: 0,
CONNECTING: 1, CONNECTING: 1,
...@@ -163,8 +170,223 @@ export default function actsWifiEventTest() { ...@@ -163,8 +170,223 @@ export default function actsWifiEventTest() {
wifi.off(hotspotState, hotspotStateChangeCallback); wifi.off(hotspotState, hotspotStateChangeCallback);
done(); done();
}) })
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0001
* @tc.name testenableHotspot
* @tc.desc Test enableHotspot api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0001', 0, async function (done) {
console.info('testSysCaps01 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
console.info("[wifi_test] enableHotspot: " + wifiext.enableHotspot())
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps01 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps01 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0002
* @tc.name testdisableHotspot
* @tc.desc Test disableHotspot api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0002', 0, async function (done) {
console.info('testSysCaps02 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
console.info("[wifi_test] disableHotspot: " + wifiext.disableHotspot())
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps02 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps02 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0003
* @tc.name testgetSupportedPowerModel
* @tc.desc Test getSupportedPowerModel api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0003', 0, async function (done) {
console.info('testSysCaps03 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
await wifiext.getSupportedPowerModel()
.then(data => {
console.info("[wifi_test]getSupportedPowerModel promise result -> " + JSON.stringify(data));
});
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps03 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps03 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0004
* @tc.name testgetSupportedPowerModel
* @tc.desc Test getSupportedPowerModel api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0004', 0, async function (done) {
console.info('testSysCaps04 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps04 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
function getSupportedPowerModelResult(){
return new Promise((resolve, reject) => {
wifiext.getSupportedPowerModel(
(err, result) => {
if(err) {
console.info("[wifi_test]failed to getSupportedPowerModel:" + JSON.stringify(err));
expect(true).assertTrue();
}
console.info("[wifi_test]getSupportedPowerModel callback:" + JSON.stringify(result));
resolve();
});
});
}
await getSupportedPowerModelResult();
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps04 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps04 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0005
* @tc.name testgetPowerModel
* @tc.desc Test getPowerModel api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0005', 0, async function (done) {
console.info('testSysCaps05 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
await wifiext.getPowerModel()
.then(data => {
console.info("[wifi_test]getPowerModel promise result -> " + JSON.stringify(data));
});
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps05 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps05 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0006
* @tc.name testgetPowerModel
* @tc.desc Test getPowerModel api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0006', 0, async function (done) {
console.info('testSysCaps04 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps04 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
function getPowerModelResult(){
return new Promise((resolve, reject) => {
wifiext.getPowerModel(
(err, result) => {
if(err) {
console.info("[wifi_test]failed to getPowerModel:" + JSON.stringify(err));
expect(true).assertTrue();
}
console.info("[wifi_test]getPowerModel callback:" + JSON.stringify(result));
resolve();
});
});
}
await getPowerModelResult();
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps06 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps06 end');
done();
})
/**
* @tc.number SUB_Communication_WiFi_SysCaps_Test_0007
* @tc.name testsetPowerModel
* @tc.desc Test setPowerModel api.
* @tc.type Function
*/
it('SUB_Communication_WiFi_SysCaps_Test_0007', 0, async function (done) {
console.info('testSysCaps01 start');
let ret = false;
try {
var isAccessToken = canIUse("SystemCapability.Communication.WiFi.AP.Extension");
console.info("testSysCaps01 test.syscap.param.001 : " + isAccessToken);
if (isAccessToken) {
ret = true;
}
console.info("[wifi_test] setPowerModel: " + wifiext.setPowerModel(PowerModel))
expect(isAccessToken).assertFalse();
done();
} catch (e) {
expect(ret).assertFalse();
console.info("testSysCaps07 canIUse isAccessToken error: " + e);
}
console.info('testSysCaps07 end');
done();
})
console.log("*************[wifi_test] start wifi js unit test end*************"); console.log("*************[wifi_test] start wifi js unit test end*************");
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册