提交 0cab7285 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 4901cdb1
......@@ -23,6 +23,7 @@ group("communication") {
"bluetooth_standard:ActsBluetoothJsTest",
"dsoftbus/rpc:ActsRpcJsTest",
"nfc_Controller:ActsNFCJSTest",
"nfc_ErrorCode:ActsNFCErrorJSTest",
"wifi_p2p:ActsP2PJSTest",
"wifi_standard:ActsWifiJSTest",
]
......
......@@ -344,99 +344,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1300
* @tc.name testSppListen
* @tc.desc Test 2900003 - Bluetooth switch is off
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_1300', 0, async function (done) {
try {
let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: bluetooth.SppType.SPP_RFCOMM};
let serverNumber = -1;
function serverSocket(code, number) {
if (code) {
console.log('bluetooth error code01: ' + code);
}else{
console.log('bluetooth serverSocket Number:' + JSON.stringify(number));
serverNumber = number;
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppListen('server1', SppOption, serverSocket);
expect(true).assertFalse();
done()
} catch (error) {
console.error('[bluetooth_js]sppListen error.code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900003');
done()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1400
* @tc.name testSppAccept
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_1400', 0, async function (done) {
try {
function acceptClientSocket(code, number) {
if (code) {
console.log('[bluetooth_js] error code05: ' + JSON.stringify(code));
}else{
console.log('[bluetooth_js] clientSocket Number:' + JSON.stringify(number));
expect(true).assertEqual(number!=null);
}
}
bluetooth.sppAccept(0, acceptClientSocket);
expect(true).assertFalse();
done()
} catch (error) {
console.error('[bluetooth_js]sppAccept error.code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900003');
done()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1500
* @tc.name testSppConnect
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_1500', 0, async function (done) {
try {
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB',
secure: true, type: 0};
bluetooth.sppConnect('00:11:22:33:44:55', sppOption, function(code, number) {
if (code) {
console.info('[bluetooth_js] code is: ' + JSON.stringify(code));
} else {
console.log('[bluetooth_js]sppConnect Number:'
+ JSON.stringify(number));
}
});
expect(true).assertFalse();
done()
} catch (error) {
console.error('[bluetooth_js]sppConnect error.code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900003');
done()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1600
* @tc.name test getDevice HFP State.
......@@ -701,28 +608,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2700
* @tc.name test getConnectedBLEDevices
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_2700', 0, function () {
try {
let result = bluetooth.BLE.getConnectedBLEDevices();
console.info("[bluetooth_js] getConnDev:" + JSON.stringify(result)
+ "length:" +result.length);
expect(true).assertFalse();
} catch (error) {
console.error(`[bluetooth_js]getConnDev failed, code is ${error.code},
message is ${error.message}`);
expect(error.code).assertEqual('2900003');
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2800
* @tc.name testClassicStartBLEScan
......@@ -971,43 +856,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3500
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_3500', 0, async function (done) {
try {
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: descV};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue:
arrayBufferC, descriptors:descriptors};
let NotifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue:
characteristic.characteristicValue, confirm: false};
gattServer.notifyCharacteristicChanged('00:11:22:33:44:55', NotifyCharacteristic);
expect(true).assertFalse();
done();
} catch (error) {
console.error('[bluetooth_js]notifyCharacteristicChanged1 failed, code:'
+JSON.stringify(error.code)+'error.message:'+JSON.stringify(error.message));
expect(error.code).assertEqual('2900003');
done()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3600
* @tc.name testSendResponse success
......
......@@ -132,8 +132,10 @@ describe('bluetoothhostTest_host_3', function () {
}
let hfpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY);
hfpSrc.on('connectionStateChange', StateChangeParam);
hfpSrc.connect('11:22:33:44:55:66');
let conn = hfpSrc.connect('11:22:33:44:55:66');
await sleep(6000);
console.info('[bluetooth_js]hfp connect result:' + JSON.stringify(conn));
expect(conn).assertFalse();
hfpSrc.off('connectionStateChange', StateChangeParam);
done();
})
......@@ -220,4 +222,3 @@ describe('bluetoothhostTest_host_3', function () {
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsNFCErrorJSTest") {
hap_profile = "./src/main/config.json"
deps = [
":nfc_js_assets",
":nfc_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsNFCErrorJSTest"
part_name = "nfc"
subsystem_name = "communication"
}
ohos_js_assets("nfc_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("nfc_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for nfc js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "600000",
"testcase-timeout": "600000",
"bundle-name": "ohos.acts.communication.nfc.nfcdevice",
"package-name": "ohos.acts.communication.nfc.nfcdevice"
},
"kits": [
{
"test-file-name": [
"ActsNFCErrorJSTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "ohos.acts.communication.nfc.nfcdevice",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.communication.nfc.nfcdevice",
"name": ".entry",
"mainAbility": ".MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "nfc_standard",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.NFC_CARD_EMULATION",
"reason": "use ohos.permission.SET_nfc_INFO"
},
{
"name": "ohos.permission.NFC_TAG",
"reason": "use ohos.permission.NFC_TAG"
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"srcPath": ""
}
}
/*
* 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.
*/
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
/*
* 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
/*
* 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.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: '',
myTimeout: 25000
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
console.info('onReady finish')
},
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* 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 nfcIsoDepErrorTest from './error.IsoDepTag.js'
import MifareClassicErrorTest from './error.MifareClassicTag.js'
import UltralightTagErrorTest from './error.MifareUltralightTag.js'
import nfcNDEFErrorTest from './error.NDEFTag.js'
import nfcTagABFVErrorTest from './error.TagABFV.js'
import parameter from '@ohos.systemparameter';
let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
export default function testsuite() {
if (info != "false")
{
nfcIsoDepErrorTest();
MifareClassicErrorTest();
UltralightTagErrorTest();
nfcNDEFErrorTest();
nfcTagABFVErrorTest();
}
}
\ No newline at end of file
/*
* 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 FeatureType = {
HCE : 0,
UICC : 0,
ESE : 0,
}
let isoDepTaginfo = {
"uid": [0x01, 0x02, 0x03, 0x04],
"technology": [1, 3],
"extrasData": [
{
"Sak": 0x08, "Atqa": "B000",
},
{
"HistoricalBytes": "4D54000500308693695B", "HiLayerResponse": "",
},
],
"tagRfDiscId": 1,
};
let IsoDepTag ;
export default function nfcIsoDepErrorTest() {
describe('nfcIsoDepErrorTest', function () {
beforeAll(function () {
console.info('beforeAll called')
})
beforeEach(function() {
console.info('beforeEach called')
try{
IsoDepTag = tag.getIsoDep(isoDepTaginfo);
}catch(error){
console.info('getIsoDep is ->' + error)
}
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0100
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported Promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0100', 0, async function (done) {
if (IsoDepTag != null && IsoDepTag != undefined) {
(async () => {
try {
let result = await IsoDepTag.isExtendedApduSupported('test');
console.info("[NFC_test]isoDep1 isExtendedApduSupported data: " + result);
expect(result).assertInstanceOf('Array')
expect().assertFail()
} catch(error) {
console.info("[NFC_test]isoDep1 isExtendedApduSupported errorcode: " + error.code);
expect(401).assertEqual(error.code)
}
})();
sleep(3000);
done();
} else {
console.info("[NFC_test]IsoDepTag1 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0200
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0200', 0, async function (done) {
if (IsoDepTag != null && IsoDepTag != undefined) {
try {
IsoDepTag.isExtendedApduSupported('test')((err, data)=> {
if (err) {
expect().assertFail();
console.info("[NFC_test]isoDep2 isExtendedApduSupported errcode: " + err);
} else {
expect(false).assertEqual(data);
console.info("[NFC_test]isoDep2 isExtendedApduSupported data: " + data);
}
});
} catch (error) {
console.info("[NFC_test]isoDep2 isExtendedApduSupported errorcode: " + error.code);
expect(401).assertEqual(error.code)
}
done();
} else {
console.info("[NFC_test]IsoDepTag2 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0300
* @tc.name Test getIsoDep IsoDep
* @tc.desc Obtains an object based on the tag information The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfcIsoDep_js_0300', 0, function () {
if (IsoDepTag != null && IsoDepTag != undefined) {
try {
let getIsoDepTaginfo = tag.getIsoDep("test");
console.info("[NFC_test]isoDep3 getIsoDep: " + getIsoDepTaginfo);
} catch (error) {
console.info("[NFC_test]isoDep3 getIsoDep errorcode: " + error.code);
expect(401).assertEqual(error.code)
}
} else {
console.info("[NFC_test]IsoDepTag3 = null & = undefined: ");
expect(true).assertFalse();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
/*
* 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,
};
let MifareUltralightType = {
TYPE_UNKOWN : 0x04,
TYPE_ULTRALIGHT : 1,
TYPE_ULTRALIGHT_C : 2,
}
let MifareUltralightTag = null;
export default function UltralightTagErrorTest() {
describe('UltralightTagErrorTest', function () {
beforeAll(function () {
console.info('beforeAll called')
})
beforeEach(function() {
console.info('beforeEach called')
try{
MifareUltralightTag = tag.getMifareUltralight(mifareUltralightTaginfo);
console.info(' mifareUltralight is' + mifareUltralight)
}catch(error){
console.info(' mifareUltralight error' + error)
}
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0100
* @tc.name testreadMultiplePages
* @tc.desc Test readMultiplePages api by promise. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_mifareUltralight_0100', 0, async function (done) {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let pageIndex = 1;
(async () => {
try {
let result = await MifareUltralightTag.readMultiplePages('test');
console.info("[NFC_test]mifareUltralight1 readMultiplePages data: " + result);
} catch(error) {
console.info("[NFC_test]mifareUltralight1 readMultiplePages errorcode: " + error.code);
expect(401).assertEqual(error.code);
}
})();
sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight1 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0200
* @tc.name testreadMultiplePages
* @tc.desc Test readMultiplePages api by callback. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_mifareUltralight_0200', 0, async function (done) {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let pageIndex = 1;
try {
MifareUltralightTag.readMultiplePages('test', (err, data)=> {
if (err) {
console.info("[NFC_test]mifareUltralight2 readMultiplePages errcode: " + err);
expect(true).assertEqual(true);
} else {
console.info("[NFC_test]mifareUltralight2 readMultiplePages data: " + data + "json2:" + JSON.stringify(data));
expect(true).assertTrue(data >= 0);
}
});
} catch (error) {
console.info("[NFC_test]mifareUltralight2 readMultiplePages errorcode: " + error.code);
expect(401).assertEqual(error.code);
}
sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight2 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0300
* @tc.name testwriteSinglePage
* @tc.desc Test writeSinglePage api by promise. The error code is 401
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_mifareUltralight_0300', 0, async function (done) {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let pageIndex = 1;
let rawData = [0x01, 0x02];
(async () => {
try {
let result = await MifareUltralightTag.writeSinglePage('test', rawData);
console.info("[NFC_test]mifareUltralight3 writeSinglePage data: " + result);
} catch(error) {
console.info("[NFC_test]mifareUltralight3 writeSinglePage errorcode: " + error.code);
expect(401).assertEqual(error.code);
}
})();
sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight3 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0400
* @tc.name testwriteSinglePage
* @tc.desc Test writeSinglePage api by callback. The error code is 401
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_mifareUltralight_0400', 0, async function (done) {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
let pageIndex = 1;
let rawData = [0x01, 0x02];
try {
MifareUltralightTag.writeSinglePage('test', rawData, (err, data)=> {
if (err) {
console.log("[NFC_test]mifareUltralight4 writeSinglePage errcode: " + err);
expect(true).assertEqual(true);
} else {
console.log("[NFC_test]mifareUltralight4 writeSinglePage data: " + data + "json2:" + JSON.stringify(data));
expect(true).assertTrue(data >= 0);
}
});
} catch (error) {
console.info("[NFC_test]mifareUltralight4 writeSinglePage errorcode: " + error.code);
expect(401).assertEqual(error.code);
}
sleep(3000);
done();
} else {
console.info("[NFC_test]mifareUltralight4 = null & = undefined: ");
expect(true).assertFalse();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0500
* @tc.name getMifareUltralight
* @tc.desc Test getMifareUltralight api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_mifareUltralight_0500', 0, function () {
if (MifareUltralightTag != null && MifareUltralightTag != undefined) {
try {
let nfcMifareUltralightTag = tag.getMifareUltralight("test");
console.info("[NFC_test]mifareUltralight5 getMifareUl: " + nfcMifareUltralightTag);
} catch (error) {
console.info("[NFC_test]mifareUltralight5 getMifareUl errorcode: " + error.code);
expect(401).assertEqual(error.code)
}
} else {
console.info("[NFC_test]mifareUltralight5 = null & = undefined: ");
expect(true).assertFalse();
}
})
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,
"supportedProfiles": 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,
};
let Want = {
"uid" : '01020304',
"technology" : [1],
"tagRfDiscId" :1,
"Sak": 0x08,
"Atqa": "B000",
}
export default function nfcTagABFVErrorTest() {
describe('nfcTagABFVErrorTest', function () {
beforeAll(function () {
console.info('beforeAll called')
})
beforeEach(function() {
console.info('beforeEach called')
})
afterEach(function () {
console.info('afterEach called')
})
afterAll(function () {
console.info('afterAll called')
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0100
* @tc.name Test getTagInfo
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_0100', 0, function () {
let TagInfo ;
try{
TagInfo = tag.getTagInfo("test");
console.info('[NFC_test]TagABFV1 TagInfo:' + TagInfo)
expect(TagInfo instanceof Object).assertTrue();
}catch(error){
console.info('[NFC_test]TagABFV1 TagInfo errorcode:' + error.code)
expect(401).assertEqual(error.code);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0200
* @tc.name Test getNfcA
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_0200', 0, function () {
let TagInfo ;
try{
TagInfo = tag.getNfcA("test");
console.info('[NFC_test]TagABFV2 getNfcAtag:' + TagInfo)
expect(TagInfo instanceof Object).assertTrue();
}catch(error){
console.info('[NFC_test]TagABFV2 getNfcAtag errorcode:' + error.code)
expect(401).assertEqual(error.code);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0300
* @tc.name Test getNfcB
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_0300', 0, function () {
let TagInfo ;
try{
TagInfo = tag.getNfcB("test");
console.info('[NFC_test]TagABFV3 getNfcBtag:' + TagInfo)
expect(TagInfo instanceof Object).assertTrue();
}catch(error){
console.info('[NFC_test]TagABFV3 getNfcBtag errorcode:' + error.code)
expect(401).assertEqual(error.code);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0400
* @tc.name Test getNfcF
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_0400', 0, function () {
let TagInfo ;
try{
TagInfo = tag.getNfcF("test");
console.info('[NFC_test]TagABFV4 getNfcFtag:' + TagInfo)
expect(TagInfo instanceof Object).assertTrue();
}catch(error){
console.info('[NFC_test]TagABFV4 getNfcFtag errorcode:' + error.code)
expect(401).assertEqual(error.code);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0500
* @tc.name Test getNfcV
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_0500', 0, function () {
let TagInfo ;
try{
TagInfo = tag.getNfcV("test");
console.info('[NFC_test]TagABFV5 getNfcVtag:' + TagInfo)
expect(TagInfo instanceof Object).assertTrue();
}catch(error){
console.info('[NFC_test]TagABFV5 getNfcVtag errorcode:' + error.code)
expect(401).assertEqual(error.code);
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
{
"string": [
{
"name": "app_name",
"value": "OsAccountTest"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
/*
* 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifiMg from '@ohos.wifiManager'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("[wifi_test]wifi status:" + wifiMg.isWifiActive());
}
export default function actsWifiManagerEventTest() {
describe('actsWifiManagerEventTest', function () {
beforeEach(function () {
console.info("[wifi_test]beforeEach start" );
checkWifiPowerOn();
})
afterEach(async function () {
console.info("[wifi_test]afterEach start" );
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0008', 0, async function (done) {
let p2pState = "p2pStateChange";
let p2pStateChangeCallback = result => {
console.info("[wifi_test]p2pStateChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pState, p2pStateChangeCallback);
await sleep(3000);
wifiMg.off(p2pState, p2pStateChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0009', 0, async function (done) {
let p2pConnectionState = "p2pConnectionChange";
let p2pConnectionChangeCallback = result => {
console.info("[wifi_test]p2pConnectionChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pConnectionState, p2pConnectionChangeCallback);
let p2pConnectState = {
DISCONNECTED :0,
CONNECTED : 1,
};
let wifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ456",
goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO,
};
let connectResult = wifiMg.p2pConnect(wifiP2PConfig);
await wifiMg.getP2pLinkedInfo()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test]getP2pLinkedInfo promise result : " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
done()
});
await sleep(2000);
wifiMg.off(p2pConnectionState, p2pConnectionChangeCallback);
let removeGroupResult = wifiMg.removeGroup();
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0012', 0, async function (done) {
let p2pDeviceState = "p2pDeviceChange";
let p2pDeviceChangeCallback = result => {
console.info("[wifi_test]p2pDeviceChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pDeviceState, p2pDeviceChangeCallback);
await sleep(3000);
wifiMg.off(p2pDeviceState, p2pDeviceChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0010', 0, async function (done) {
let p2pPeerDeviceState = "p2pPeerDeviceChange";
let p2pPeerDeviceChangeCallback = result => {
console.info("[wifi_test]p2pPeerDeviceChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
let startDiscover = wifiMg.startDiscoverDevices();
await sleep(3000);
let stopDiscover = wifiMg.stopDiscoverDevices();
wifiMg.off(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0013', 0, async function (done) {
let p2pGroupState = "p2pPersistentGroupChange";
let p2pPersistentGroupChangeCallback = () => {
console.info("[wifi_test]p2pPersistentGroupChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pGroupState, p2pPersistentGroupChangeCallback);
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -2,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO,
};
let createGroupResult = wifiMg.createGroup(WifiP2PConfig);
await (2000);
await wifiMg.getCurrentGroup()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test] getCurrentGroup promise result -> " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
});
wifiMg.off(p2pGroupState, p2pPersistentGroupChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0011', 0, async function (done) {
let p2pPeerDeviceState = "p2pDiscoveryChange";
let p2pDiscoveryChangeCallback = result => {
console.info("[wifi_test]p2pDiscoveryChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
let startDiscover = wifiMg.startDiscoverDevices();
await sleep(3000);
let stopDiscover = wifiMg.stopDiscoverDevices();
wifiMg.off(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
done();
})
console.log("*************[wifi_test] start wifi 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifiMg from '@ohos.wifiManager'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("[wifi_test]wifi status:" + wifiMg.isWifiActive());
}
export default function actsWifiManagerEventTest() {
describe('actsWifiManagerEventTest', function () {
beforeEach(function () {
console.info("[wifi_test]beforeEach start" );
checkWifiPowerOn();
})
afterEach(async function () {
console.info("[wifi_test]afterEach start" );
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0008', 0, async function (done) {
let p2pState = "p2pStateChange";
let p2pStateChangeCallback = result => {
console.info("[wifi_test]p2pStateChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pState, p2pStateChangeCallback);
await sleep(3000);
wifiMg.off(p2pState, p2pStateChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0009', 0, async function (done) {
let p2pConnectionState = "p2pConnectionChange";
let p2pConnectionChangeCallback = result => {
console.info("[wifi_test]p2pConnectionChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pConnectionState, p2pConnectionChangeCallback);
let p2pConnectState = {
DISCONNECTED :0,
CONNECTED : 1,
};
let wifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ456",
goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO,
};
let connectResult = wifiMg.p2pConnect(wifiP2PConfig);
await wifiMg.getP2pLinkedInfo()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test]getP2pLinkedInfo promise result : " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
done()
});
await sleep(2000);
wifiMg.off(p2pConnectionState, p2pConnectionChangeCallback);
let removeGroupResult = wifiMg.removeGroup();
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0012', 0, async function (done) {
let p2pDeviceState = "p2pDeviceChange";
let p2pDeviceChangeCallback = result => {
console.info("[wifi_test]p2pDeviceChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pDeviceState, p2pDeviceChangeCallback);
await sleep(3000);
wifiMg.off(p2pDeviceState, p2pDeviceChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0010', 0, async function (done) {
let p2pPeerDeviceState = "p2pPeerDeviceChange";
let p2pPeerDeviceChangeCallback = result => {
console.info("[wifi_test]p2pPeerDeviceChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
let startDiscover = wifiMg.startDiscoverDevices();
await sleep(3000);
let stopDiscover = wifiMg.stopDiscoverDevices();
wifiMg.off(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0013', 0, async function (done) {
let p2pGroupState = "p2pPersistentGroupChange";
let p2pPersistentGroupChangeCallback = () => {
console.info("[wifi_test]p2pPersistentGroupChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pGroupState, p2pPersistentGroupChangeCallback);
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -2,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : wifiMg.GroupOwnerBand.GO_BAND_AUTO,
};
let createGroupResult = wifiMg.createGroup(WifiP2PConfig);
await (2000);
try {
await wifiMg.getCurrentP2pGroup()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test] getCurrentP2pGroup promise result -> " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
}).catch((error) => {
console.error('[wifi_test] getCurrentP2pGroup promise failed :' + JSON.stringify(error));
expect(true).assertEqual(error !=null);
});
}catch(error){
console.info("[wifi_test]getCurrentP2pGroup promise error: " + JSON.stringify(error.message));
expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
}
wifiMg.off(p2pGroupState, p2pPersistentGroupChangeCallback);
done();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('SUB_Communication_WiFi_Event_Test_0011', 0, async function (done) {
let p2pPeerDeviceState = "p2pDiscoveryChange";
let p2pDiscoveryChangeCallback = result => {
console.info("[wifi_test]p2pDiscoveryChange callback, result: " + JSON.stringify(result));
}
wifiMg.on(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
let startDiscover = wifiMg.startDiscoverDevices();
await sleep(3000);
let stopDiscover = wifiMg.stopDiscoverDevices();
wifiMg.off(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
done();
})
console.log("*************[wifi_test] start wifi 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("[wifi_test]wifi status:" + wifi.isWifiActive());
}
export default function actsWifiEventTest() {
describe('actsWifiEventTest', function () {
beforeEach(function () {
console.info("[wifi_test]beforeEach start" );
checkWifiPowerOn();
})
afterEach(async function () {
console.info("[wifi_test]afterEach start" );
})
/**
* @tc.number Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0008', 0, async function (done) {
let p2pState = "p2pStateChange";
let p2pStateChangeCallback = result => {
console.info("[wifi_test]p2pStateChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pState, p2pStateChangeCallback);
await sleep(3000);
wifi.off(p2pState, p2pStateChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0009', 0, async function (done) {
let p2pConnectionState = "p2pConnectionChange";
let p2pConnectionChangeCallback = result => {
console.info("[wifi_test]p2pConnectionChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pConnectionState, p2pConnectionChangeCallback);
let wifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ456",
goBand : wifi.GroupOwnerBand.GO_BAND_AUTO
};
let connectResult = wifi.p2pConnect(wifiP2PConfig);
console.info("[wifi_test]test p2pConnect result." + connectResult);
await wifi.getP2pLinkedInfo()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test]getP2pLinkedInfo promise result : " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
done()
});
await sleep(2000);
wifi.off(p2pConnectionState, p2pConnectionChangeCallback);
let removeGroupResult = wifi.removeGroup();
console.info("[wifi_test]test start removeGroup:" + removeGroupResult);
expect(removeGroupResult).assertTrue();
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0012', 0, async function (done) {
let p2pDeviceState = "p2pDeviceChange";
let p2pDeviceChangeCallback = result => {
console.info("[wifi_test]p2pDeviceChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pDeviceState, p2pDeviceChangeCallback);
await sleep(3000);
wifi.off(p2pDeviceState, p2pDeviceChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0010', 0, async function (done) {
let p2pPeerDeviceState = "p2pPeerDeviceChange";
let p2pPeerDeviceChangeCallback = result => {
console.info("[wifi_test]p2pPeerDeviceChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
let startDiscover = wifi.startDiscoverDevices();
await sleep(3000);
expect(startDiscover).assertTrue();
let stopDiscover = wifi.stopDiscoverDevices();
console.info("[wifi_test] test stopDiscoverDevices result." + stopDiscover);
wifi.off(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0013', 0, async function (done) {
let p2pGroupState = "p2pPersistentGroupChange";
let p2pPersistentGroupChangeCallback = () => {
console.info("[wifi_test]p2pPersistentGroupChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pGroupState, p2pPersistentGroupChangeCallback);
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -2,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : wifi.GroupOwnerBand.GO_BAND_AUTO,
};
let createGroupResult = wifi.createGroup(WifiP2PConfig);
await (2000);
console.info("[wifi_test] test createGroup result." + createGroupResult)
expect(createGroupResult).assertTrue();
await wifi.getCurrentGroup()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test] getCurrentGroup promise result -> " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
});
wifi.off(p2pGroupState, p2pPersistentGroupChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0011', 0, async function (done) {
let p2pPeerDeviceState = "p2pDiscoveryChange";
let p2pDiscoveryChangeCallback = result => {
console.info("[wifi_test]p2pDiscoveryChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
let startDiscover = wifi.startDiscoverDevices();
await sleep(3000);
expect(startDiscover).assertTrue();
let stopDiscover = wifi.stopDiscoverDevices();
console.info("[wifi_test] test stopDiscoverDevices result." + stopDiscover);
wifi.off(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
done();
})
console.log("*************[wifi_test] start wifi 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import wifi from '@ohos.wifi'
function sleep(delay) {
return new Promise(resovle => setTimeout(resovle, delay))
}
function checkWifiPowerOn(){
console.info("[wifi_test]wifi status:" + wifi.isWifiActive());
}
export default function actsWifiEventTest() {
describe('actsWifiEventTest', function () {
beforeEach(function () {
console.info("[wifi_test]beforeEach start" );
checkWifiPowerOn();
})
afterEach(async function () {
console.info("[wifi_test]afterEach start" );
})
/**
* @tc.number Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0008', 0, async function (done) {
let p2pState = "p2pStateChange";
let p2pStateChangeCallback = result => {
console.info("[wifi_test]p2pStateChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pState, p2pStateChangeCallback);
await sleep(3000);
wifi.off(p2pState, p2pStateChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0009', 0, async function (done) {
let p2pConnectionState = "p2pConnectionChange";
let p2pConnectionChangeCallback = result => {
console.info("[wifi_test]p2pConnectionChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pConnectionState, p2pConnectionChangeCallback);
let wifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -1,
passphrase : "12345678",
groupName : "AAAZZZ456",
goBand : wifi.GroupOwnerBand.GO_BAND_AUTO
};
let connectResult = wifi.p2pConnect(wifiP2PConfig);
console.info("[wifi_test]test p2pConnect result." + connectResult);
await wifi.getP2pLinkedInfo()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test]getP2pLinkedInfo promise result : " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
done()
});
await sleep(2000);
wifi.off(p2pConnectionState, p2pConnectionChangeCallback);
let removeGroupResult = wifi.removeGroup();
console.info("[wifi_test]test start removeGroup:" + removeGroupResult);
expect(removeGroupResult).assertTrue();
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0012', 0, async function (done) {
let p2pDeviceState = "p2pDeviceChange";
let p2pDeviceChangeCallback = result => {
console.info("[wifi_test]p2pDeviceChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pDeviceState, p2pDeviceChangeCallback);
await sleep(3000);
wifi.off(p2pDeviceState, p2pDeviceChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0010', 0, async function (done) {
let p2pPeerDeviceState = "p2pPeerDeviceChange";
let p2pPeerDeviceChangeCallback = result => {
console.info("[wifi_test]p2pPeerDeviceChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
let startDiscover = wifi.startDiscoverDevices();
await sleep(3000);
expect(startDiscover).assertTrue();
let stopDiscover = wifi.stopDiscoverDevices();
console.info("[wifi_test] test stopDiscoverDevices result." + stopDiscover);
wifi.off(p2pPeerDeviceState, p2pPeerDeviceChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0013', 0, async function (done) {
let p2pGroupState = "p2pPersistentGroupChange";
let p2pPersistentGroupChangeCallback = () => {
console.info("[wifi_test]p2pPersistentGroupChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pGroupState, p2pPersistentGroupChangeCallback);
let WifiP2PConfig = {
deviceAddress : "00:00:00:00:00:00",
netId : -2,
passphrase : "12345678",
groupName : "AAAZZZ123",
goBand : wifi.GroupOwnerBand.GO_BAND_AUTO,
};
let createGroupResult = wifi.createGroup(WifiP2PConfig);
await (2000);
console.info("[wifi_test] test createGroup result." + createGroupResult)
expect(createGroupResult).assertTrue();
try {
await wifi.getCurrentGroup()
.then(data => {
let resultLength = Object.keys(data).length;
console.info("[wifi_test] getCurrentGroup promise result -> " + JSON.stringify(data));
expect(true).assertEqual(resultLength!=0);
}).catch((error) => {
console.error('[wifi_test] getCurrentGroup promise failed :' + JSON.stringify(error));
expect(true).assertEqual(error !=null);
});
}catch(error){
console.info("[wifi_test]getCurrentGroup promise error: " + JSON.stringify(error.message));
expect(true).assertEqual( (JSON.stringify(error.message)) !=null);
}
wifi.off(p2pGroupState, p2pPersistentGroupChangeCallback);
done();
})
/**
* @tc.number Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it('Communication_WiFi_Event_Test_0011', 0, async function (done) {
let p2pPeerDeviceState = "p2pDiscoveryChange";
let p2pDiscoveryChangeCallback = result => {
console.info("[wifi_test]p2pDiscoveryChange callback, result: " + JSON.stringify(result));
}
wifi.on(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
let startDiscover = wifi.startDiscoverDevices();
await sleep(3000);
expect(startDiscover).assertTrue();
let stopDiscover = wifi.stopDiscoverDevices();
console.info("[wifi_test] test stopDiscoverDevices result." + stopDiscover);
wifi.off(p2pPeerDeviceState, p2pDiscoveryChangeCallback);
done();
})
console.log("*************[wifi_test] start wifi js unit test end*************");
})
}
......@@ -105,10 +105,9 @@ export default function geolocationTest_4() {
console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result));
console.info("[lbs_js] country :" + result.country);
console.info("[lbs_js] type: " + result.type);
expect(true).assertEqual(JSON.stringify(result.type)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_SIM);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK);
expect(true).assertEqual(result!=null);
expect(true).assertEqual(JSON.stringify(result.country)!=null);
expect(true).assertEqual(JSON.stringify(result.type)!=null);
}).catch((error) => {
console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error));
expect().assertFail();
......
......@@ -104,10 +104,9 @@ export default function geolocationTest_6() {
console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result));
console.info("[lbs_js] country :" + result.country);
console.info("[lbs_js] type: " + result.type);
expect(true).assertEqual(JSON.stringify(result.type)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_SIM);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION);
expect(true).assertEqual(JSON.stringify(result.type)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK);
expect(true).assertEqual(result!=null);
expect(true).assertEqual(JSON.stringify(result.country)!=null);
expect(true).assertEqual(JSON.stringify(result.type)!=null);
}).catch((error) => {
console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error));
expect().assertFail();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册