• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import { describe, it, expect, Level, Size, TestType } from '@ohos/hypium'
16import socket from "@ohos.net.socket";
17import { BusinessError, Callback } from '@ohos.base';
18import { ArrayBufferToString } from './utils';
19
20
21function expectSuccess(): void {
22  expect(true).assertTrue();
23}
24
25
26function expectFail(info: string = ''): void {
27  try {
28    expect(false).assertTrue();
29  } catch (err) {
30    console.info(`${info} test failed`);
31  }
32}
33
34
35function expectTrue(exp: boolean, info: string = ''): void {
36  try {
37    expect(exp).assertTrue();
38  } catch (err) {
39    console.info(`${info} test failed`);
40  }
41}
42
43function expectFalse(exp: boolean, info: string = ''): void {
44  try {
45    expect(exp).assertFalse();
46  } catch (err) {
47    console.info(`${info} test failed`);
48  }
49}
50
51function expectEqual(exp: string | number | boolean, assert: string | number | boolean, info: string = ''): void {
52  try {
53    expect(exp).assertEqual(assert);
54  } catch (err) {
55    console.info(`${info} test failed`);
56  }
57}
58
59
60export default function TCPSocketConnectionTest() {
61  describe('ActsTCPSocketConnectionTest', () => {
62
63    /* *
64     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0100
65     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0100
66     * @tc.desc  : Sending data through TCP Socket Connection connection,Sending data as a string;callback
67     * @tc.size  : MediumTest
68     * @tc.type  : Function
69     * @tc.level : level 0
70     */
71    it('testNetworkMgrSocketTCPSocketConnectionSend0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => {
72      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0100';
73      try {
74        console.info(`${caseName} test start`);
75        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
76        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
77        let listenAddress: socket.NetAddress = {
78          address: '127.0.0.1',
79          port: 8000,
80          family: 1
81        };
82        await tcpServer.listen(listenAddress)
83        let tcpConnectOptions: socket.TCPConnectOptions = {
84          address: listenAddress
85        };
86        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
87          let tcpSendOption: socket.TCPSendOptions = {
88            data: 'Hello, client!'
89          };
90          client.send(tcpSendOption, (err: BusinessError) => {
91            if (err) {
92              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
93              expectFail();
94              done();
95            } else {
96              console.info(`${caseName} success`);
97              expectSuccess();
98              done();
99            };
100            tcpServer.off('connect');
101            console.info(`${caseName} test end`);
102            done();
103          });
104        });
105        await tcp.connect(tcpConnectOptions);
106      } catch (err) {
107        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
108        expectFail();
109        console.info(`${caseName} test end`);
110        done();
111      }
112    });
113
114    /* *
115     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0200
116     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0200
117     * @tc.desc  : Sending data through TCP Socket Connection connection,input parameter type is arrayBuffer;callback
118     * @tc.size  : MediumTest
119     * @tc.type  : Function
120     * @tc.level : level 2
121     */
122    it('testNetworkMgrSocketTCPSocketConnectionSend0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
123      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0200';
124      try {
125        console.info(`${caseName} test start`);
126        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
127        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
128        let listenAddress: socket.NetAddress = {
129          address: '127.0.0.1',
130          port: 8003,
131          family: 1
132        };
133        await tcpServer.listen(listenAddress);
134        let tcpConnectOptions: socket.TCPConnectOptions = {
135          address: listenAddress
136        };
137        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
138          let tcpSendOption: socket.TCPSendOptions = {
139            data: new ArrayBuffer(234)
140          };
141          client.send(tcpSendOption, (err: BusinessError) => {
142            if (err) {
143              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
144              expectFail();
145              done();
146            } else {
147              console.info(`${caseName} success`);
148              expectSuccess();
149              done();
150            };
151            tcpServer.off('connect');
152            console.info(`${caseName} test end`);
153            done();
154          });
155        });
156        await tcp.connect(tcpConnectOptions);
157      } catch (err) {
158        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
159        expectFail();
160        console.info(`${caseName} test end`);
161        done();
162      }
163    });
164
165    /* *
166     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0300
167     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0300
168     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is an empty string; callback
169     * @tc.size  : MediumTest
170     * @tc.type  : Function
171     * @tc.level : level 0
172     */
173    it('testNetworkMgrSocketTCPSocketConnectionSend0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => {
174      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0300';
175      try {
176        console.info(`${caseName} test start`);
177        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
178        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
179        let listenAddress: socket.NetAddress = {
180          address: '127.0.0.1',
181          port: 8004,
182          family: 1
183        };
184        let tcpConnectOptions: socket.TCPConnectOptions = {
185          address: listenAddress
186        };
187        await tcpServer.listen(listenAddress);
188        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
189          let tcpSendOption: socket.TCPSendOptions = {
190            data: 'Hello, client!',
191            encoding: ''
192          };
193          client.send(tcpSendOption, (err: BusinessError) => {
194            if (err) {
195              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
196              expectFail();
197              done();
198            } else {
199              console.info(`${caseName} success`);
200              expectSuccess();
201              done();
202            };
203            tcpServer.off('connect');
204            console.info(`${caseName} test end`);
205            done();
206          });
207        });
208        await tcp.connect(tcpConnectOptions);
209      } catch (err) {
210        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
211        expectFail();
212        console.info(`${caseName} test end`);
213        done();
214      }
215    });
216
217    /* *
218     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0400
219     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0400
220     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-8; callback
221     * @tc.size  : MediumTest
222     * @tc.type  : Function
223     * @tc.level : level 2
224     */
225    it('testNetworkMgrSocketTCPSocketConnectionSend0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
226      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0400';
227      try {
228        console.info(`${caseName} test start`);
229        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
230        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
231        let listenAddress: socket.NetAddress = {
232          address: '127.0.0.1',
233          port: 8005,
234          family: 1
235        };
236        await tcpServer.listen(listenAddress);
237        let tcpConnectOptions: socket.TCPConnectOptions = {
238          address: listenAddress
239        };
240        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
241          let tcpSendOption: socket.TCPSendOptions = {
242            data: 'Hello, client!',
243            encoding: 'UTF-8'
244          };
245          client.send(tcpSendOption, (err: BusinessError) => {
246            if (err) {
247              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
248              expectFail();
249              done();
250            } else {
251              console.info(`${caseName} success`);
252              expectSuccess();
253              done();
254            };
255            tcpServer.off('connect');
256            console.info(`${caseName} test end`);
257            done();
258          });
259        });
260        await tcp.connect(tcpConnectOptions);
261      } catch (err) {
262        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
263        expectFail();
264        console.info(`${caseName} test end`);
265        done();
266      }
267    });
268
269    /* *
270     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0500
271     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0500
272     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16BE; callback
273     * @tc.size  : MediumTest
274     * @tc.type  : Function
275     * @tc.level : level 2
276     */
277    it('testNetworkMgrSocketTCPSocketConnectionSend0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
278      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0500';
279      try {
280        console.info(`${caseName} test start`);
281        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
282        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
283        let listenAddress: socket.NetAddress = {
284          address: '127.0.0.1',
285          port: 8006,
286          family: 1
287        };
288        await tcpServer.listen(listenAddress);
289        let tcpConnectOptions: socket.TCPConnectOptions = {
290          address: listenAddress
291        };
292        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
293          let tcpSendOption: socket.TCPSendOptions = {
294            data: 'Hello, client!',
295            encoding: 'UTF-16BE'
296          };
297          client.send(tcpSendOption, (err: BusinessError) => {
298            if (err) {
299              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
300              expectFail();
301              done();
302            } else {
303              console.info(`${caseName} success`);
304              expectSuccess();
305              done();
306            };
307            tcpServer.off('connect');
308            console.info(`${caseName} test end`);
309            done();
310          });
311        });
312        await tcp.connect(tcpConnectOptions);
313      } catch (err) {
314        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
315        expectFail();
316        console.info(`${caseName} test end`);
317        done();
318      }
319    });
320
321    /* *
322     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0600
323     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0600
324     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16LE; callback
325     * @tc.size  : MediumTest
326     * @tc.type  : Function
327     * @tc.level : level 2
328     */
329    it('testNetworkMgrSocketTCPSocketConnectionSend0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
330      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0600';
331      try {
332        console.info(`${caseName} test start`);
333        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
334        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
335        let listenAddress: socket.NetAddress = {
336          address: '127.0.0.1',
337          port: 8008,
338          family: 1
339        };
340        await tcpServer.listen(listenAddress);
341        let tcpConnectOptions: socket.TCPConnectOptions = {
342          address: listenAddress
343        };
344        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
345          let tcpSendOption: socket.TCPSendOptions = {
346            data: 'Hello, client!',
347            encoding: 'UTF-16LE'
348          };
349          client.send(tcpSendOption, (err: BusinessError) => {
350            if (err) {
351              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
352              expectFail();
353              done();
354            } else {
355              console.info(`${caseName} success`);
356              expectSuccess();
357              done();
358            };
359            tcpServer.off('connect');
360            console.info(`${caseName} test end`);
361            done();
362          });
363        });
364        await tcp.connect(tcpConnectOptions);
365      } catch (err) {
366        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
367        expectFail();
368        console.info(`${caseName} test end`);
369        done();
370      }
371    });
372
373    /* *
374     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0700
375     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0700
376     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16; callback
377     * @tc.size  : MediumTest
378     * @tc.type  : Function
379     * @tc.level : level 0
380     */
381    it('testNetworkMgrSocketTCPSocketConnectionSend0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => {
382      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0700';
383      try {
384        console.info(`${caseName} test start`);
385        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
386        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
387        let listenAddress: socket.NetAddress = {
388          address: '127.0.0.1',
389          port: 8009,
390          family: 1
391        };
392        await tcpServer.listen(listenAddress);
393        let tcpConnectOptions: socket.TCPConnectOptions = {
394          address: listenAddress
395        };
396        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
397          let tcpSendOption: socket.TCPSendOptions = {
398            data: 'Hello, client!',
399            encoding: 'UTF-16'
400          };
401          client.send(tcpSendOption, (err: BusinessError) => {
402            if (err) {
403              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
404              expectFail();
405              done();
406            } else {
407              console.info(`${caseName} success`);
408              expectSuccess();
409              done();
410            };
411            tcpServer.off('connect');
412            console.info(`${caseName} test end`);
413            done();
414          });
415        });
416        await tcp.connect(tcpConnectOptions);
417      } catch (err) {
418        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
419        expectFail();
420        console.info(`${caseName} test end`);
421        done();
422      }
423    });
424
425    /* *
426     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0800
427     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0800
428     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is US-AECII; callback
429     * @tc.size  : MediumTest
430     * @tc.type  : Function
431     * @tc.level : level 2
432     */
433    it('testNetworkMgrSocketTCPSocketConnectionSend0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
434      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0800';
435      try {
436        console.info(`${caseName} test start`);
437        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
438        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
439        let listenAddress: socket.NetAddress = {
440          address: '127.0.0.1',
441          port: 8010,
442          family: 1
443        };
444        await tcpServer.listen(listenAddress);
445        let tcpConnectOptions: socket.TCPConnectOptions = {
446          address: listenAddress
447        };
448        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
449          let tcpSendOption: socket.TCPSendOptions = {
450            data: 'Hello, client!',
451            encoding: 'US-AECII'
452          };
453          client.send(tcpSendOption, (err: BusinessError) => {
454            if (err) {
455              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
456              expectFail();
457              done();
458            } else {
459              console.info(`${caseName} success`);
460              expectSuccess();
461              done();
462            };
463            tcpServer.off('connect');
464            console.info(`${caseName} test end`);
465            done();
466          });
467        });
468        await tcp.connect(tcpConnectOptions);
469      } catch (err) {
470        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
471        expectFail();
472        console.info(`${caseName} test end`);
473        done();
474      }
475    });
476
477    /* *
478     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_0900
479     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend0900
480     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is ISO-8859-1; callback
481     * @tc.size  : MediumTest
482     * @tc.type  : Function
483     * @tc.level : level 0
484     */
485    it('testNetworkMgrSocketTCPSocketConnectionSend0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => {
486      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend0900';
487      try {
488        console.info(`${caseName} test start`);
489        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
490        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
491        let listenAddress: socket.NetAddress = {
492          address: '127.0.0.1',
493          port: 8099,
494          family: 1
495        };
496        await tcpServer.listen(listenAddress);
497        let tcpConnectOptions: socket.TCPConnectOptions = {
498          address: listenAddress
499        };
500        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
501          let tcpSendOption: socket.TCPSendOptions = {
502            data: 'Hello, client!',
503            encoding: 'ISO-8859-1'
504          };
505          client.send(tcpSendOption, (err: BusinessError) => {
506            if (err) {
507              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
508              expectFail();
509              done();
510            } else {
511              console.info(`${caseName} success`);
512              expectSuccess();
513              done();
514            };
515            tcpServer.off('connect');
516            console.info(`${caseName} test end`);
517            done();
518          });
519        });
520        await tcp.connect(tcpConnectOptions);
521      } catch (err) {
522        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
523        expectFail();
524        console.info(`${caseName} test end`);
525        done();
526      }
527    });
528
529    /* *
530     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1000
531     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1000
532     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is GB2312; callback
533     * @tc.size  : MediumTest
534     * @tc.type  : Function
535     * @tc.level : level 2
536     */
537    it('testNetworkMgrSocketTCPSocketConnectionSend1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
538      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1000';
539      try {
540        console.info(`${caseName} test start`);
541        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
542        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
543        let listenAddress: socket.NetAddress = {
544          address: '127.0.0.1',
545          port: 8011,
546          family: 1
547        };
548        await tcpServer.listen(listenAddress);
549        let tcpConnectOptions: socket.TCPConnectOptions = {
550          address: listenAddress
551        };
552        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
553          let tcpSendOption: socket.TCPSendOptions = {
554            data: 'Hello, client!',
555            encoding: 'GB2312'
556          };
557          client.send(tcpSendOption, (err: BusinessError) => {
558            if (err) {
559              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
560              expectFail();
561              done();
562            } else {
563              console.info(`${caseName} success`);
564              expectSuccess();
565              done();
566            };
567            tcpServer.off('connect');
568            console.info(`${caseName} test end`);
569            done();
570          });
571        });
572        await tcp.connect(tcpConnectOptions);
573      } catch (err) {
574        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
575        expectFail();
576        console.info(`${caseName} test end`);
577        done();
578      }
579    });
580
581    /* *
582     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1100
583     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1100
584     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is undefined; callback
585     * @tc.size  : MediumTest
586     * @tc.type  : Function
587     * @tc.level : level 2
588     */
589    it('testNetworkMgrSocketTCPSocketConnectionSend1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
590      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1100';
591      try {
592        console.info(`${caseName} test start`);
593        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
594        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
595        let listenAddress: socket.NetAddress = {
596          address: '127.0.0.1',
597          port: 8012,
598          family: 1
599        };
600        await tcpServer.listen(listenAddress);
601        let tcpConnectOptions: socket.TCPConnectOptions = {
602          address: listenAddress
603        };
604        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
605          let tcpSendOption: socket.TCPSendOptions = {
606            data: 'Hello, client!',
607            encoding: undefined
608          };
609          client.send(tcpSendOption, (err: BusinessError) => {
610            if (err) {
611              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
612              expectFail();
613              done();
614            } else {
615              console.info(`${caseName} success`);
616              expectSuccess();
617              done();
618            };
619            tcpServer.off('connect');
620            console.info(`${caseName} test end`);
621            done();
622          });
623        });
624        await tcp.connect(tcpConnectOptions);
625      } catch (err) {
626        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
627        expectFail();
628        console.info(`${caseName} test end`);
629        done();
630      }
631    });
632
633    /* *
634     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1200
635     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1200
636     * @tc.desc  : Sending data through TCP Socket Connection connection,Sending data as a string; promise
637     * @tc.size  : MediumTest
638     * @tc.type  : Function
639     * @tc.level : level 2
640     */
641    it('testNetworkMgrSocketTCPSocketConnectionSend1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
642      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1200';
643      try {
644        console.info(`${caseName} test start`);
645        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
646        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
647        let listenAddress: socket.NetAddress = {
648          address: '127.0.0.1',
649          port: 8013,
650          family: 1
651        };
652        await tcpServer.listen(listenAddress);
653        let tcpConnectOptions: socket.TCPConnectOptions = {
654          address: listenAddress
655        };
656        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
657          let tcpSendOption: socket.TCPSendOptions = {
658            data: 'Hello, client!'
659          };
660          client.send(tcpSendOption).then(() => {
661            console.info(`${caseName} success`);
662            expectSuccess();
663            done();
664          }).catch((err: BusinessError) => {
665            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
666            expectFail();
667            done();
668          }).finally(() => {
669            tcpServer.off('connect');
670            console.info(`${caseName} test end`);
671            done();
672          });
673        });
674        await tcp.connect(tcpConnectOptions);
675      } catch (err) {
676        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
677        expectFail();
678        console.info(`${caseName} test end`);
679        done();
680      }
681    });
682
683    /* *
684     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1300
685     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1300
686     * @tc.desc  : Sending data through TCP Socket Connection connection,input parameter type is arrayBuffer; promise
687     * @tc.size  : MediumTest
688     * @tc.type  : Function
689     * @tc.level : level 2
690     */
691    it('testNetworkMgrSocketTCPSocketConnectionSend1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
692      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1300';
693      try {
694        console.info(`${caseName} test start`);
695        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
696        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
697        let listenAddress: socket.NetAddress = {
698          address: '127.0.0.1',
699          port: 8016,
700          family: 1
701        };
702        await tcpServer.listen(listenAddress);
703        let tcpConnectOptions: socket.TCPConnectOptions = {
704          address: listenAddress
705        };
706        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
707          let tcpSendOption: socket.TCPSendOptions = {
708            data: new ArrayBuffer(234)
709          };
710          client.send(tcpSendOption).then(() => {
711            console.info(`${caseName} success`);
712            expectSuccess();
713            done();
714          }).catch((err: BusinessError) => {
715            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
716            expectFail();
717            done();
718          }).finally(() => {
719            tcpServer.off('connect');
720            console.info(`${caseName} test end`);
721            done();
722          });
723        });
724        await tcp.connect(tcpConnectOptions);
725      } catch (err) {
726        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
727        expectFail();
728        console.info(`${caseName} test end`);
729        done();
730      }
731    });
732
733    /* *
734     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1400
735     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1400
736     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is an empty string; promise
737     * @tc.size  : MediumTest
738     * @tc.type  : Function
739     * @tc.level : level 2
740     */
741    it('testNetworkMgrSocketTCPSocketConnectionSend1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
742      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1400';
743      try {
744        console.info(`${caseName} test start`);
745        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
746        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
747        let listenAddress: socket.NetAddress = {
748          address: '127.0.0.1',
749          port: 8017,
750          family: 1
751        };
752        await tcpServer.listen(listenAddress);
753        let tcpConnectOptions: socket.TCPConnectOptions = {
754          address: listenAddress
755        };
756        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
757          let tcpSendOption: socket.TCPSendOptions = {
758            data: 'Hello, client!',
759            encoding: ''
760          };
761          client.send(tcpSendOption).then(() => {
762            console.info(`${caseName} success`);
763            expectSuccess();
764            done();
765          }).catch((err: BusinessError) => {
766            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
767            expectFail();
768            done();
769          }).finally(() => {
770            tcpServer.off('connect');
771            console.info(`${caseName} test end`);
772            done();
773          });
774        });
775        await tcp.connect(tcpConnectOptions);
776      } catch (err) {
777        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
778        expectFail();
779        console.info(`${caseName} test end`);
780        done();
781      }
782    });
783
784    /* *
785     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1500
786     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1500
787     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-8; promise
788     * @tc.size  : MediumTest
789     * @tc.type  : Function
790     * @tc.level : level 2
791     */
792    it('testNetworkMgrSocketTCPSocketConnectionSend1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
793      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1500';
794      try {
795        console.info(`${caseName} test start`);
796        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
797        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
798        let listenAddress: socket.NetAddress = {
799          address: '127.0.0.1',
800          port: 8018,
801          family: 1
802        };
803        await tcpServer.listen(listenAddress);
804        let tcpConnectOptions: socket.TCPConnectOptions = {
805          address: listenAddress
806        };
807        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
808          let tcpSendOption: socket.TCPSendOptions = {
809            data: 'Hello, client!',
810            encoding: 'UTF-8'
811          };
812          client.send(tcpSendOption).then(() => {
813            console.info(`${caseName} success`);
814            expectSuccess();
815            done();
816          }).catch((err: BusinessError) => {
817            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
818            expectFail();
819            done();
820          }).finally(() => {
821            tcpServer.off('connect');
822            console.info(`${caseName} test end`);
823            done();
824          });
825        });
826        await tcp.connect(tcpConnectOptions);
827      } catch (err) {
828        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
829        expectFail();
830        console.info(`${caseName} test end`);
831        done();
832      }
833    });
834
835    /* *
836     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1600
837     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1600
838     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16BE; promise
839     * @tc.size  : MediumTest
840     * @tc.type  : Function
841     * @tc.level : level 2
842     */
843    it('testNetworkMgrSocketTCPSocketConnectionSend1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
844      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1600';
845      try {
846        console.info(`${caseName} test start`);
847        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
848        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
849        let listenAddress: socket.NetAddress = {
850          address: '127.0.0.1',
851          port: 8019,
852          family: 1
853        };
854        await tcpServer.listen(listenAddress);
855        let tcpConnectOptions: socket.TCPConnectOptions = {
856          address: listenAddress
857        };
858        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
859          let tcpSendOption: socket.TCPSendOptions = {
860            data: 'Hello, client!',
861            encoding: 'UTF-16BE'
862          };
863          client.send(tcpSendOption).then(() => {
864            console.info(`${caseName} success`);
865            expectSuccess();
866            done();
867          }).catch((err: BusinessError) => {
868            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
869            expectFail();
870            done();
871          }).finally(() => {
872            tcpServer.off('connect');
873            console.info(`${caseName} test end`);
874            done();
875          });
876        });
877        await tcp.connect(tcpConnectOptions);
878      } catch (err) {
879        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
880        expectFail();
881        console.info(`${caseName} test end`);
882        done();
883      }
884    });
885
886    /* *
887     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1700
888     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1700
889     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16LE; promise
890     * @tc.size  : MediumTest
891     * @tc.type  : Function
892     * @tc.level : level 2
893     */
894    it('testNetworkMgrSocketTCPSocketConnectionSend1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
895      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1700';
896      try {
897        console.info(`${caseName} test start`);
898        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
899        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
900        let listenAddress: socket.NetAddress = {
901          address: '127.0.0.1',
902          port: 8021,
903          family: 1
904        };
905        await tcpServer.listen(listenAddress);
906        let tcpConnectOptions: socket.TCPConnectOptions = {
907          address: listenAddress
908        };
909        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
910          let tcpSendOption: socket.TCPSendOptions = {
911            data: 'Hello, client!',
912            encoding: 'UTF-16LE'
913          };
914          client.send(tcpSendOption).then(() => {
915            console.info(`${caseName} success`);
916            expectSuccess();
917            done();
918          }).catch((err: BusinessError) => {
919            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
920            expectFail();
921            done();
922          }).finally(() => {
923            tcpServer.off('connect');
924            console.info(`${caseName} test end`);
925            done();
926          });
927        });
928        await tcp.connect(tcpConnectOptions);
929      } catch (err) {
930        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
931        expectFail();
932        console.info(`${caseName} test end`);
933        done();
934      }
935    });
936
937    /* *
938     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1800
939     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1800
940     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is UTF-16; promise
941     * @tc.size  : MediumTest
942     * @tc.type  : Function
943     * @tc.level : level 2
944     */
945    it('testNetworkMgrSocketTCPSocketConnectionSend1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
946      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1800';
947      try {
948        console.info(`${caseName} test start`);
949        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
950        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
951        let listenAddress: socket.NetAddress = {
952          address: '127.0.0.1',
953          port: 8022,
954          family: 1
955        };
956        await tcpServer.listen(listenAddress);
957        let tcpConnectOptions: socket.TCPConnectOptions = {
958          address: listenAddress
959        };
960        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
961          let tcpSendOption: socket.TCPSendOptions = {
962            data: 'Hello, client!',
963            encoding: 'UTF-16'
964          };
965          client.send(tcpSendOption).then(() => {
966            console.info(`${caseName} success`);
967            expectSuccess();
968            done();
969          }).catch((err: BusinessError) => {
970            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
971            expectFail();
972            done();
973          }).finally(() => {
974            tcpServer.off('connect');
975            console.info(`${caseName} test end`);
976            done();
977          });
978        });
979        await tcp.connect(tcpConnectOptions);
980      } catch (err) {
981        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
982        expectFail();
983        console.info(`${caseName} test end`);
984        done();
985      }
986    });
987
988    /* *
989     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_1900
990     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend1900
991     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is US-AECII;promise
992     * @tc.size  : MediumTest
993     * @tc.type  : Function
994     * @tc.level : level 2
995     */
996    it('testNetworkMgrSocketTCPSocketConnectionSend1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
997      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend1900';
998      try {
999        console.info(`${caseName} test start`);
1000        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1001        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1002        let listenAddress: socket.NetAddress = {
1003          address: '127.0.0.1',
1004          port: 8023,
1005          family: 1
1006        };
1007        await tcpServer.listen(listenAddress);
1008        let tcpConnectOptions: socket.TCPConnectOptions = {
1009          address: listenAddress
1010        };
1011        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
1012          let tcpSendOption: socket.TCPSendOptions = {
1013            data: 'Hello, client!',
1014            encoding: 'US-AECII'
1015          };
1016          client.send(tcpSendOption).then(() => {
1017            console.info(`${caseName} success`);
1018            expectSuccess();
1019            done();
1020          }).catch((err: BusinessError) => {
1021            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1022            expectFail();
1023            done();
1024          }).finally(() => {
1025            tcpServer.off('connect');
1026            console.info(`${caseName} test end`);
1027            done();
1028          });
1029        });
1030        await tcp.connect(tcpConnectOptions);
1031      } catch (err) {
1032        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1033        expectFail();
1034        console.info(`${caseName} test end`);
1035        done();
1036      }
1037    });
1038
1039    /* *
1040     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_2000
1041     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend2000
1042     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is ISO-8859-1;promise
1043     * @tc.size  : MediumTest
1044     * @tc.type  : Function
1045     * @tc.level : level 2
1046     */
1047    it('testNetworkMgrSocketTCPSocketConnectionSend2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1048      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend2000';
1049      try {
1050        console.info(`${caseName} test start`);
1051        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1052        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1053        let listenAddress: socket.NetAddress = {
1054          address: '127.0.0.1',
1055          port: 9023,
1056          family: 1
1057        };
1058        await tcpServer.listen(listenAddress);
1059        let tcpConnectOptions: socket.TCPConnectOptions = {
1060          address: listenAddress
1061        };
1062        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
1063          let tcpSendOption: socket.TCPSendOptions = {
1064            data: 'Hello, client!',
1065            encoding: 'US-AECII'
1066          };
1067          client.send(tcpSendOption).then(() => {
1068            console.info(`${caseName} success`);
1069            expectSuccess();
1070            done();
1071          }).catch((err: BusinessError) => {
1072            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1073            expectFail();
1074            done();
1075          }).finally(() => {
1076            tcpServer.off('connect');
1077            console.info(`${caseName} test end`);
1078            done();
1079          });
1080        });
1081        await tcp.connect(tcpConnectOptions);
1082      } catch (err) {
1083        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1084        expectFail();
1085        console.info(`${caseName} test end`);
1086        done();
1087      }
1088    });
1089
1090    /* *
1091     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_2100
1092     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend2100
1093     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is GB2312; promise
1094     * @tc.size  : MediumTest
1095     * @tc.type  : Function
1096     * @tc.level : level 2
1097     */
1098    it('testNetworkMgrSocketTCPSocketConnectionSend2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1099      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend2100';
1100      try {
1101        console.info(`${caseName} test start`);
1102        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1103        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1104        let listenAddress: socket.NetAddress = {
1105          address: '127.0.0.1',
1106          port: 8024,
1107          family: 1
1108        };
1109        await tcpServer.listen(listenAddress);
1110        let tcpConnectOptions: socket.TCPConnectOptions = {
1111          address: listenAddress
1112        };
1113        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
1114          let tcpSendOption: socket.TCPSendOptions = {
1115            data: 'Hello, client!',
1116            encoding: 'GB2312'
1117          };
1118          client.send(tcpSendOption).then(() => {
1119            console.info(`${caseName} success`);
1120            expectSuccess();
1121            done();
1122          }).catch((err: BusinessError) => {
1123            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1124            expectFail();
1125            done();
1126          }).finally(() => {
1127            tcpServer.off('connect');
1128            console.info(`${caseName} test end`);
1129            done();
1130          });
1131        });
1132        await tcp.connect(tcpConnectOptions);
1133      } catch (err) {
1134        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1135        expectFail();
1136        console.info(`${caseName} test end`);
1137        done();
1138      }
1139    });
1140
1141    /* *
1142     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Send_2200
1143     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionSend2200
1144     * @tc.desc  : Sending data through TCP Socket Connection connection,Encoding format is undefined; promise
1145     * @tc.size  : MediumTest
1146     * @tc.type  : Function
1147     * @tc.level : level 2
1148     */
1149    it('testNetworkMgrSocketTCPSocketConnectionSend2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1150      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionSend2200';
1151      try {
1152        console.info(`${caseName} test start`);
1153        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1154        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1155        let listenAddress: socket.NetAddress = {
1156          address: '127.0.0.1',
1157          port: 8025,
1158          family: 1
1159        };
1160        await tcpServer.listen(listenAddress);
1161        let tcpConnectOptions: socket.TCPConnectOptions = {
1162          address: listenAddress
1163        };
1164        tcpServer.on('connect', (client: socket.TCPSocketConnection) => {
1165          let tcpSendOption: socket.TCPSendOptions = {
1166            data: 'Hello, client!',
1167            encoding: undefined
1168          };
1169          client.send(tcpSendOption).then(() => {
1170            console.info(`${caseName} success`);
1171            expectSuccess();
1172            done();
1173          }).catch((err: BusinessError) => {
1174            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1175            expectFail();
1176            done();
1177          }).finally(() => {
1178            tcpServer.off('connect');
1179            console.info(`${caseName} test end`);
1180            done();
1181          });
1182        });
1183        await tcp.connect(tcpConnectOptions);
1184      } catch (err) {
1185        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1186        expectFail();
1187        console.info(`${caseName} test end`);
1188        done();
1189      }
1190    });
1191
1192    /* *
1193     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Close_0100
1194     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionClose0100
1195     * @tc.desc  : Close a connection established with TCP Socket; callback
1196     * @tc.size  : MediumTest
1197     * @tc.type  : Function
1198     * @tc.level : level 2
1199     */
1200    it('testNetworkMgrSocketTCPSocketConnectionClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1201      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionClose0100';
1202      try {
1203        console.info(`${caseName} test start`);
1204        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1205        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1206        let listenAddress: socket.NetAddress = {
1207          address: '127.0.0.1',
1208          port: 8026,
1209          family: 1
1210        };
1211        await tcpServer.listen(listenAddress);
1212        let tcpConnectOptions: socket.TCPConnectOptions = {
1213          address: listenAddress
1214        };
1215        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1216          client.close((err: BusinessError) => {
1217            if (err) {
1218              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1219              expectFail();
1220              done();
1221            } else {
1222              console.info(`${caseName} success`);
1223              expectSuccess();
1224              done();
1225            };
1226            tcpServer.off('connect');
1227            console.info(`${caseName} test end`);
1228            done();
1229          });
1230        });
1231        await tcp.connect(tcpConnectOptions);
1232      } catch (err) {
1233        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1234        expectFail();
1235        console.info(`${caseName} test end`);
1236        done();
1237      }
1238    });
1239
1240    /* *
1241     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_Close_0200
1242     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionClose0200
1243     * @tc.desc  : Close a connection established with TCP Socket; promise
1244     * @tc.size  : MediumTest
1245     * @tc.type  : Function
1246     * @tc.level : level 2
1247     */
1248    it('testNetworkMgrSocketTCPSocketConnectionClose0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1249      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionClose0200';
1250      try {
1251        console.info(`${caseName} test start`);
1252        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1253        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1254        let listenAddress: socket.NetAddress = {
1255          address: '127.0.0.1',
1256          port: 8027,
1257          family: 1
1258        };
1259        await tcpServer.listen(listenAddress);
1260        let tcpConnectOptions: socket.TCPConnectOptions = {
1261          address: listenAddress
1262        };
1263        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1264          client.close().then(() => {
1265            console.info(`${caseName} success`);
1266            expectSuccess();
1267            done();
1268          }).catch((err: BusinessError) => {
1269            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1270            expectFail();
1271            done();
1272          }).finally(() => {
1273            tcpServer.off('connect');
1274            console.info(`${caseName} test end`);
1275            done();
1276          });
1277        });
1278        await tcp.connect(tcpConnectOptions);
1279      } catch (err) {
1280        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1281        expectFail();
1282        console.info(`${caseName} test end`);
1283        done();
1284      }
1285    });
1286
1287    /* *
1288     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_GetRemoteAddress_0100
1289     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0100
1290     * @tc.desc  : Get the Opposite Socket Address; callback
1291     * @tc.size  : MediumTest
1292     * @tc.type  : Function
1293     * @tc.level : level 2
1294     */
1295    it('testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1296      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0100';
1297      try {
1298        console.info(`${caseName} test start`);
1299        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1300        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1301        let listenAddress: socket.NetAddress = {
1302          address: '127.0.0.1',
1303          port: 8028,
1304          family: 1
1305        };
1306        await tcpServer.listen(listenAddress);
1307        let tcpConnectOptions: socket.TCPConnectOptions = {
1308          address: listenAddress
1309        };
1310        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1311          client.getRemoteAddress((err: BusinessError, data: socket.NetAddress) => {
1312            if (err) {
1313              console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1314              expectFail();
1315              done();
1316            } else {
1317              console.info(`${caseName} success data:${JSON.stringify(data)}`);
1318              expectSuccess();
1319              done();
1320            };
1321            tcpServer.off('connect');
1322            console.info(`${caseName} test end`);
1323            done();
1324          });
1325        });
1326        await tcp.connect(tcpConnectOptions);
1327      } catch (err) {
1328        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1329        expectFail();
1330        console.info(`${caseName} test end`);
1331        done();
1332      }
1333    });
1334
1335    /* *
1336     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_GetRemoteAddress_0200
1337     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0200
1338     * @tc.desc  : Get the Opposite Socket Address; promise
1339     * @tc.size  : MediumTest
1340     * @tc.type  : Function
1341     * @tc.level : level 2
1342     */
1343    it('testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1344      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionGetRemoteAddress0200';
1345      try {
1346        console.info(`${caseName} test start`);
1347        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1348        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1349        let listenAddress: socket.NetAddress = {
1350          address: '127.0.0.1',
1351          port: 8029,
1352          family: 1
1353        };
1354        await tcpServer.listen(listenAddress);
1355        let tcpConnectOptions: socket.TCPConnectOptions = {
1356          address: listenAddress
1357        };
1358        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1359          client.getRemoteAddress().then((data: socket.NetAddress) => {
1360            console.info(`${caseName} success data:${JSON.stringify(data)}`);
1361            expectSuccess();
1362            done();
1363          }).catch((err: BusinessError) => {
1364            console.info(`${caseName} fail err:${JSON.stringify(err)}`);
1365            expectFail();
1366            done();
1367          }).finally(() => {
1368            tcpServer.off('connect');
1369            console.info(`${caseName} test end`);
1370            done();
1371          });
1372        });
1373        await tcp.connect(tcpConnectOptions);
1374      } catch (err) {
1375        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1376        expectFail();
1377        console.info(`${caseName} test end`);
1378        done();
1379      }
1380    });
1381
1382    /* *
1383     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_OffMessage_0100
1384     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionOffMessage0100
1385     * @tc.desc  : UnSubscription to receive message events for TCPSocketConnection connections
1386     * @tc.size  : MediumTest
1387     * @tc.type  : Function
1388     * @tc.level : level 2
1389     */
1390    it('testNetworkMgrSocketTCPSocketConnectionOffMessage0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1391      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionOffMessage0100';
1392      try {
1393        console.info(`${caseName} test start`);
1394        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1395        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1396        let listenAddress: socket.NetAddress = {
1397          address: '127.0.0.1',
1398          port: 8031,
1399          family: 1
1400        };
1401        await tcpServer.listen(listenAddress);
1402        let tcpConnectOptions: socket.TCPConnectOptions = {
1403          address: listenAddress
1404        };
1405        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1406          let clientSendOptions: socket.TCPSendOptions = {
1407            data: 'Hello, server!'
1408          };
1409          const callback: Callback<socket.SocketMessageInfo> = () => {
1410            expectFail();
1411            console.info(`${caseName} test end`);
1412            done();
1413          };
1414          client.on('message', callback);
1415          client.off('message', callback);
1416          await tcp.send(clientSendOptions);
1417          await client.close();
1418          expectSuccess();
1419          done();
1420        });
1421        await tcp.connect(tcpConnectOptions);
1422      } catch (err) {
1423        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1424        expectFail();
1425        console.info(`${caseName} test end`);
1426        done();
1427      }
1428    });
1429
1430    /* *
1431     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_OffMessage_0200
1432     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionOffMessage0200
1433     * @tc.desc  : Cancel multiple subscriptions to receive message events for TCP Socket Connection connections
1434     * @tc.size  : MediumTest
1435     * @tc.type  : Function
1436     * @tc.level : level 2
1437     */
1438    it('testNetworkMgrSocketTCPSocketConnectionOffMessage0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1439      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionOffMessage0200';
1440      try {
1441        console.info(`${caseName} test start`);
1442        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1443        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1444        let listenAddress: socket.NetAddress = {
1445          address: '127.0.0.1',
1446          port: 8032,
1447          family: 1
1448        };
1449        await tcpServer.listen(listenAddress);
1450        let tcpConnectOptions: socket.TCPConnectOptions = {
1451          address: listenAddress
1452        };
1453        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1454          let clientSendOptions: socket.TCPSendOptions = {
1455            data: 'Hello, server!'
1456          };
1457          const callback1: Callback<socket.SocketMessageInfo> = () => {
1458            expectFail();
1459            console.info(`${caseName} test end`);
1460            done();
1461          };
1462          const callback2: Callback<socket.SocketMessageInfo> = () => {
1463            expectFail();
1464            console.info(`${caseName} test end`);
1465            done();
1466          };
1467          client.on('message', callback1);
1468          client.on('message', callback2);
1469          client.off('message');
1470          await tcp.send(clientSendOptions);
1471          await client.close();
1472          expectSuccess();
1473          done();
1474        });
1475        await tcp.connect(tcpConnectOptions);
1476      } catch (err) {
1477        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1478        expectFail();
1479        console.info(`${caseName} test end`);
1480        done();
1481      }
1482    });
1483
1484    /* *
1485     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_OnClose_0100
1486     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionOnClose0100
1487     * @tc.desc  : Subscription to the closure event of TCPSocketConnection
1488     * @tc.size  : MediumTest
1489     * @tc.type  : Function
1490     * @tc.level : level 2
1491     */
1492    it('testNetworkMgrSocketTCPSocketConnectionOnClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1493      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionOnClose0100';
1494      try {
1495        console.info(`${caseName} test start`);
1496        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1497        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1498        let listenAddress: socket.NetAddress = {
1499          address: '127.0.0.1',
1500          port: 8033,
1501          family: 1
1502        };
1503        await tcpServer.listen(listenAddress);
1504        let tcpConnectOptions: socket.TCPConnectOptions = {
1505          address: listenAddress
1506        };
1507        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1508          const callback: Callback<void> = () => {
1509            expectSuccess();
1510            tcpServer.off('connect');
1511            console.info(`${caseName} test end`);
1512            done();
1513          };
1514          client.on('close', callback);
1515          await client.close();
1516          console.info(`${caseName} test end`);
1517          done();
1518        });
1519        await tcp.connect(tcpConnectOptions);
1520      } catch (err) {
1521        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1522        expectFail();
1523        console.info(`${caseName} test end`);
1524        done();
1525      }
1526    });
1527
1528    /* *
1529     * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_OffClose_0100
1530     * @tc.name  : testNetworkMgrSocketTCPSocketConnectionOffClose0100
1531     * @tc.desc  : UnSubscription to the closure event of TCPSocketConnection
1532     * @tc.size  : MediumTest
1533     * @tc.type  : Function
1534     * @tc.level : level 2
1535     */
1536    it('testNetworkMgrSocketTCPSocketConnectionOffClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1537      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionOffClose0100';
1538      try {
1539        console.info(`${caseName} test start`);
1540        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1541        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1542        let listenAddress: socket.NetAddress = {
1543          address: '127.0.0.1',
1544          port: 8034,
1545          family: 1
1546        };
1547        await tcpServer.listen(listenAddress);
1548        let tcpConnectOptions: socket.TCPConnectOptions = {
1549          address: listenAddress
1550        };
1551        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1552          const callback: Callback<void> = () => {
1553            expectFail();
1554            tcpServer.off('connect');
1555            console.info(`${caseName} test end`);
1556            done();
1557          };
1558          client.on('close', callback);
1559          client.off('close', callback);
1560          await client.close();
1561          expectSuccess();
1562          console.info(`${caseName} test end`);
1563          done();
1564        });
1565        await tcp.connect(tcpConnectOptions);
1566      } catch (err) {
1567        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1568        expectFail();
1569        console.info(`${caseName} test end`);
1570        done();
1571      }
1572    });
1573
1574    /* *
1575      * @tc.number: SUB_NetworkMgr_Socket_TCPSocketConnection_OffClose_0200
1576      * @tc.name  : testNetworkMgrSocketTCPSocketConnectionOffClose0200
1577      * @tc.desc  : Cancel multiple subscriptions to the TCP Socket Connection shutdown event
1578      * @tc.size  : MediumTest
1579      * @tc.type  : Function
1580      * @tc.level : level 2
1581      */
1582    it('testNetworkMgrSocketTCPSocketConnectionOffClose0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done: Function) => {
1583      let caseName: string = 'testNetworkMgrSocketTCPSocketConnectionOffClose0200';
1584      try {
1585        console.info(`${caseName} test start`);
1586        let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
1587        let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
1588        let listenAddress: socket.NetAddress = {
1589          address: '127.0.0.1',
1590          port: 8035,
1591          family: 1
1592        };
1593        await tcpServer.listen(listenAddress);
1594        let tcpConnectOptions: socket.TCPConnectOptions = {
1595          address: listenAddress
1596        };
1597        tcpServer.on('connect', async (client: socket.TCPSocketConnection) => {
1598          const callback1: Callback<void> = () => {
1599            expectFail();
1600            tcpServer.off('connect');
1601            console.info(`${caseName} test end`);
1602            done();
1603          };
1604          const callback2: Callback<void> = () => {
1605            expectFail();
1606            tcpServer.off('connect');
1607            console.info(`${caseName} test end`);
1608            done();
1609          };
1610          client.on('close', callback1);
1611          client.on('close', callback2);
1612          client.off('close');
1613          await client.close();
1614          expectSuccess();
1615          console.info(`${caseName} test end`);
1616          done();
1617        });
1618        await tcp.connect(tcpConnectOptions);
1619      } catch (err) {
1620        console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`);
1621        expectFail();
1622        console.info(`${caseName} test end`);
1623        done();
1624      }
1625    });
1626  })
1627}