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 fade0b054d51970fd1812f8eac1bbd6b7998fb03..4a2351772b508c55d98eba94ac8a2c45e1244f6e 100644 --- a/communication/nfc_Controller/src/main/js/test/List.test.js +++ b/communication/nfc_Controller/src/main/js/test/List.test.js @@ -20,6 +20,7 @@ import nfcMifareClassicTag from './nfc.MifareClassicTag.js' import nfcMifareUltralightTag from './nfc.MifareUltralightTag.js' import nfcTagABFVTest from './nfc.TagABFV.js' import nfcNDEFTagTest from './nfc.NDEFTag.js' +import ConnectedTagTest from './nfc.ConnectedTag.js' import parameter from '@ohos.systemparameter'; let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false"); export default function testsuite() { @@ -32,6 +33,7 @@ if (info != "false") nfcMifareUltralightTag(); nfcTagABFVTest(); nfcNDEFTagTest(); + ConnectedTagTest(); } } diff --git a/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js new file mode 100644 index 0000000000000000000000000000000000000000..8a270e5513dbd409953168e1a5bddc5b3fdd05eb --- /dev/null +++ b/communication/nfc_Controller/src/main/js/test/nfc.ConnectedTag.js @@ -0,0 +1,239 @@ +/* + * 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*************"); + }) +} + diff --git a/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js index c786cad885a64473a25e79850a3b9ef893a6b41e..10e0b1a828c11936c22a4f88adb0fb1fe2f523bd 100644 --- a/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js +++ b/communication/wifi_standard/src/main/js/test/WifiStationEvent.test.js @@ -17,6 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from import wifi from '@ohos.wifi' +import wifiext from '@ohos.wifiext' function sleep(delay) { return new Promise(resovle => setTimeout(resovle, delay)) @@ -37,6 +38,12 @@ let wifiSecurityType = { WIFI_SEC_TYPE_SAE: 4, } +let PowerModel = { + SLEEPING : 0, + GENERAL : 1, + THROUGH_WALL : 2, +} + let connState = { SCANNING: 0, CONNECTING: 1, @@ -163,8 +170,223 @@ export default function actsWifiEventTest() { wifi.off(hotspotState, hotspotStateChangeCallback); 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*************"); }) } +