提交 f60494fc 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 ac446cc9
...@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() { ...@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() {
beforeAll(function () { beforeAll(function () {
console.info('beforeAll called') console.info('beforeAll called')
gattServer = bluetooth.BLE.createGattServer(); gattServer = bluetooth.BLE.createGattServer();
gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); gattClient = bluetooth.BLE.createGattClientDevice("92:3A:C0:3A:4C:28");
}) })
beforeEach(async function(done) { beforeEach(async function(done) {
console.info('beforeEach called') console.info('beforeEach called')
...@@ -300,8 +300,8 @@ describe('btManagerGattManagerTest', function() { ...@@ -300,8 +300,8 @@ describe('btManagerGattManagerTest', function() {
it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0200', 0, async function (done) { it('SUB_COMMUNICATION_BTMANAGER_GETSERVICE_0200', 0, async function (done) {
try { try {
gattClient.getServices((code, data)=> { gattClient.getServices((code, data)=> {
if(code.code==0){ if(code.code == 0) {
console.info("bluetooth services size is ", data.length) console.info("bluetooth services size is ", data.length);
expect(true).assertEqual(data.length >= 0); expect(true).assertEqual(data.length >= 0);
} else { } else {
console.info('[bluetooth_js] get services code ' + JSON.stringify(code)); console.info('[bluetooth_js] get services code ' + JSON.stringify(code));
...@@ -310,11 +310,11 @@ describe('btManagerGattManagerTest', function() { ...@@ -310,11 +310,11 @@ describe('btManagerGattManagerTest', function() {
done(); done();
}); });
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code}, console.error(`[bluetooth_js]GetService_0200 failed, code is ${error.code},message is ${error.message}`);
message is ${error.message}`);
expect(true).assertFalse(); expect(true).assertFalse();
done() done();
} }
done();
}) })
...@@ -467,11 +467,14 @@ describe('btManagerGattManagerTest', function() { ...@@ -467,11 +467,14 @@ describe('btManagerGattManagerTest', function() {
it('SUB_COMMUNICATION_BTMANAGER_READCHARACTERISTIC_2000', 0, async function(done) { it('SUB_COMMUNICATION_BTMANAGER_READCHARACTERISTIC_2000', 0, async function(done) {
try { try {
function readCcc(code, BLECharacteristic) { function readCcc(code, BLECharacteristic) {
console.log('bluetooth characteristic code:'+ code.code);
if (code.code != 0) { if (code.code != 0) {
return; return;
} }
console.log('bluetooth characteristic uuid:'+ BLECharacteristic.characteristicUuid); console.log('bluetooth characteristic serviceUuid:'+ BLECharacteristic.serviceUuid);
expect(true).assertEqual(data==null); console.log('bluetooth characteristic characteristicUuid:'+ BLECharacteristic.characteristicUuid);
console.log('bluetooth characteristic characteristicValue:'+ BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic descriptors:'+ BLECharacteristic.descriptors);
let value = new Uint8Array(BLECharacteristic.characteristicValue); let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: ' console.log('bluetooth characteristic value: '
+ value[0] +','+ value[1]+','+ value[2]+','+ value[3]); + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
...@@ -492,15 +495,13 @@ describe('btManagerGattManagerTest', function() { ...@@ -492,15 +495,13 @@ describe('btManagerGattManagerTest', function() {
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: arrayBufferCCC, descriptors:descriptors}; characteristicValue: arrayBufferCCC, descriptors:descriptors};
gattClient.readCharacteristicValue(characteristic,readCcc); gattClient.readCharacteristicValue(characteristic,readCcc);
expect(true).assertFalse(); done();
done()
} catch (error) { } catch (error) {
console.error(`[bluetooth_js]readDescrValue20 failed, code is ${error.code}, console.error(`[bluetooth_js]readDescrValue20 failed, code is ${error.code},message is ${error.message}`);
message is ${error.message}`);
expect(error.code).assertEqual('401'); expect(error.code).assertEqual('401');
done() done();
} }
done();
}) })
/** /**
......
...@@ -323,6 +323,92 @@ export default function nfcIsoDepTagTest() { ...@@ -323,6 +323,92 @@ export default function nfcIsoDepTagTest() {
expect(tag.NDEF_FORMATABLE).assertEqual(7); expect(tag.NDEF_FORMATABLE).assertEqual(7);
}) })
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0900
* @tc.name Test startHCE
* @tc.desc startHCE
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_0900', 0, function () {
let starthce ;
let aidList = "test"
try {
starthce = cardEmulation.startHCE(aidList);
console.info('[NFC_test] cardEmulationnfc9 hasHceCapability type ->' + starthce )
expect(starthce).assertTrue();
} catch (error) {
console.info('[NFC_test] cardEmulationnfc9 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1000
* @tc.name Test start
* @tc.desc start.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1000', 0, function () {
let Start ;
let aidList = "test"
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
try {
Start = cardEmulation.start(elementName, aidList);
console.info('[NFC_test] cardEmulationnfc10 Start pass' )
} catch (error) {
console.info('[NFC_test] cardEmulationnfc10 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1100
* @tc.name Test stopHCE
* @tc.desc stopHCE.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1100', 0, function () {
let stophce ;
try {
stophce = cardEmulation.stopHCE();
console.info('[NFC_test] cardEmulationnfc11 hasHceCapability type ->' + starthce )
expect(starthce).assertTrue();
} catch (error) {
console.info('[NFC_test] cardEmulationnfc11 HCE not delivered')
}
})
/**
* @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1200
* @tc.name Test stop
* @tc.desc stop.
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfccardEmulationnfc_js_1200', 0, function () {
let Stop ;
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
try {
Stop = cardEmulation.stop(elementName);
console.info('[NFC_test] cardEmulationnfc12 stop pass' )
} catch (error) {
console.info('[NFC_test] cardEmulationnfc12 HCE not delivered')
}
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
\ No newline at end of file
...@@ -674,6 +674,38 @@ export default function nfcTagABFVTest() { ...@@ -674,6 +674,38 @@ export default function nfcTagABFVTest() {
} }
}) })
/**
* @tc.number SUB_Communication_NFC_nfctage_js_2300
* @tc.name Test registerForegroundDispatch
* @tc.desc This interface registerForegroundDispatch.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_nfctage_js_2300', 0, function () {
let elementName = {
"bundleName": "com.test.cardemulation",
"abilityName": "MainAbility",
"moduleName": "entry"
};
let discTech = [1, 2, 4];
try {
let recvNfcTagFunc = tagInfo => {
console.info("[NFC_test] controller1 nfc state receive state ->" + tagInfo);
expect(tagInfo != null).assertTrue();
}
tag.registerForegroundDispatch(elementName, discTech, recvNfcTagFunc);
console.info('[NFC_test] nfc registerForegroundDispatch pass')
tag.unregisterForegroundDispatch(elementName);
console.info('[NFC_test] nfc unregisterForegroundDispatch pass')
} catch (error) {
console.info('nfc registerForegroundDispatch error' + error)
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************"); console.info("*************[nfc_test] start nfc js unit test end*************");
}) })
} }
\ No newline at end of file
# Copyright (C) 2023 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("ActsnfcSEServiceTest") {
hap_profile = "./src/main/config.json"
deps = [
":nfc_js_assets",
":nfc_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsnfcSEServiceTest"
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": "180000",
"shell-timeout": "600000",
"testcase-timeout": "600000",
"bundle-name": "ohos.acts.communication.nfc.nfcdevice",
"package-name": "ohos.acts.communication.nfc.nfcdevice"
},
"kits": [
{
"test-file-name": [
"ActsnfcSEServiceTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"svc nfc enable",
"power-shell wakeup",
"power-shell setmode 602"
]
}
]
}
\ No newline at end of file
{
"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) 2023 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) 2023 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) 2023 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) 2023 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) 2023 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) 2023 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) 2023 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.info('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) 2023 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 newSEServicetest from './newSEService.test.js';
import openSessionTest from './openSession.test.js';
import openBasicChanneltest from './openBasicChannel.test.js';
import openLogicalChanneltest from './openLogicalChannel.test.js';
import channelCallbacktest from './channelCallback.test.js';
import parameter from '@ohos.systemparameter';
let info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
export default function testsuite() {
if (info != "false")
{
newSEServicetest();
openSessionTest();
openBasicChanneltest();
openLogicalChanneltest();
channelCallbacktest();
}
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 secureElement from '@ohos.secureElement';
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 nfcSEService = null;
let nfcESEReader = null;
let nfcOmaSession = null;
let nfcOmaReaderList = [];
let aidArray = [160, 0, 0, 1, 81, 0, 0, 0];
let p2 = 0x00;
let command = [128, 202, 159, 127, 0];
export default function channelCallbacktest() {
describe('channelCallbacktest', function () {
beforeAll(function () {
try {
nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[nfc_test] beforeAll Se_channel state is Disconnected");
} else {
console.info("[nfc_test] beforeAll Se_channel state is Connected");
}
expect(state instanceof Object).assertTrue();
console.info("[nfc_test] beforeAll Se_channel state is getReaders" + state);
});
nfcOmaReaderList = nfcSEService.getReaders();
if (nfcOmaReaderList.length === 0) {
console.info("[NFC_test][NFC_test]This function is not supported because the phone NFC chip is ST chip.");
} else {
console.info("[nfc_test] beforeAll Se_channel Result of getReaders:" + nfcOmaReaderList.length);
nfcESEReader = nfcOmaReaderList[0];
console.info("[nfc_test] beforeAll Se_channel getReaders results list 0 is" + nfcESEReader);
nfcOmaSession = nfcESEReader.openSession();
console.info("[nfc_test] beforeAll Se_channel openSession The result is" + nfcOmaSession);
}
} catch (e) {
console.info("[nfc_test] beforeAll Se_channel occurs exception:" + e.message);
}
})
beforeEach(function() {
console.info('beforeEach called');
})
afterEach(function () {
console.info('shutdown success');
})
afterAll(function () {
nfcSEService.shutdown();
console.info('[nfc_test] afterAll channelcallback shutdown success');
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2400
* @tc.name Test isBasicChannel
* @tc.desc open BasicChannel Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2400', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]24 This function is not supported because the phone NFC chip is ST chip.");
} else {
function P2BasicChannel_callback(){
return new Promise((resolve, reject) => {
nfcOmaSession.openBasicChannel(aidArray, p2,
(err, result) => {
if(err) {
console.info("[NFC_test]24 openBasicChannel data == null" + err);
expect().assertFail();
}
console.info("[NFC_test]24 openBasicChannel data != null " + result);
let P2BasicChannel = result;
let isBasic = P2BasicChannel.isBasicChannel();
console.info("[NFC_test]24 Check whether the channel is a basic channel: " + isBasic);
expect(isBasic).assertTrue();
P2BasicChannel.close();
console.info("[NFC_test]24 Data received by the application select command: " );
resolve();
});
});
}
await P2BasicChannel_callback();
}
} catch (error) {
console.info("[NFC_test]24 openBasicChannel_p2_callback occurs exception:" + error);
expect().assertFail();
}
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2500
* @tc.name Test isClosed
* @tc.desc open LogicalChannel Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2500', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]25 This function is not supported because the phone NFC chip is ST chip.");
} else {
function LogicalChannel_callback(){
return new Promise((resolve, reject) => {
nfcOmaSession.openLogicalChannel(aidArray, p2,
(err, result) => {
if(err) {
console.info("[NFC_test]25 openLogicalChannel data == null" + err);
expect().assertFail();
}
console.info("[NFC_test]25 openLogicalChannel data == null" + result);
let P2LogicalChannel = result;
P2LogicalChannel.close();
console.info("[NFC_test]25 Data received by the application select command: " );
let isChannelClosed = P2LogicalChannel.isClosed();
console.info("[NFC_test]25 Check whether the channel is closed: " + isChannelClosed);
expect(isChannelClosed).assertTrue();
resolve();
});
});
}
await LogicalChannel_callback();
}
} catch (error) {
console.info("[NFC_test]25 openLogicalChannel_P2_callback occurs exception:" + error);
expect().assertFail();
}
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2600
* @tc.name Test getSelectResponse
* @tc.desc open BasicChannel Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2600', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]26 This function is not supported because the phone NFC chip is ST chip.");
} else {
function BasicChannel_callback(){
return new Promise((resolve, reject) => {
nfcOmaSession.openBasicChannel(aidArray,
(err, result) => {
if(err) {
console.info("[NFC_test]26 to get openBasicChannel:" + JSON.stringify(err));
expect().assertFail();
}
console.info("[NFC_test]26 openBasicChannel data != null " + result);
let nfcBasicChannel = result;
let getResponse = nfcBasicChannel.getSelectResponse();
console.info("[NFC_test]26 getSelectResponse data: " + getResponse);
nfcBasicChannel.close();
console.info("[NFC_test]26 Data received by the application select command: " );
expect(getResponse).assertInstanceOf('Array');
resolve();
});
});
}
await BasicChannel_callback();
}
} catch (error) {
console.info("[NFC_test]26 openBasicChannel_callback occurs exception:" + error);
expect().assertFail();
}
sleep(5000);
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2700
* @tc.name Test transmit
* @tc.desc open LogicalChannel Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2700', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]27 This function is not supported because the phone NFC chip is ST chip.");
} else {
function LogicalChannel_callback(){
return new Promise((resolve, reject) => {
nfcOmaSession.openLogicalChannel(aidArray,
(err, result) => {
if(err) {
console.info("[NFC_test]27 failed to get openLogicalChannel:" + JSON.stringify(err));
expect().assertFail();
}
console.info("[NFC_test]27 openLogicalChannel data != null " + result);
let nfcLogicalChannel = result;
nfcLogicalChannel.transmit(command, (err, data) => {
if (err) {
console.info("[NFC_test]27 Send error an APDU command to the SE: " + err);
expect().assertFail();
} else {
console.info("[NFC_test]27 Send an APDU command to the SE: " + data);
expect(data).assertInstanceOf('Array');
}
});
sleep(5000);
nfcLogicalChannel.close();
console.info("[NFC_test]27 Data received by the application select command: " );
resolve();
});
});
}
await LogicalChannel_callback();
}
} catch (error) {
console.info("[NFC_test]27 openLogicalChannel_callback occurs exception:" + error);
expect().assertFail();
}
sleep(3000);
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2800
* @tc.name Test transmit
* @tc.desc open LogicalChannel Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2800', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]28 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getPromise = nfcOmaSession.openBasicChannel(aidArray);
await getPromise.then((data) => {
console.info("[NFC_test]28 openBasicChannel openBasicChannel data: " + data);
if ( data != undefined && data != null){
console.info("[NFC_test]28 openBasicChannel data != null");
let OmaBasicChannel = data;
OmaBasicChannel.close();
console.info("[NFC_test]28 Data received by the application select command: " );
}
else {
console.info("[NFC_test]28 openBasicChannel data == null");
}
});
sleep(5000);
}
} catch (error) {
console.info("[NFC_test]28 openBasicChannel_Promise occurs exception:" + error);
expect().assertFail();
}
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2900
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2900', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]29 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getPromise = nfcOmaSession.openLogicalChannel(aidArray);
await getPromise.then((data) => {
console.info("[NFC_test]29 openLogicalChannel data: " + data);
if ( data != undefined && data != null){
console.info("[NFC_test]29 openLogicalChannel data != null");
let OmaLogicalChannel = data;
let isChannelClosed = OmaLogicalChannel.isClosed();
console.info("[NFC_test]29 Check whether the channel is disabled: " + isChannelClosed);
expect(isChannelClosed).assertFalse();
}
else {
console.info("[NFC_test]29 openLogicalChannel data == null");
}
});
sleep(5000);
}
} catch (error) {
console.info("[NFC_test]29 openLogicalChannel_Promise occurs exception:" + error);
expect().assertFail();
}
done();
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 secureElement from '@ohos.secureElement';
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 nfcSEService = null;
export default function newSEServicetest() {
describe('newSEServicetest', function () {
beforeAll(function () {
try {
nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[nfc_test] beforeAll newService state is Disconnected");
} else {
console.info("[nfc_test] beforeAll newService state is Connected");
}
expect(state instanceof Object).assertTrue();
console.info("[nfc_test] beforeAll newService state is " + state);
});
} catch (e) {
console.info("[nfc_test] beforeAll newService occurs exception:" + e.message);
}
})
beforeEach(function() {
console.info('beforeEach called');
})
afterEach(function () {
console.info('afterEach called');
})
afterAll(function () {
nfcSEService.shutdown();
console.info('[nfc_test] afterAll newService shutdown success');
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0100
* @tc.name Test isConnected
* @tc.desc Check whether the SE service is connected.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0100', 0, function () {
try {
let nfcisConnected = nfcSEService.isConnected();
console.info("[NFC_test]1 SEService The connection status is: " + nfcisConnected);
expect(nfcisConnected).assertTrue();
} catch (error) {
console.info("[NFC_test]1 exception occurred when checking the connection status.:" + error)
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0200
* @tc.name Test getVersion
* @tc.desc Returns the version number of the OMA specification.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0200', 0, function () {
try {
let getSEVersion = nfcSEService.getVersion();
console.info("[NFC_test]2 OMA The version number is: " + getSEVersion);
expect(typeof (getSEVersion)).assertEqual('string');
} catch (error) {
console.info("[NFC_test]2 Failed to obtain the version.:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0300
* @tc.name Test getName
* @tc.desc Returns the name of this reader.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0300', 0, function () {
try {
let nfcOmaReaderList = nfcSEService.getReaders();
console.info("[nfc_test]3 Result of getReaders:" + nfcOmaReaderList );
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]3 This function is not supported because the phone NFC chip is ST chip.");
} else {
expect(nfcOmaReaderList instanceof Object).assertTrue();
let nfcESEReader = nfcOmaReaderList[0];
console.info("[nfc_test]3 getReaders results list 0 is" + nfcESEReader);
expect(nfcESEReader instanceof Object).assertTrue();
let getNfcname = nfcESEReader.getName();
console.info("[NFC_test]3 The reader name is: " + getNfcname);
expect(typeof (getNfcname)).assertEqual('string');
}
} catch (error) {
console.info("[NFC_test]3 getName occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0400
* @tc.name Test isSecureElementPresent
* @tc.desc Indicates whether the corresponding secure element is available.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0400', 0, function () {
try {
let nfcOmaReaderList2 = [];
nfcOmaReaderList2 = nfcSEService.getReaders();
if (nfcOmaReaderList2 == undefined) {
console.info("[NFC_test]4 This function is not supported because the phone NFC chip is ST chip.");
} else {
console.info("[nfc_test]4 Result of getReaders:" + nfcOmaReaderList2);
expect(nfcOmaReaderList2 instanceof Object).assertTrue();
let nfcESEReader2 = nfcOmaReaderList2[0];
console.info("[nfc_test]4 getReaders results list 0 is" + nfcESEReader2);
expect(nfcESEReader2 instanceof Object).assertTrue();
let nfcSePresent = nfcESEReader2.isSecureElementPresent();
console.info("[NFC_test]4 security unit check result is: " + nfcSePresent);
expect(nfcSePresent).assertTrue();
}
} catch (error) {
console.info("[NFC_test]4 isSecureElementPresent occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0500
* @tc.name Test shutdown
* @tc.desc Release all SE resources allocated to the service.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0500', 0, function () {
try {
nfcSEService.shutdown();
console.info('[NFC_test] 05 eseshutdown pass');
let downESEisconnected = nfcSEService.isConnected();
console.info("[NFC_test]5 shutdown the SE SEService The connection status is: " + downESEisconnected);
expect(downESEisconnected).assertFalse();
sleep(5000);
let SEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[nfc_test]5 Service state is Disconnected");
} else {
console.info("[nfc_test]5 Service state is Connected");
}
console.info("[nfc_test]5 Service state is" + state);
});
expect(SEService instanceof Object).assertTrue();
let openESEisconnected = nfcSEService.isConnected();
console.info("[NFC_test]5 SEService The connection status is:: " + openESEisconnected);
expect(openESEisconnected).assertTrue();
let nfcReadersList = SEService.getReaders();
if (nfcReadersList == undefined) {
console.info("[NFC_test]5 This function is not supported because the phone NFC chip is ST chip.");
} else {
expect(nfcReadersList instanceof Object).assertTrue();
console.info("[nfc_test]5 Result of getReaders:" + nfcReadersList);
}
} catch (error) {
console.info("[NFC_test]5 getReaders occurs exception:" + error);
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 secureElement from '@ohos.secureElement';
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 nfcSEService = null;
let nfcESEReader = null;
let nfcOmaSession = null;
let nfcOmaChannel = null;
let nfcOmaReaderList = [];
let aidArray = [160, 0, 0, 1, 81, 0, 0, 0];
let p2 = 0x00;
let command = [128, 202, 159, 127, 0];
export default function openBasicChanneltest() {
describe('openBasicChanneltest', function () {
beforeAll(async function (done) {
try {
nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[NFC_test] beforeAll se_basic Opened successfully");
} else {
console.info("[NFC_test] beforeAll se_basic Failed to open");
}
expect(state instanceof Object).assertTrue();
});
nfcOmaReaderList = nfcSEService.getReaders();
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]This function is not supported because the phone NFC chip is ST chip.");
} else {
console.info("[nfc_test] beforeAll se_basic Result of getReaders:" + nfcOmaReaderList.length);
nfcESEReader = nfcOmaReaderList[0];
console.info("[nfc_test] beforeAll se_basic getReaders results list 0 is" + nfcESEReader);
nfcOmaSession = nfcESEReader.openSession();
console.info("[nfc_test] beforeAll se_basic openSession The result is" + nfcOmaSession);
let getPromise = nfcOmaSession.openBasicChannel(aidArray, p2);
await getPromise.then((data) => {
console.info("[NFC_test] beforeAll se_basic openBasicChannel data: " + data);
return nfcOmaChannel = data;
// if ( data != undefined && data != null){
// console.info("[NFC_test] beforeAll se_basic openBasicChannel data != null" + nfcOmaChannel);
// return nfcOmaChannel = data;
// }
// else {
// console.info("[NFC_test] beforeAll se_basic openBasicChannel data == null");
// }
})
sleep(5000);
}
} catch (e) {
console.info("[NFC_test] beforeAll se_basic occurs exception:" + e.message);
expect().assertFail();
}
done();
console.info('beforeAll called');
})
beforeEach(function() {
console.info('beforeEach called');
})
afterEach(function () {
console.info('afterEach called');
})
afterAll(function () {
nfcSEService.shutdown();
console.info('shutdown success');
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1000
* @tc.name Test isBasicChannel
* @tc.desc Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1000', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]10 This function is not supported because the phone NFC chip is ST chip.");
} else {
let isBasic = nfcOmaChannel.isBasicChannel();
console.info("[NFC_test]10 Check whether the channel is a basic channel: " + isBasic);
expect(isBasic).assertTrue();
}
} catch (error) {
console.info("[NFC_test]10 isBasicChannel occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1100
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1100', 0, async function ( ) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]11 This function is not supported because the phone NFC chip is ST chip.");;
} else {
let isChannelClosed = nfcOmaChannel.isClosed();
console.info("[NFC_test]11 Check whether the channel is closed: " + isChannelClosed);
expect(isChannelClosed).assertFalse();
}
} catch (error) {
console.info("[NFC_test]11 isClosed occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1200
* @tc.name Test getSelectResponse
* @tc.desc Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1200', 0, async function ( ) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]12 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getResponse = nfcOmaChannel.getSelectResponse();
console.info("[NFC_test]12 Data received by the application select command: " + getResponse);
expect(getResponse).assertInstanceOf('Array');
}
} catch (error) {
console.info("[NFC_test]12 getSelectResponse occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1300
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1300', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]13 This function is not supported because the phone NFC chip is ST chip.");
} else {
nfcOmaChannel.transmit(command, (err, data) => {
if (err) {
console.info("[NFC_test]13 Send error an APDU command to the SE: " + err);
expect().assertFail();
} else {
console.info("[NFC_test]13 Send an APDU command to the SE: " + data);
expect(data).assertInstanceOf('Array')
}
});
}
} catch (error) {
console.info("[NFC_test]13 exception when sending the APDU command to the SE:" + error);
expect().assertFail();
}
sleep(5000);
done();
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1400
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1400', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]14 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getPromise = nfcOmaChannel.transmit(command);
await getPromise.then((data) => {
console.info("[NFC_test]14 Send an APDU command to the SE:" + data);
expect(data).assertInstanceOf('Array');
}).catch((err)=> {
console.info("[NFC_test]14 Send error an APDU command to the SE:: " + err);
expect().assertFail();
});
}
} catch (error) {
console.info("[NFC_test]14 exception when sending the APDU command to the SE:" + error);
expect().assertFail();
}
done();
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1500
* @tc.name Test close
* @tc.desc Obtains the session object that opens the channel.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1500', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]15 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getchannelSession = nfcOmaChannel.getSession();
expect(getchannelSession instanceof Object).assertTrue();
console.info("[NFC_test] 15 getSession data: " + getchannelSession);
}
} catch (error) {
console.info("[NFC_test]15 getSession occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1600
* @tc.name Test close
* @tc.desc Close the channel with the SE.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_BasicChannel_js_1600', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]16 This function is not supported because the phone NFC chip is ST chip.");
} else {
nfcOmaChannel.close();
console.info("[NFC_test] 1600 The closeChannel test is successfully" );
let isChannelClosed = nfcOmaChannel.isClosed();
console.info("[NFC_test]16 Check whether the channel is disabled: " + isChannelClosed);
expect(isChannelClosed).assertTrue();
}
} catch (error) {
console.info("[NFC_test]16 close and isclosed occurs exception:" + error);
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 secureElement from '@ohos.secureElement';
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 nfcSEService = null;
let nfcESEReader = null;
let nfcOmaSession = null;
let nfcOmaChannel = null;
let nfcOmaReaderList = [];
let aidArray = [160, 0, 0, 1, 81, 0, 0, 0];
let p2 = 0x00;
let command = [128, 202, 159, 127, 0];
export default function openLogicalChanneltest() {
describe('openLogicalChanneltest', function () {
beforeAll(async function (done) {
try {
nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[NFC_test] se_Logical Opened successfully");
} else {
console.info("[NFC_test] se_Logical Failed to open");
}
expect(state instanceof Object).assertTrue();
});
nfcOmaReaderList = nfcSEService.getReaders();
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]This function is not supported because the phone NFC chip is ST chip.");
} else {
console.info("[nfc_test] beforeAll se_Logical Result of getReaders:" + nfcOmaReaderList.length);
nfcESEReader = nfcOmaReaderList[0];
console.info("[nfc_test] beforeAll se_Logical getReaders results list 0 is" + nfcESEReader);
nfcOmaSession = nfcESEReader.openSession();
console.info("[nfc_test] beforeAll se_Logical openSession The result is" + nfcOmaSession);
let getPromise = nfcOmaSession.openLogicalChannel(aidArray, p2);
await getPromise.then((data) => {
console.info("[NFC_test] beforeAll se_Logical openLogicalChannel data: " + data);
return nfcOmaChannel = data;
// if ( data != undefined && data != null){
// console.info("[NFC_test] beforeAll se_Logical openLogicalChannel data != null");
// return nfcOmaChannel = data;
// }
// else {
// console.info("[NFC_test] beforeAll se_Logical openLogicalChannel data == null");
// }
})
sleep(5000);
}
} catch (e) {
console.info("[NFC_test] beforeAll se_Logical occurs exception:" + e.message);
expect().assertFail();
}
done();
console.info('beforeAll called');
})
beforeEach(function() {
console.info('beforeEach called');
})
afterEach(function () {
console.info('afterEach called');
})
afterAll(function () {
nfcSEService.shutdown();
console.info('shutdown success');
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1700
* @tc.name Test isBasicChannel
* @tc.desc Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_1700', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]17 This function is not supported because the phone NFC chip is ST chip.");
} else {
let isBasic = nfcOmaChannel.isBasicChannel();
console.info("[NFC_test]17 Check whether the channel is a basic channel: " + isBasic);
expect(isBasic).assertFalse();
}
} catch (error) {
console.info("[NFC_test]17 isBasicChannel occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1800
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_1800', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]18 This function is not supported because the phone NFC chip is ST chip.");
} else {
let isChannelClosed = nfcOmaChannel.isClosed();
console.info("[NFC_test]18 Check whether the channel is closed: " + isChannelClosed);
expect(isChannelClosed).assertFalse();
}
} catch (error) {
console.info("[NFC_test]18 isClosed occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1900
* @tc.name Test getSelectResponse
* @tc.desc Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_1900', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]19 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getResponse = nfcOmaChannel.getSelectResponse();
console.info("[NFC_test]19 Data received by the application select command: " + getResponse);
expect(getResponse).assertInstanceOf('Array');
}
} catch (error) {
console.info("[NFC_test]19 getSelectResponse occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2000
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2000', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]20 This function is not supported because the phone NFC chip is ST chip.");
} else {
nfcOmaChannel.transmit(command, (err, data) => {
if (err) {
console.info("[NFC_test]20 Send error an APDU command to the SE: " + err);
expect().assertFail();
} else {
console.info("[NFC_test]20 Send an APDU command to the SE: " + data);
expect(data).assertInstanceOf('Array');
}
});
}
} catch (error) {
console.info("[NFC_test]19 exception when sending the APDU command to the SE:" + error);
expect().assertFail();
}
sleep(5000);
done();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2100
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2100', 0, async function (done) {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]21 This function is not supported because the phone NFC chip is ST chip.");
done();
} else {
let getPromise = nfcOmaChannel.transmit(command);
await getPromise.then((data) => {
console.info("[NFC_test]21 secureElement transmit data: " + data);
expect(data).assertInstanceOf('Array');
done();
}).catch((err)=> {
console.info("[NFC_test]21 secureElement transmit err: " + err);
expect().assertFail();
done();
});
}
} catch (error) {
console.info("[NFC_test]21 exception when sending the APDU command to the SE:" + error);
expect().assertFail();
done();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2200
* @tc.name Test close
* @tc.desc Obtains the session object that opens the channel.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2200', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]22 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getchannelSession = nfcOmaChannel.getSession();
expect(getchannelSession instanceof Object).assertTrue();
console.info("[NFC_test]22 getSession data: " + getchannelSession);
}
} catch (error) {
console.info("[NFC_test]22 getSession occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2300
* @tc.name Test getNfcATag
* @tc.desc This interface is used to obtain the NFC A tag object.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_Ese_LogicalChannel_js_2300', 0, async function () {
try {
if (nfcOmaReaderList == undefined) {
console.log("[NFC_test]23 This function is not supported because the phone NFC chip is ST chip.");
} else {
nfcOmaChannel.close();
console.info("[NFC_test] 23 The closeChannel test is successfully" );
let isChannelClosed = nfcOmaChannel.isClosed();
console.info("[NFC_test]23 Check whether the channel is disabled: " + isChannelClosed);
expect(isChannelClosed).assertTrue();
}
} catch (error) {
console.info("[NFC_test]23 close and isclosed occurs exception:" + error);
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 secureElement from '@ohos.secureElement';
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 nfcSEService = null;
let nfcESEReader = null;
let nfcOmaSession = null;
let nfcOmaReaderList = [];
export default function openSessionTest() {
describe('openSessionTest', function () {
beforeAll(function () {
try {
nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) {
console.info("[nfc_test] beforeAll Se_session state is Disconnected");
} else {
console.info("[nfc_test] beforeAll Se_session state is Connected");
}
expect(state instanceof Object).assertTrue();
console.info("[nfc_test] beforeAll Se_session state is getReaders" + state);
});
nfcOmaReaderList = nfcSEService.getReaders();
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]This function is not supported because the phone NFC chip is ST chip.");
} else {
console.info("[nfc_test] beforeAll Se_session Result of getReaders:" + nfcOmaReaderList.length);
nfcESEReader = nfcOmaReaderList[0];
console.info("[nfc_test] beforeAll Se_session getReaders results list 0 is" + nfcESEReader);
nfcOmaSession = nfcESEReader.openSession();
console.info("[nfc_test] beforeAll Se_session openSession The result is" + nfcOmaSession);
}
} catch (e) {
console.info("[nfc_test] beforeAll Se_session occurs exception:" + e.message);
}
})
beforeEach(function() {
console.info('beforeEach called');
})
afterEach(function () {
console.info('afterEach called');
})
afterAll(function () {
nfcSEService.shutdown();
console.info('[nfc_test] afterAll Se_session shutdown success');
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0600
* @tc.name Test getReader
* @tc.desc Obtains the reader that provides the session.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0600', 0, async function ( ) {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]6 This function is not supported because the phone NFC chip is ST chip.");
} else {
let getNfcreader = nfcOmaSession.getReader();
console.info("[NFC_test]6 Reader result of this session: " + getNfcreader);
expect(getNfcreader instanceof Object).assertTrue();
}
} catch (error) {
console.info("[NFC_test]6 The reader result of the session is abnormal:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0700
* @tc.name Test getATR
* @tc.desc Obtain the ATR of the SE.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0700', 0, function () {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]7 This function is not supported because the phone NFC chip is ST chip.");
} else {
let nfcGetart = nfcOmaSession.getATR();
expect(nfcGetart).assertInstanceOf('Array');
expect(!nfcGetart == false ).assertTrue();
console.info("[NFC_test]7 Get the ATR of this SE: " + nfcGetart);
}
} catch (error) {
console.info("[NFC_test]7 Get the ATR of this SE occurs exception:" + error);
expect().assertFail();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0800
* @tc.name Test close Session
* @tc.desc Close a single session.
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_Communication_NFC_secureElement_js_0800', 0, function () {
try {
if (nfcOmaReaderList == undefined) {
console.info("[NFC_test]8 This function is not supported because the phone NFC chip is ST chip.");
} else {
let nfcOmaSession2 = nfcESEReader.openSession();
console.info("[nfc_test]8 Open the second session result" + nfcOmaSession2);
expect(nfcOmaSession2 instanceof Object).assertTrue();
let iscloseChannel1 = nfcOmaSession.isClosed();
console.info("[NFC_test]8 Check the first one session is open: " + iscloseChannel1);
expect(iscloseChannel1).assertFalse();
let iscloseChannel2 = nfcOmaSession2.isClosed();
console.info("[NFC_test]8 Check the second session is open: " + iscloseChannel2);
expect(iscloseChannel2).assertFalse();
nfcOmaSession2.close();
console.info("[NFC_test]8 second session is closed successfully");
let opencloseChannel1 = nfcOmaSession.isClosed();
console.info("[NFC_test]8 After close Check the first one session is open: " + opencloseChannel1);
expect(opencloseChannel1).assertFalse();
let opencloseChannel2 = nfcOmaSession2.isClosed();
console.info("[NFC_test]8 After close Check the second session is open: " + opencloseChannel2);
expect(opencloseChannel2).assertTrue();
}
} catch (error) {
console.info("[NFC_test]8 0800 occurs exception:" + error);
expect().assertFail();
}
})
console.info("*************[nfc_test] start nfc js unit test end*************");
})
}
\ No newline at end of file
{
"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
...@@ -113,11 +113,11 @@ export default function geolocationTest_geo5() { ...@@ -113,11 +113,11 @@ export default function geolocationTest_geo5() {
try { try {
let geocoder1 = geolocationm.isGeocoderAvailable(); let geocoder1 = geolocationm.isGeocoderAvailable();
console.info('[lbs_js] isGeocoderAvailable result: ' + JSON.stringify(geocoder1)); console.info('[lbs_js] isGeocoderAvailable result: ' + JSON.stringify(geocoder1));
expect(true).assertEqual(JSON.stringify(geocoder1) != null); expect(geocoder1).assertTrue();
} catch (error) { } catch (error) {
console.info('[lbs_js] isGeocoderAvailable err:' + JSON.stringify(error)); console.info('[lbs_js] isGeocoderAvailable err:' + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual("801"); expect(true).assertFalse();
} }
}); });
...@@ -130,22 +130,23 @@ export default function geolocationTest_geo5() { ...@@ -130,22 +130,23 @@ export default function geolocationTest_geo5() {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_HSS_LocationSystem_Geo_2000', 0, async function (done) { it('SUB_HSS_LocationSystem_Geo_2000', 0, async function (done) {
try {
let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1 }; let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1 };
geolocationm.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geolocationm.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
try {
if (err) { if (err) {
console.info('[lbs_js] getAddressesFromLocation4 callback err is:' + JSON.stringify(err)); console.info('[lbs_js] getAddressesFromLocation4 callback err is:' + JSON.stringify(err));
console.info('[lbs_js] not support now'); expect(err.code).assertEqual(3301300);
expect(err.code).assertEqual(801);
} else { } else {
console.info("[lbs_js] getAddressesFromLocation4 callback data is:" + JSON.stringify(data)); console.info("[lbs_js] getAddressesFromLocation4 callback data is:" + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null); expect(true).assertEqual((JSON.stringify(data)) != null);
} }
}); }
} catch (error) { catch (error) {
console.info("[lbs_js] getAddressesFromLocation4 callback try error:"+ error); console.info("[lbs_js] getAddressesFromLocation4 callback try error:"+ error);
expect(true).assertFalse(); expect(true).assertFalse();
} }
});
await sleep(2000); await sleep(2000);
done(); done();
}) })
...@@ -189,7 +190,7 @@ export default function geolocationTest_geo5() { ...@@ -189,7 +190,7 @@ export default function geolocationTest_geo5() {
}).catch(error => { }).catch(error => {
console.info("[lbs_js] getAddressesFromLocation21 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation21 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation21 try err." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation21 try err." + JSON.stringify(error));
...@@ -216,7 +217,7 @@ export default function geolocationTest_geo5() { ...@@ -216,7 +217,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocation22 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation22 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation22 try err." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation22 try err." + JSON.stringify(error));
...@@ -243,7 +244,7 @@ export default function geolocationTest_geo5() { ...@@ -243,7 +244,7 @@ export default function geolocationTest_geo5() {
}).catch(error => { }).catch(error => {
console.info("[lbs_js] getAddressesFromLocation2301 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation2301 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error));
...@@ -270,7 +271,7 @@ export default function geolocationTest_geo5() { ...@@ -270,7 +271,7 @@ export default function geolocationTest_geo5() {
}).catch(error => { }).catch(error => {
console.info("[lbs_js] getAddressesFromLocation2303 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation2303 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error));
...@@ -310,10 +311,10 @@ export default function geolocationTest_geo5() { ...@@ -310,10 +311,10 @@ export default function geolocationTest_geo5() {
}).catch(error => { }).catch(error => {
console.info("[lbs_js] getAddressesFromLocation2401 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation2401 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message1." + JSON.stringify(error));
expect(true).assertFalse(); expect(true).assertFalse();
} }
await sleep(1000); await sleep(1000);
...@@ -327,8 +328,9 @@ export default function geolocationTest_geo5() { ...@@ -327,8 +328,9 @@ export default function geolocationTest_geo5() {
expect(true).assertFalse(); expect(true).assertFalse();
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message2." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error.message)) != null); // expect(true).assertEqual((JSON.stringify(error.message)) != null);
expect(error.code).assertEqual("401");
} }
await sleep(1000); await sleep(1000);
let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 };
...@@ -339,10 +341,10 @@ export default function geolocationTest_geo5() { ...@@ -339,10 +341,10 @@ export default function geolocationTest_geo5() {
}).catch(error => { }).catch(error => {
console.info("[lbs_js] getAddressesFromLocation2403 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation2403 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301300);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message3." + JSON.stringify(error));
expect(true).assertFalse(); expect(true).assertFalse();
} }
await sleep(1000); await sleep(1000);
...@@ -356,8 +358,9 @@ export default function geolocationTest_geo5() { ...@@ -356,8 +358,9 @@ export default function geolocationTest_geo5() {
expect(true).assertFalse(); expect(true).assertFalse();
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocation message4." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error.message)) != null); // expect(true).assertEqual((JSON.stringify(error.message)) != null);
expect(error.code).assertEqual("401");
} }
await sleep(1000); await sleep(1000);
done(); done();
...@@ -378,8 +381,8 @@ export default function geolocationTest_geo5() { ...@@ -378,8 +381,8 @@ export default function geolocationTest_geo5() {
"maxItems": 1, "maxItems": 1,
"locale": "zh", "locale": "zh",
}; };
try { geolocationm.getAddressesFromLocationName(geocodeRequest, (err, data) => {
geolocationm.getAddressesFromLocationName(geocodeRequest, (err, data) => { try{
if (err) { if (err) {
switch (err) { switch (err) {
case 100: case 100:
...@@ -412,17 +415,19 @@ export default function geolocationTest_geo5() { ...@@ -412,17 +415,19 @@ export default function geolocationTest_geo5() {
default: default:
console.info('getAddressesFromLocationName callback err: ' + JSON.stringify(err)); console.info('getAddressesFromLocationName callback err: ' + JSON.stringify(err));
} }
} else {
console.info("[lbs_js] getAddressesFromLocationName08 callback data is: " + JSON.stringify(data));
} }
else {
console.info("[lbs_js] getAddressesFromLocationName08 callback data is: " + JSON.stringify(data));
}
}
catch(error){
console.info("[lbs_js] getAddressesFromLocationName08 message." + JSON.stringify(error.message));
expect(true).assertFalse();
}
done(); done();
}); });
}catch(error){ await sleep(1000);
console.info("[lbs_js] getAddressesFromLocationName08 message." + JSON.stringify(error.message)); done();
expect(true).assertFalse();
}
await sleep(1000);
done();
}) })
/** /**
...@@ -442,7 +447,7 @@ export default function geolocationTest_geo5() { ...@@ -442,7 +447,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocationName26 try err." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName26 try err." + JSON.stringify(error));
...@@ -469,7 +474,7 @@ export default function geolocationTest_geo5() { ...@@ -469,7 +474,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName10 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName10 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocationName27 try err." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName27 try err." + JSON.stringify(error));
...@@ -544,7 +549,7 @@ export default function geolocationTest_geo5() { ...@@ -544,7 +549,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName29 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName29 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocationName29 try err." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName29 try err." + JSON.stringify(error));
...@@ -634,7 +639,7 @@ export default function geolocationTest_geo5() { ...@@ -634,7 +639,7 @@ export default function geolocationTest_geo5() {
expect(result.length >= 0).assertTrue(); expect(result.length >= 0).assertTrue();
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName31 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName31 promise then error." + JSON.stringify(error));
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocationName31 message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName31 message." + JSON.stringify(error));
...@@ -669,7 +674,7 @@ export default function geolocationTest_geo5() { ...@@ -669,7 +674,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName32 promise then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName32 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
} catch (error) { } catch (error) {
console.info("[lbs_js] getAddressesFromLocationName32 message." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName32 message." + JSON.stringify(error));
...@@ -703,7 +708,7 @@ export default function geolocationTest_geo5() { ...@@ -703,7 +708,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName33 promise1 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName33 promise1 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName33 message1." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName33 message1." + JSON.stringify(error.message));
...@@ -725,7 +730,7 @@ export default function geolocationTest_geo5() { ...@@ -725,7 +730,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName33 promise2 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName33 promise2 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName33 message2." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName33 message2." + JSON.stringify(error.message));
...@@ -790,7 +795,7 @@ export default function geolocationTest_geo5() { ...@@ -790,7 +795,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName33 promise5 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName33 promise5 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName33 message5." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName33 message5." + JSON.stringify(error.message));
...@@ -812,7 +817,7 @@ export default function geolocationTest_geo5() { ...@@ -812,7 +817,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName33 promise6 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName33 promise6 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName33 message6." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName33 message6." + JSON.stringify(error.message));
...@@ -888,7 +893,7 @@ export default function geolocationTest_geo5() { ...@@ -888,7 +893,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName34 promise1 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName34 promise1 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName34 message1." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName34 message1." + JSON.stringify(error.message));
...@@ -910,7 +915,7 @@ export default function geolocationTest_geo5() { ...@@ -910,7 +915,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName34 promise2 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName34 promise2 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName34 message2." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName34 message2." + JSON.stringify(error.message));
...@@ -974,7 +979,7 @@ export default function geolocationTest_geo5() { ...@@ -974,7 +979,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName34 promise5 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName34 promise5 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName34 message5." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName34 message5." + JSON.stringify(error.message));
...@@ -995,7 +1000,7 @@ export default function geolocationTest_geo5() { ...@@ -995,7 +1000,7 @@ export default function geolocationTest_geo5() {
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName34 promise6 then error." + JSON.stringify(error)); console.info("[lbs_js] getAddressesFromLocationName34 promise6 then error." + JSON.stringify(error));
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801); expect(error.code).assertEqual(3301400);
}); });
}catch(error){ }catch(error){
console.info("[lbs_js] getAddressesFromLocationName34 message6." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName34 message6." + JSON.stringify(error.message));
...@@ -1046,9 +1051,5 @@ export default function geolocationTest_geo5() { ...@@ -1046,9 +1051,5 @@ export default function geolocationTest_geo5() {
done(); done();
}) })
}) })
} }
\ No newline at end of file
...@@ -1656,6 +1656,35 @@ export default function geolocationTest_geo7() { ...@@ -1656,6 +1656,35 @@ export default function geolocationTest_geo7() {
done(); done();
}) })
/**
* @tc.number SUB_HSS_LocationSystem_SingleLoc_3500
* @tc.name Test getCurrentLocation
* @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario..
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_SingleLoc_3500', 0, async function (done) {
let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 };
try {
geolocationm.getCurrentLocation(currentLocationRequest, (err, result) => {
if (err) {
console.info("[lbs_js] getCurrentLocation callback err: " + JSON.stringify(err));
expect(err.code).assertEqual(3301200);
console.info('[lbs_js] getCurrentLocationCallback reject after')
} else {
console.info("[lbs_js] getCurrentLocation callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result != null);
}
});
} catch (error) {
console.info("[lbs_js] getCurrentLocation callback try err." + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null);
}
await sleep(1000);
done();
})
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册