Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
1bbdd0e3
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1bbdd0e3
编写于
7月 15, 2023
作者:
高
高曦
提交者:
Gitee
7月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update NetworkManagerTCPSocketServer.test.js.
Signed-off-by:
N
高曦
<
gaoxi785@huawei.com
>
上级
b9dcd581
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
1221 addition
and
1121 deletion
+1221
-1121
telephony/telephonyjstest/netmanager_base/socket/src/main/js/test/NetworkManagerTCPSocketServer.test.js
...et/src/main/js/test/NetworkManagerTCPSocketServer.test.js
+1221
-1121
未找到文件。
telephony/telephonyjstest/netmanager_base/socket/src/main/js/test/NetworkManagerTCPSocketServer.test.js
浏览文件 @
1bbdd0e3
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
{
describe
,
it
,
expect
,
beforeAll
,
afterAll
,
afterEach
}
from
'
@ohos/hypium
'
;
import
{
describe
,
it
,
expect
}
from
'
@ohos/hypium
'
;
import
socket
from
"
@ohos.net.socket
"
;
let
address
=
{
...
...
@@ -42,7 +42,7 @@ let TCPExtraOptions = {
socketTimeout
:
3000
,
}
function
e
xpectFalse
()
{
function
E
xpectFalse
()
{
try
{
expect
().
assertFail
();
}
catch
(
err
)
{
...
...
@@ -79,9 +79,10 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
listen
(
address
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
done
();
}
else
{
console
.
info
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
).
assertFail
();
done
();
}
...
...
@@ -99,40 +100,14 @@ export default function NetTCPSocketServerTest() {
try
{
server
.
listen
(
null
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
listen failed, err:
${
JSON
.
stringify
(
err
)}
`
);
done
();
}
else
{
expect
(
data
).
assertFail
();
done
();
}
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
console
.
info
(
`
${
caseName
}
listen failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
.
code
).
assertEqual
(
401
);
done
();
}
});
/**
* @tc.number NetworkManager_TCPSocketServer_listen_Async_0300
* @tc.name Test listen() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_listen_Async_0300
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocketServer_listen_Async_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
listen
(
address
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
listen failed, err:
${
JSON
.
stringify
(
err
)}
`
);
done
();
}
else
{
expect
(
data
).
assertFail
();
done
();
}
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
}
...
...
@@ -147,10 +122,11 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_listen_Promise_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
listen
(
address
).
then
((
data
)
=>
{
console
.
info
(
`
${
caseName
}
listen :
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
).
assertFail
();
done
();
}).
catch
((
err
)
=>
{
console
.
log
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
done
();
});
});
...
...
@@ -164,14 +140,14 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_connect_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
typeof
(
data
)).
assertEqual
(
'
object
'
);
server
.
on
(
'
connect
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -187,12 +163,13 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
...
...
@@ -208,18 +185,18 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_connect_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
+ data.clientId`
);
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
});
server
.
off
(
"
connect
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
off connect success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
typeof
(
data
)).
assertEqual
(
'
object
'
);
expect
(
true
).
assertTrue
();
server
.
off
(
'
connect
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
off connect success
${
JSON
.
stringify
(
data
)}
`
);
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -234,16 +211,17 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_connect_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
});
server
.
off
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
off connect success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
off connect success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
...
...
@@ -258,10 +236,10 @@ export default function NetTCPSocketServerTest() {
it
(
'
NetworkManager_TCPSocketServer_off_connect_0300
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocketServer_off_connect_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
on
(
"
connect
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
});
server
.
off
(
"
connect
"
);
server
.
off
(
'
connect
'
);
expect
(
true
).
assertTrue
();
done
();
});
...
...
@@ -275,23 +253,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Async_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions1
,
(
data
,
err
)
=>
{
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions1
,
(
err
,
data
)
=>
{
if
(
err
)
{
expectFalse
();
console
.
info
(
`
${
caseName
}
send err
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
}
else
{
console
.
log
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -306,23 +286,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Async_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions2
,
(
data
,
err
)
=>
{
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions2
,
(
err
,
data
)
=>
{
if
(
err
)
{
expectFalse
();
console
.
info
(
`
${
caseName
}
send err
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
}
else
{
console
.
log
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -337,30 +319,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Async_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
null
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
send failed
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
send failed
${
JSON
.
stringify
(
err
)}
`
);
done
();
return
;
}
else
{
expectFalse
();
console
.
info
(
`
${
caseName
}
on send data
${
JSON
.
stringify
(
data
)}
`
);
ExpectFalse
();
done
();
return
;
}
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect send error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect connect
error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expectFalse
(
);
console
.
info
(
`
${
caseName
}
catch error, expect send
error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
}
...
...
@@ -375,21 +352,23 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Promise_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions1
).
then
((
data
)
=>
{
console
.
log
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}).
catch
((
err
)
=>
{
expectFalse
();
console
.
info
(
`
${
caseName
}
on send catch
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -401,24 +380,26 @@ export default function NetTCPSocketServerTest() {
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_send_Promise_0200
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Promise_01
00
'
;
let
caseName
=
'
NetworkManager_TCPSocketServer_send_Promise_02
00
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
send
(
sendOptions2
).
then
((
data
)
=>
{
console
.
log
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
send success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}).
catch
((
err
)
=>
{
expectFalse
();
console
.
info
(
`
${
caseName
}
on send catch
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -433,23 +414,24 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_close_Async_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
close
((
data
,
err
)
=>
{
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
close
((
err
,
data
)
=>
{
if
(
err
)
{
e
xpectFalse
();
E
xpectFalse
();
done
();
return
;
}
else
{
console
.
log
(
`
${
caseName
}
close success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
close success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -464,21 +446,23 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_close_Promise_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
close
().
then
((
data
)
=>
{
console
.
log
(
`
${
caseName
}
close success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
close success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}).
catch
((
err
)
=>
{
expectFalse
();
console
.
info
(
`
${
caseName
}
on close catch
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -493,23 +477,24 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_getRemoteAddress_Async_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
getRemoteAddress
((
data
,
err
)
=>
{
if
(
err
)
{
e
xpectFalse
();
E
xpectFalse
();
done
();
return
;
}
else
{
console
.
log
(
`
${
caseName
}
getRemoteAddress success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
getRemoteAddress success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -524,21 +509,23 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_getRemoteAddress_Promise_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
getRemoteAddress
().
then
((
data
)
=>
{
console
.
log
(
`
${
caseName
}
getRemoteAddress success
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
getRemoteAddress success
${
JSON
.
stringify
(
data
)}
`
);
done
();
return
;
}).
catch
((
err
)
=>
{
expectFalse
();
console
.
info
(
`
${
caseName
}
on connect catch
${
JSON
.
stringify
(
err
)}
`
);
ExpectFalse
();
done
();
return
;
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -550,38 +537,104 @@ export default function NetTCPSocketServerTest() {
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_getState_Async_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
"
NetworkManager_TCPSocketServer_getState_Async_0100
"
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
getState
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
`
${
caseName
}
getState err
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
}
else
{
expect
(
data
.
isBound
).
assertEqual
(
false
)
expect
(
data
.
isClose
).
assertEqual
(
true
)
expect
(
data
.
isConnected
).
assertEqual
(
false
)
console
.
info
(
`
${
caseName
}
getState data
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
.
isBound
).
assertEqual
(
false
);
expect
(
data
.
isClose
).
assertEqual
(
true
);
expect
(
data
.
isConnected
).
assertEqual
(
false
);
done
();
}
});
});
/**
* @tc.number NetworkManager_TCPSocketServer_getState_Async_0200
* @tc.name Test getState() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_getState_Async_0200
'
,
0
,
async
function
(
done
)
{
let
caseName
=
"
NetworkManager_TCPSocketServer_getState_Async_0200
"
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
listen
(
address
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
done
();
}
else
{
console
.
info
(
`
${
caseName
}
listen data
${
JSON
.
stringify
(
data
)}
`
);
server
.
getState
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
`
${
caseName
}
getState err
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
}
else
{
console
.
info
(
`
${
caseName
}
getState data
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
.
isBound
).
assertEqual
(
false
);
expect
(
data
.
isClose
).
assertEqual
(
true
);
expect
(
data
.
isConnected
).
assertEqual
(
false
);
done
();
}
});
}
});
});
/**
* @tc.number NetworkManager_TCPSocketServer_getState_Promise_0100
* @tc.name Test getState() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_getState_Promise_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
"
NetworkManager_TCPSocketServer_getState_Promise_0100
"
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
getState
().
then
((
data
)
=>
{
expect
(
data
.
isBound
).
assertEqual
(
false
)
expect
(
data
.
isClose
).
assertEqual
(
true
)
expect
(
data
.
isConnected
).
assertEqual
(
false
)
console
.
info
(
`
${
caseName
}
getState data
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
.
isBound
).
assertEqual
(
false
);
expect
(
data
.
isClose
).
assertEqual
(
true
);
expect
(
data
.
isConnected
).
assertEqual
(
false
);
done
();
}).
catch
((
err
)
=>
{
console
.
info
(
`
${
caseName
}
getState err
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
).
assertFail
();
done
();
});
});
/**
* @tc.number NetworkManager_TCPSocketServer_getState_Promise_0100
* @tc.name Test getState() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocketServer_getState_Promise_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
"
NetworkManager_TCPSocketServer_getState_Promise_0100
"
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
listen
(
address
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
`
${
caseName
}
listen failed:
${
JSON
.
stringify
(
err
)}
`
);
done
();
}
else
{
console
.
info
(
`
${
caseName
}
getState data
${
JSON
.
stringify
(
data
)}
`
);
server
.
getState
().
then
((
data
)
=>
{
console
.
info
(
`
${
caseName
}
getState data
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
.
isBound
).
assertEqual
(
false
);
expect
(
data
.
isClose
).
assertEqual
(
true
);
expect
(
data
.
isConnected
).
assertEqual
(
false
);
done
();
}).
catch
((
err
)
=>
{
console
.
info
(
`
${
caseName
}
getState err
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
).
assertFail
();
done
();
});
}
});
});
/**
* @tc.number NetworkManager_TCPSocketServer_setExtraOptions_Async_0100
* @tc.name Test setExtraOptions() interface
...
...
@@ -590,14 +643,14 @@ export default function NetTCPSocketServerTest() {
it
(
'
NetworkManager_TCPSocketServer_setExtraOptions_Async_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocketServer_setExtraOptions_Async_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
setExtraOptions
(
TCPExtraOptions
,
(
data
,
err
)
=>
{
server
.
setExtraOptions
(
TCPExtraOptions
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
).
assertFail
(
);
console
.
info
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
!=
undefined
).
assertEqual
(
true
);
done
();
}
else
{
console
.
log
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
!=
undefined
).
assertEqual
(
true
);
console
.
info
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
ExpectFalse
(
);
done
();
}
});
...
...
@@ -614,18 +667,18 @@ export default function NetTCPSocketServerTest() {
try
{
server
.
setExtraOptions
(
null
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
.
code
).
assertEqual
(
401
);
done
();
}
else
{
console
.
log
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
).
assertFail
();
done
();
}
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -640,20 +693,20 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_setExtraOptions_Async_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
setExtraOptions
(
TCPExtraOptions
.
keepAlive
,
(
err
,
data
)
=>
{
server
.
setExtraOptions
(
TCPExtraOptions
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
.
code
).
assertEqual
(
401
);
console
.
info
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
!=
undefined
).
assertEqual
(
true
);
done
();
}
else
{
console
.
log
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
).
assertFail
();
done
();
}
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -668,11 +721,11 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_setExtraOptions_Promise_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
server
.
setExtraOptions
(
TCPExtraOptions
).
then
((
data
)
=>
{
console
.
log
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
console
.
info
(
`
${
caseName
}
setExtraOptions success, data:
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
).
assertFail
();
done
();
}).
catch
((
err
)
=>
{
console
.
log
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
setExtraOptions failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
(
err
!=
undefined
).
assertEqual
(
true
);
done
();
});
...
...
@@ -687,24 +740,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_message_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
message
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
message
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
typeof
(
data
)).
assertEqual
(
'
object
'
);
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -719,24 +773,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_message_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
expect
(
err
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -751,27 +806,28 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_message_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
message
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
message
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
"
message
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
off message success
${
JSON
.
stringify
(
data
)}
`
);
data
.
off
(
'
message
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
off message success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
typeof
(
data
)).
assertEqual
(
'
object
'
);
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -786,27 +842,28 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_message_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
message
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
message
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
off message success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
off message success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -821,18 +878,19 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_message_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
"
message
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
message
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on message success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
"
message
"
);
data
.
off
(
'
message
'
);
expect
(
true
).
assertTrue
();
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -847,24 +905,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_close_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
close
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
close
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
!=
undefined
).
assertEqual
(
true
);
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -879,24 +938,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_close_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
expect
(
err
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -911,27 +971,28 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_close_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
close
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
close
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
"
close
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
off close success
${
JSON
.
stringify
(
data
)}
`
);
data
.
off
(
'
close
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
off close success
${
JSON
.
stringify
(
data
)}
`
);
expect
(
data
!=
undefined
).
assertEqual
(
true
);
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -946,27 +1007,28 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_close_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
close
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
close
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
null
,
data
=>
{
console
.
log
(
`
${
caseName
}
off close success
${
JSON
.
stringify
(
data
)}
`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
off close success
${
JSON
.
stringify
(
data
)}
`
);
E
xpectFalse
();
done
();
});
}
catch
(
err
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
err
.
code
}
,
${
err
.
message
}
]`
);
expect
(
err
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -981,18 +1043,19 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_close_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
"
close
"
,
data
=>
{
console
.
log
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
'
close
'
,
data
=>
{
console
.
info
(
`
${
caseName
}
on close success
${
JSON
.
stringify
(
data
)}
`
);
});
data
.
off
(
"
close
"
);
data
.
off
(
'
close
'
);
expect
(
true
).
assertTrue
();
done
();
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1007,17 +1070,17 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_error_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
done
();
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1032,24 +1095,25 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_on_error_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
null
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
});
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1064,20 +1128,20 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_error_0100
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
data
.
off
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
console
.
info
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
done
();
});
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1092,27 +1156,27 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_error_0200
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
try
{
data
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
data
.
off
(
null
,
err
=>
{
console
.
log
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
console
.
info
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
}
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1127,18 +1191,17 @@ export default function NetTCPSocketServerTest() {
let
caseName
=
'
NetworkManager_TCPSocketServer_off_error_0300
'
;
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
connect
"
,
(
data
)
=>
{
console
.
log
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
server
.
on
(
'
connect
'
,
(
data
)
=>
{
console
.
info
(
`
${
caseName
}
on connect success
${
JSON
.
stringify
(
data
)}
`
);
data
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
data
.
off
(
"
error
"
)
expect
().
assertFail
();
done
();
data
.
off
(
"
error
"
);
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1154,13 +1217,12 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1176,16 +1238,15 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
server
.
off
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
console
.
info
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
...
...
@@ -1201,15 +1262,14 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
server
.
off
(
null
,
err
=>
{
console
.
log
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
expect
().
assertFail
();
done
();
console
.
info
(
`
${
caseName
}
off err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
console
.
info
(
`
${
caseName
}
catch err, expect err: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
expect
(
error
.
code
).
assertEqual
(
401
);
done
();
return
;
...
...
@@ -1226,17 +1286,57 @@ export default function NetTCPSocketServerTest() {
let
server
=
socket
.
constructTCPSocketServerInstance
();
try
{
server
.
on
(
"
error
"
,
err
=>
{
console
.
log
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
console
.
info
(
`
${
caseName
}
on err failed, err:
${
JSON
.
stringify
(
err
)}
`
);
});
server
.
off
(
"
error
"
)
expect
().
assertFail
();
done
();
}
catch
(
error
)
{
console
.
log
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
e
xpectFalse
();
console
.
info
(
`
${
caseName
}
catch error, expect error: [
${
error
.
code
}
,
${
error
.
message
}
]`
);
E
xpectFalse
();
done
();
return
;
}
});
/**
* @tc.number NetworkManager_TCPSocket_getSocketFd_Async_0100
* @tc.name Test getSocketFd() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocket_getSocketFd_Async_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocket_getSocketFd_Async_0100
'
;
let
tcp
=
socket
.
constructTCPSocketInstance
();
tcp
.
getSocketFd
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
caseName
+
'
getSocketFd err
'
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
}
else
{
console
.
info
(
caseName
+
'
getSocketFd data
'
+
JSON
.
stringify
(
data
));
expect
(
data
==
0
).
assertTrue
();
done
();
}
});
});
/**
* @tc.number NetworkManager_TCPSocket_getSocketFd_Promise_0100
* @tc.name Test getSocketFd() interface
* @tc.desc Function test
*/
it
(
'
NetworkManager_TCPSocket_getSocketFd_Promise_0100
'
,
0
,
async
function
(
done
)
{
let
caseName
=
'
NetworkManager_TCPSocket_getSocketFd_Promise_0100
'
;
let
tcp
=
socket
.
constructTCPSocketInstance
();
tcp
.
getSocketFd
().
then
((
data
)
=>
{
console
.
info
(
caseName
+
'
getSocketFd data
'
+
JSON
.
stringify
(
data
));
expect
(
data
==
0
).
assertTrue
();
done
();
}).
catch
((
err
)
=>
{
console
.
info
(
caseName
+
'
getSocketFd err
'
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
});
});
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录