提交 9a339e86 编写于 作者: G gaoxi785

new code

Signed-off-by: Ngaoxi785 <gaoxi785@huawei.com>
上级 c291af34
......@@ -14,7 +14,9 @@
*/
import Telephony_NETSTACK_SocketTest from './NetStackSocket.test';
import NetworkManagerTCPSocketServer from "./NetworkManagerTCPSocketServer.test";
import NetManagerTLSSocketServer from './NetManagerTLSSocketServer.test';
export default function testsuite() {
Telephony_NETSTACK_SocketTest();
NetworkManagerTCPSocketServer();
NetManagerTLSSocketServer();
}
\ 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 netSocket from '@ohos.net.socket';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function NetManagerTlsSocketServerTest() {
describe('NetManagerTLSSocketServerTest', function () {
/**
* @tc.number NetworkManager_TLSSocketServer_on_connect_0100
* @tc.name Test on() interface
* @tc.desc Function test
*/
it('NetworkManager_TLSSocketServer_on_connect_0100', 0, async function (done) {
let caseName = 'NetworkManager_TLSSocketServer_on_connect_0100';
let tlsServer = netSocket.constructTLSSocketServerInstance();
try {
tlsServer.on('connect', data => {
console.info(`${caseName} on connect success ${JSON.stringify(data)}`);
expect(data.clientId != undefined).assertTrue();
done();
});
tlsServer.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
ExpectFalse();
done();
return;
}
});
});
}
\ No newline at end of file
......@@ -142,8 +142,10 @@ export default function NetTCPSocketServerTest() {
try {
server.on('connect', data => {
console.info(`${caseName} on connect success ${JSON.stringify(data)}`);
expect(data.clientId != undefined).assertTrue();
done();
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -219,6 +221,7 @@ export default function NetTCPSocketServerTest() {
ExpectFalse();
done();
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -268,6 +271,7 @@ export default function NetTCPSocketServerTest() {
}
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -301,6 +305,7 @@ export default function NetTCPSocketServerTest() {
}
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -334,6 +339,7 @@ export default function NetTCPSocketServerTest() {
}
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect send error: [${error.code}, ${error.message}]`);
......@@ -365,6 +371,7 @@ export default function NetTCPSocketServerTest() {
return;
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -396,6 +403,7 @@ export default function NetTCPSocketServerTest() {
return;
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -428,6 +436,7 @@ export default function NetTCPSocketServerTest() {
}
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -459,6 +468,7 @@ export default function NetTCPSocketServerTest() {
return;
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -491,6 +501,7 @@ export default function NetTCPSocketServerTest() {
}
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -522,6 +533,7 @@ export default function NetTCPSocketServerTest() {
return;
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -754,7 +766,9 @@ export default function NetTCPSocketServerTest() {
done();
return;
}
data.off('message');
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -788,6 +802,7 @@ export default function NetTCPSocketServerTest() {
return;
}
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -824,6 +839,7 @@ export default function NetTCPSocketServerTest() {
return;
}
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -859,7 +875,9 @@ export default function NetTCPSocketServerTest() {
done();
return;
}
data.off('message');
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -887,6 +905,7 @@ export default function NetTCPSocketServerTest() {
expect(true).assertTrue();
done();
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -919,7 +938,9 @@ export default function NetTCPSocketServerTest() {
done();
return;
}
data.off('close');
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -953,6 +974,7 @@ export default function NetTCPSocketServerTest() {
return;
}
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -989,6 +1011,7 @@ export default function NetTCPSocketServerTest() {
return;
}
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1024,7 +1047,9 @@ export default function NetTCPSocketServerTest() {
done();
return;
}
data.off('close');
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1052,6 +1077,7 @@ export default function NetTCPSocketServerTest() {
expect(true).assertTrue();
done();
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1076,7 +1102,9 @@ export default function NetTCPSocketServerTest() {
console.info(`${caseName} on err failed, err: ${JSON.stringify(err)}`);
done();
});
data.off("error");
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1110,6 +1138,7 @@ export default function NetTCPSocketServerTest() {
return;
}
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1138,6 +1167,7 @@ export default function NetTCPSocketServerTest() {
done();
});
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1172,7 +1202,9 @@ export default function NetTCPSocketServerTest() {
done();
return;
}
data.off("error");
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1198,6 +1230,7 @@ export default function NetTCPSocketServerTest() {
});
data.off("error");
});
server.off('connect');
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1219,6 +1252,7 @@ export default function NetTCPSocketServerTest() {
server.on("error", err => {
console.info(`${caseName} on err failed, err: ${JSON.stringify(err)}`);
});
server.off("error");
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1267,6 +1301,7 @@ export default function NetTCPSocketServerTest() {
server.off(null, err => {
console.info(`${caseName} off err failed, err: ${JSON.stringify(err)}`);
});
server.off("error");
done();
} catch (error) {
console.info(`${caseName} catch err, expect err: [${error.code}, ${error.message}]`);
......@@ -1288,7 +1323,7 @@ export default function NetTCPSocketServerTest() {
server.on("error", err => {
console.info(`${caseName} on err failed, err: ${JSON.stringify(err)}`);
});
server.off("error")
server.off("error");
done();
} catch (error) {
console.info(`${caseName} catch error, expect error: [${error.code}, ${error.message}]`);
......@@ -1313,7 +1348,7 @@ export default function NetTCPSocketServerTest() {
done();
} else {
console.info(caseName + ' getSocketFd data ' + JSON.stringify(data));
expect(data == 0).assertTrue();
expect(data != -1).assertTrue();
done();
}
});
......@@ -1329,7 +1364,7 @@ export default function NetTCPSocketServerTest() {
let tcp = socket.constructTCPSocketInstance();
tcp.getSocketFd().then((data) => {
console.info(caseName + ' getSocketFd data ' + JSON.stringify(data));
expect(data == 0).assertTrue();
expect(data != -1).assertTrue();
done();
}).catch((err) => {
console.info(caseName + ' getSocketFd err ' + JSON.stringify(err));
......
......@@ -15,9 +15,12 @@
import {describe, it, expect} from '@ohos/hypium';
import http from '@ohos.net.http';
import connection from "@ohos.net.connection";
import ethernet from '@ohos.net.ethernet';
type httpProxy = connection.HttpProxy;
export default function httpJsunit() {
describe("httpJsunitTest", function () {
/**
* @tc.number Telephony_Http_Http_createHttp_0100
* @tc.name createHttp
......@@ -31,6 +34,7 @@ export default function httpJsunit() {
httpRequest.destroy();
done();
});
/**
* @tc.number Telephony_NetworkManager_getDefaultNetSync
* @tc.name Test getDefaultNetSync() to check return value
......@@ -69,7 +73,7 @@ export default function httpJsunit() {
expect(data).assertEqual(true);
done();
}
})
});
});
/**
......@@ -87,7 +91,100 @@ export default function httpJsunit() {
console.log(JSON.stringify(error));
expect().assertFail();
done();
})
});
});
/**
* @tc.number Telephony_NetworkManager_getDefaultHttpProxy_Async_0100
* @tc.name Test getDefaultHttpProxy() to check return value
* @tc.desc Function test
*/
it('Telephony_NetworkManager_getDefaultHttpProxy_Async_0100', 0, async function (done) {
let caseName = 'Telephony_NetworkManager_getDefaultHttpProxy_Async_0100';
connection.getDefaultHttpProxy((error, data) => {
if (error) {
console.log(`${caseName} getDefaultHttpProxy error`);
expect().assertFail();
done();
} else {
console.log(`${caseName} getDefaultHttpProxy success`);
expect(error).assertEqual(undefined);
expect(data != '').assertTrue();
done();
}
});
});
/**
* @tc.number Telephony_NetworkManager_getDefaultHttpProxy_Promise_0100
* @tc.name Test getDefaultHttpProxy() to check return value
* @tc.desc Function test
*/
it('Telephony_NetworkManager_getDefaultHttpProxy_Promise_0100', 0, async function (done) {
let caseName = 'Telephony_NetworkManager_getDefaultHttpProxy_Promise_0100';
connection.getDefaultHttpProxy().then((data) => {
console.log(`${caseName} getDefaultHttpProxy success`);
expect(data != '').assertTrue();
done();
}).catch((error) => {
console.log(JSON.stringify(error));
expect().assertFail();
done();
});
});
/**
* @tc.number Telephony_NetworkManager_getDefaultHttpProxy_Async_0200
* @tc.name Test getDefaultHttpProxy() to check return value
* @tc.desc Function test
*/
it('Telephony_NetworkManager_getDefaultHttpProxy_Async_0200', 0, async function (done) {
let caseName = 'Telephony_NetworkManager_getDefaultHttpProxy_Async_0200';
connection.getDefaultNet().then(function (netHandle) {
console.log("netHandle is " +JSON.stringify(netHandle));
connection.setAppNet(netHandle).then(() => {
console.log("setAppNet success");
connection.getDefaultHttpProxy((error, data) => {
if (error) {
console.log(`${caseName} getDefaultHttpProxy error`);
expect().assertFail();
done();
} else {
console.log(`${caseName} getDefaultHttpProxy success`);
expect(data != '').assertTrue();
done();
}
});
}).catch(error => {
console.log("setAppNet err " + JSON.stringify(error));
});
});
});
/**
* @tc.number Telephony_NetworkManager_getDefaultHttpProxy_Promise_0200
* @tc.name Test getDefaultHttpProxy() to check return value
* @tc.desc Function test
*/
it('Telephony_NetworkManager_getDefaultHttpProxy_Promise_0200', 0, async function (done) {
let caseName = 'Telephony_NetworkManager_getDefaultHttpProxy_Promise_0200';
connection.getDefaultNet().then(function (netHandle) {
console.log("netHandle is " +JSON.stringify(netHandle));
connection.setAppNet(netHandle).then(() => {
console.log("setAppNet success");
connection.getDefaultHttpProxy().then((data) => {
console.log(`${caseName} getDefaultHttpProxy success`);
expect(data != '').assertTrue();
done();
}).catch((error) => {
console.log(JSON.stringify(error));
expect().assertFail();
done();
});
}).catch(error => {
console.log("setAppNet err " + JSON.stringify(error));
});
});
});
})
};
\ No newline at end of file
});
}
\ No newline at end of file
......@@ -316,6 +316,7 @@ export default function radioSecondJsunit() {
expect(NETWORK_TYPES).assertContain(data[i].signalInformation.signalType);
expect(NETWORK_SIGNAL).assertContain(data[i].signalInformation.signalLevel);
expect(NETWORK_SIGNAL).assertContain(data[i].signalInformation.dBm);
expect(data[i].data != undefined && data[i].data != '' && data[i].data != null).assertTrue();
if (data[i].networkType === radio.NetworkType.NETWORK_TYPE_LTE) {
console.log("radio.NetworkType.NETWORK_TYPE_LTE:" + radio.NetworkType.NETWORK_TYPE_LTE);
......
......@@ -153,5 +153,91 @@ describe('SmsMmsErrorTest', function () {
done();
}
});
/**
* @tc.number Telephony_SmsMms_sendShortMessage_Promise_0100
* @tc.name Telephony_SmsMms_sendShortMessage_Promise_0100
* @tc.desc Function test
*/
it('Telephony_SmsMms_sendShortMessage_Promise_0100', 0, async function (done) {
try {
let sendCallback = function (err, data) {
expect(data.isLastPart).assertEqual(false);
console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let deliveryCallback = function (err, data) {
console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let slotId = 0;
let content = '短信内容';
let destinationHost = '10086';
let serviceCenter = '';
let destinationPort = 1000;
let options = {
slotId,
content,
destinationHost,
serviceCenter,
destinationPort,
sendCallback,
deliveryCallback
};
sms.sendMessage(options).then((data)=>{
console.info('Telephony_SmsMms_sendShortMessage_Promise_0100 ' + JSON.stringify(data));
expect().assertFail();
done();
}).catch((error)=>{
expect(error.code == 201).assertTrue();
done();
});
} catch (err) {
expect(true).assertFalse();
done();
}
});
/**
* @tc.number Telephony_SmsMms_sendShortMessage_Async_0100
* @tc.name v
* @tc.desc Function test
*/
it('Telephony_SmsMms_sendShortMessage_Async_0100', 0, async function (done) {
try {
let sendCallback = function (err, data) {
expect(data.isLastPart).assertEqual(false);
console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let deliveryCallback = function (err, data) {
console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let slotId = 0;
let content = '短信内容';
let destinationHost = '10086';
let serviceCenter = '';
let destinationPort = 1000;
let options = {
slotId,
content,
destinationHost,
serviceCenter,
destinationPort,
sendCallback,
deliveryCallback
};
sms.sendMessage(options,(err,data)=>{
if(err){
expect(error.code == 201).assertTrue();
done();
} else {
console.info('Telephony_SmsMms_sendShortMessage_Async_0100 ' + JSON.stringify(data));
expect().assertFail();
done();
}
});
} catch (err) {
expect(true).assertFalse();
done();
}
});
});
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册