提交 87420503 编写于 作者: Z zhangfuzhi

优化搜网部分测试用例

Signed-off-by: Nzhangfuzhi <zhangfuzhi1@huawei.com>
上级 c973d630
...@@ -14,10 +14,22 @@ ...@@ -14,10 +14,22 @@
*/ */
import network from '@system.network'; import network from '@system.network';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, it, expect } from '@ohos/hypium'
import connection from '@ohos.net.connection';
export default function Telephony_NetManager_NetWorkTest() { export default function Telephony_NetManager_NetWorkTest() {
describe("Telephony_NetManager_NetWorkTest", function () { describe("Telephony_NetManager_NetWorkTest", function () {
let networkAvailable = () => {
connection.getDefaultNet(function (error, netHandle) {
if (error || netHandle.netId >= 100) {
console.info("Network available or Network error:" + error)
return true
}
return false
})
}
/** /**
* @tc.number Telephony_NetManager_NetWorkTest_GetType_None_0100 * @tc.number Telephony_NetManager_NetWorkTest_GetType_None_0100
...@@ -25,6 +37,11 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -25,6 +37,11 @@ describe("Telephony_NetManager_NetWorkTest", function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it("Telephony_NetManager_NetWorkTest_GetType_None_0100", 0, function (done) { it("Telephony_NetManager_NetWorkTest_GetType_None_0100", 0, function (done) {
if (networkAvailable) {
console.warn("No network environment required")
done()
return
}
network.getType({ network.getType({
success: function (data) { success: function (data) {
console.info("NetManager getType " + JSON.stringify(data)) console.info("NetManager getType " + JSON.stringify(data))
...@@ -34,6 +51,7 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -34,6 +51,7 @@ describe("Telephony_NetManager_NetWorkTest", function () {
done(); done();
}, },
fail: function (data, code) { fail: function (data, code) {
console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code))
expect().assertFail(); expect().assertFail();
done(); done();
}, },
...@@ -51,6 +69,11 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -51,6 +69,11 @@ describe("Telephony_NetManager_NetWorkTest", function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it("Telephony_NetManager_NetWorkTest_GetType_None_0200", 0, function (done) { it("Telephony_NetManager_NetWorkTest_GetType_None_0200", 0, function (done) {
if (networkAvailable) {
console.warn("No network environment required")
done()
return
}
network.getType({ network.getType({
success: function (data) { success: function (data) {
console.info("NetManager getType 1 " + JSON.stringify(data)) console.info("NetManager getType 1 " + JSON.stringify(data))
...@@ -61,6 +84,7 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -61,6 +84,7 @@ describe("Telephony_NetManager_NetWorkTest", function () {
console.info("NetManager Telephony_NetManager_NetWorkTest_GetType_none_1 end") console.info("NetManager Telephony_NetManager_NetWorkTest_GetType_none_1 end")
}, },
fail: function (data, code) { fail: function (data, code) {
console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code))
expect().assertFail(); expect().assertFail();
done(); done();
}, },
...@@ -78,6 +102,11 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -78,6 +102,11 @@ describe("Telephony_NetManager_NetWorkTest", function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it("Telephony_NetManager_NetWorkTest_Subscribe_None_0100", 0, function (done) { it("Telephony_NetManager_NetWorkTest_Subscribe_None_0100", 0, function (done) {
if (networkAvailable) {
console.warn("No network environment required")
done()
return
}
network.subscribe({ network.subscribe({
success: function (data) { success: function (data) {
console.info("NetManager subscribe " + JSON.stringify(data)) console.info("NetManager subscribe " + JSON.stringify(data))
...@@ -87,6 +116,7 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -87,6 +116,7 @@ describe("Telephony_NetManager_NetWorkTest", function () {
done(); done();
}, },
fail: function (data, code) { fail: function (data, code) {
console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code))
expect().assertFail() expect().assertFail()
done(); done();
} }
...@@ -100,6 +130,11 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -100,6 +130,11 @@ describe("Telephony_NetManager_NetWorkTest", function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it("Telephony_NetManager_NetWorkTest_Subscribe_None_0200", 0, function (done) { it("Telephony_NetManager_NetWorkTest_Subscribe_None_0200", 0, function (done) {
if (networkAvailable) {
console.warn("No network environment required")
done()
return
}
network.subscribe({ network.subscribe({
success: function (data) { success: function (data) {
console.info("NetManager subscribe " + JSON.stringify(data)) console.info("NetManager subscribe " + JSON.stringify(data))
...@@ -109,6 +144,7 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -109,6 +144,7 @@ describe("Telephony_NetManager_NetWorkTest", function () {
done(); done();
}, },
fail: function (data, code) { fail: function (data, code) {
console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code))
expect().assertFail() expect().assertFail()
done(); done();
} }
...@@ -116,5 +152,5 @@ describe("Telephony_NetManager_NetWorkTest", function () { ...@@ -116,5 +152,5 @@ describe("Telephony_NetManager_NetWorkTest", function () {
done(); done();
}); });
}); });
} }
\ No newline at end of file
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -381,13 +381,14 @@ describe('ActsNetworkSearchTest', function () { ...@@ -381,13 +381,14 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it('Telephony_NetworkSearch_isRadioOn_Async_0200', 0, async function (done) { it('Telephony_NetworkSearch_isRadioOn_Async_0200', 0, async function (done) {
radio.isRadioOn((err) => { radio.isRadioOn((err, data) => {
if (err) { if (err) {
console.info(`Telephony_NetworkSearch_isRadioOn_Async_0200 fail: ${err}`); console.error('When the device has no modem, the interface reports an error' + JSON.stringify(err));
done(); done();
return; return;
} }
console.info('Telephony_NetworkSearch_isRadioOn_Async_0200 finish'); console.info('Telephony_NetworkSearch_isRadioOn_Async_0200 finish ' + JSON.stringify(data));
expect(data == true).assertTrue();
done(); done();
}); });
}); });
...@@ -399,11 +400,12 @@ describe('ActsNetworkSearchTest', function () { ...@@ -399,11 +400,12 @@ describe('ActsNetworkSearchTest', function () {
*/ */
it('Telephony_NetworkSearch_isRadioOn_Promise_0200', 0, async function (done) { it('Telephony_NetworkSearch_isRadioOn_Promise_0200', 0, async function (done) {
try { try {
await radio.isRadioOn(); let data = await radio.isRadioOn();
console.info('Telephony_NetworkSearch_isRadioOn_Promise_0200 success'); console.info('Telephony_NetworkSearch_isRadioOn_Promise_0200 finish ' + JSON.stringify(data));
expect(data == true).assertTrue();
done(); done();
} catch (err) { } catch (err) {
console.info(`Telephony_NetworkSearch_isRadioOn_Promise_0200 fail ${err}`); console.error('When the device has no modem, the interface reports an error' + JSON.stringify(err));
done(); done();
} }
}); });
...@@ -414,13 +416,14 @@ describe('ActsNetworkSearchTest', function () { ...@@ -414,13 +416,14 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Test isRadioOn api by callback. * @tc.desc Test isRadioOn api by callback.
*/ */
it('Telephony_NetworkSearch_isRadioOn_Async_0300', 0, async function (done) { it('Telephony_NetworkSearch_isRadioOn_Async_0300', 0, async function (done) {
radio.isRadioOn(0, (err) => { radio.isRadioOn(0, (err, data) => {
if (err) { if (err) {
console.info(`Telephony_NetworkSearch_isRadioOn_Async_0300 fail: ${err}`); console.error('When the device has no modem, the interface reports an error' + JSON.stringify(err));
done(); done();
return; return;
} }
console.info('Telephony_NetworkSearch_isRadioOn_Async_0300 finish'); console.info('Telephony_NetworkSearch_isRadioOn_Async_0300 finish ' + JSON.stringify(data));
expect(data == true).assertTrue();
done(); done();
}); });
}); });
...@@ -432,11 +435,12 @@ describe('ActsNetworkSearchTest', function () { ...@@ -432,11 +435,12 @@ describe('ActsNetworkSearchTest', function () {
*/ */
it('Telephony_NetworkSearch_isRadioOn_Promise_0300', 0, async function (done) { it('Telephony_NetworkSearch_isRadioOn_Promise_0300', 0, async function (done) {
try { try {
await radio.isRadioOn(0); let data = await radio.isRadioOn(0);
console.info('Telephony_NetworkSearch_isRadioOn_Promise_0300 success'); console.info('Telephony_NetworkSearch_isRadioOn_Promise_0300 finish ' + JSON.stringify(data));
expect(data == true).assertTrue();
done(); done();
} catch (err) { } catch (err) {
console.info(`Telephony_NetworkSearch_isRadioOn_Promise_0300 fail ${err}`); console.error('When the device has no modem, the interface reports an error' + JSON.stringify(err));
done(); done();
} }
}); });
...@@ -447,11 +451,18 @@ describe('ActsNetworkSearchTest', function () { ...@@ -447,11 +451,18 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it('Telephony_StateRegistry_on_0200', 0, async function (done) { it('Telephony_StateRegistry_on_0200', 0, async function (done) {
observer.on('networkStateChange', { slotId: SLOT_0 }, (networkState) => { try {
console.info(`Telephony_StateRegistry_on_0200 networkStateChanged data: ${JSON.stringify(networkState)}`); observer.on('networkStateChange', {
done(); slotId: 0
}, NetworkState => {
console.log("on networkStateChange, NetworkState:" + JSON.stringify(NetworkState));
expect(typeof NetworkState === undefined).assertFalse()
}); });
done(); done()
} catch (error) {
expect(false).assertTrue()
done()
}
}); });
/** /**
...@@ -460,8 +471,20 @@ describe('ActsNetworkSearchTest', function () { ...@@ -460,8 +471,20 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it('Telephony_StateRegistry_off_0200', 0, async function (done) { it('Telephony_StateRegistry_off_0200', 0, async function (done) {
try {
let callback = NetworkState => {
console.log("on networkStateChange, NetworkState:" + JSON.stringify(NetworkState));
expect(typeof NetworkState === undefined).assertFalse()
}
observer.on('networkStateChange', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
observer.off('networkStateChange', callback);
observer.off('networkStateChange'); observer.off('networkStateChange');
done(); done()
} catch (error) {
expect(false).assertTrue()
done()
}
}); });
/** /**
...@@ -470,11 +493,18 @@ describe('ActsNetworkSearchTest', function () { ...@@ -470,11 +493,18 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it('Telephony_StateRegistry_on_0300', 0, async function (done) { it('Telephony_StateRegistry_on_0300', 0, async function (done) {
observer.on('signalInfoChange', { slotId: SLOT_0 }, (networkState) => { try {
console.info(`Telephony_StateRegistry_on_0200 networkStateChanged data: ${JSON.stringify(networkState)}`); observer.on('signalInfoChange', {
done(); slotId: 0
}, SignalInformation => {
console.log("on signalInfoChange, SignalInformation:" + JSON.stringify(SignalInformation));
expect(typeof SignalInformation === undefined).assertFalse()
}); });
done(); done()
} catch (error) {
expect(false).assertTrue()
done()
}
}); });
/** /**
...@@ -483,8 +513,20 @@ describe('ActsNetworkSearchTest', function () { ...@@ -483,8 +513,20 @@ describe('ActsNetworkSearchTest', function () {
* @tc.desc Function test * @tc.desc Function test
*/ */
it('Telephony_StateRegistry_off_0300', 0, async function (done) { it('Telephony_StateRegistry_off_0300', 0, async function (done) {
try {
let callback = SignalInformation => {
console.log("on signalInfoChange, SignalInformation:" + JSON.stringify(SignalInformation));
expect(typeof SignalInformation === undefined).assertFalse()
}
observer.on('signalInfoChange', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
observer.off('signalInfoChange', callback);
observer.off('signalInfoChange'); observer.off('signalInfoChange');
done(); done()
} catch (error) {
expect(false).assertTrue()
done()
}
}); });
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册