diff --git a/telephony/BUILD.gn b/telephony/BUILD.gn index f81255a935b6ad8fdec22d636958dafe100077d2..03ca2ec4fca5022379d8906db647bc595ee74ece 100644 --- a/telephony/BUILD.gn +++ b/telephony/BUILD.gn @@ -15,6 +15,7 @@ group("telephony") { testonly = true deps = [ "crossplatform:crossplatform", + "crossplatform/socket:ActsCrossplatformSocketTest", "crossplatform/telephony_http_test:ActsCrossplatformTelephonyHttpEtsTest", "telephonyjstest:telephonyjstest", ] diff --git a/telephony/crossplatform/socket/AppScope/app.json b/telephony/crossplatform/socket/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..626f23296f0fc0626644affe18eb3eca5b0061fe --- /dev/null +++ b/telephony/crossplatform/socket/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.crossplatform.socket.normal", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/telephony/crossplatform/socket/AppScope/resources/base/element/string.json b/telephony/crossplatform/socket/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/telephony/crossplatform/socket/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/telephony/crossplatform/socket/AppScope/resources/base/media/app_icon.png b/telephony/crossplatform/socket/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/crossplatform/socket/AppScope/resources/base/media/app_icon.png differ diff --git a/telephony/crossplatform/socket/BUILD.gn b/telephony/crossplatform/socket/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dc06d309d2d604130205013c8271196d53bfc376 --- /dev/null +++ b/telephony/crossplatform/socket/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsCrossplatformSocketTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsCrossplatformSocketTest" + part_name = "netstack" + subsystem_name = "communication" +} +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + sources = [ "src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "src/main/module.json" +} diff --git a/telephony/crossplatform/socket/Test.json b/telephony/crossplatform/socket/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..5fc35257df13764290ec19e56c546b2b2ed74561 --- /dev/null +++ b/telephony/crossplatform/socket/Test.json @@ -0,0 +1,20 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "ohos.acts.crossplatform.socket.normal", + "module-name": "entry_test", + "testcase-timeout": 15000 + }, + "kits": [ + { + "test-file-name": [ + "ActsCrossplatformSocketTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/signature/openharmony_sx.p7b b/telephony/crossplatform/socket/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..1d258bf52f2306c180b18c682dbd59b48bc4fee5 Binary files /dev/null and b/telephony/crossplatform/socket/signature/openharmony_sx.p7b differ diff --git a/telephony/crossplatform/socket/src/main/ets/TestAbility/TestAbility.ets b/telephony/crossplatform/socket/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb027d69256099790b95a32b446978bbc64b4ecb --- /dev/null +++ b/telephony/crossplatform/socket/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('TestAbility/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/ets/TestAbility/pages/Index.ets b/telephony/crossplatform/socket/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8cbc4b3b96d8d38bc36fbd9a3173d3fd4f09db73 --- /dev/null +++ b/telephony/crossplatform/socket/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/telephony/crossplatform/socket/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/telephony/crossplatform/socket/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/ets/test/List.test.ets b/telephony/crossplatform/socket/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f9042682af5866dc65cb169996b23bb67c7e1a9 --- /dev/null +++ b/telephony/crossplatform/socket/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import socketTest from './socket.testerror' + +export default function testsuite() { + socketTest(); +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/ets/test/socket.testerror.ets b/telephony/crossplatform/socket/src/main/ets/test/socket.testerror.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee140dc77bf330c4ea00143fe4375510d6a78e88 --- /dev/null +++ b/telephony/crossplatform/socket/src/main/ets/test/socket.testerror.ets @@ -0,0 +1,1347 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import socket from '@ohos.net.socket' + +function toString(obj) { + return JSON.stringify(obj); +} +const localIpAdress = '192.168.1.101'; +const localIpAdressError = '192.168.1.501' +let serverIpAddress: string = "192.168.1.100"; +let serverIpAddressError: string = "192.168.1.600"; + +function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); +} + +export default function socketTest() { + + describe('socketTest', function () { + + beforeAll(function (){ + console.log("************* socket Test start*************"); + }) + let envReady = false; + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_TCP_ERROR_002 + * @tc.name : test_Socket_setExtraOptions_Tcp_Error_002 + * @tc.desc : Set other properties of the TCP Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_Tcp_Error_002', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + let promise = tcp.setExtraOptions({ + keepAlive: true, + OOBInline: true, + TCPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + }); + promise.then(()=>{ + console.log('test_Socket_setExtraOptions_Tcp_Error_002 success' ); + expect(false).assertTrue(); + tcp.close(err => { + expect(err == undefined).assertTrue(); + done(); + }) + }).catch(err=>{ + console.log('test_Socket_setExtraOptions_Tcp_Error_002 err :' + JSON.stringify(err)); + tcp.close(()=>{ + setTimeout(function (){ + done(); + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + },3000) + }) + }) + }); + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_UDP_ERROR_001 + * @tc.name : test_Socket_setExtraOptions_Udp_Error_001 + * @tc.desc : Set other properties of the UDP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_Udp_Error_001', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + try { + udp.setExtraOptions({ + // @ts-ignore + keepAlive: true, + OOBInline: true, + UDPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + }, async err => { + console.log('test_Socket_setExtraOptions_Udp_Error_001' + JSON.stringify(err)); + expect(err.code==2301088).assertTrue(); + udp.close(); + done(); + }); + } catch (err){ + console.log('test_Socket_setExtraOptions_Udp_Error_001 catch'+JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number: TEST_SOCKET_TCP_CONNECT_001 + * @tc.name : test_Socket_Tcp_Connect_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Init_001', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + expect(tcp != null).assertTrue(); + done(); + }) + + /** + * @tc.number: TEST_SOCKET_UDP_CONNECT_001 + * @tc.name : test_Socket_UDP_Connect_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Udp_Init_001', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + expect(udp != null).assertTrue(); + done(); + }) + + /** + * @tc.number: TEST_SOCKET_TLS_CONNECT_001 + * @tc.name : test_Socket_TLS_Connect_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tls_Init_001', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + expect(tls != null).assertTrue(); + done(); + }) + + /** + * @tc.number: TEST_SOCKET_TCP_BIND_001 + * @tc.name : test_Socket_Tcp_Bind_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Bind_001', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + try { + await tcp.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_Tcp_Bind_001 success') + tcp.close(); + done(); + } catch (err) { + console.log('test_Socket_Tcp_Bind_001 error' + JSON.stringify(err)); + expect().assertFail(); + tcp.close(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TCP_BIND_002 + * @tc.name : test_Socket_Tcp_Bind_002 + * @tc.desc : Connect to the specified IP address and port. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Bind_002', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + try{ + let promise = tcp.bind({ address: localIpAdressError, port: 0, family: 1 }); + promise.then(async () => { + console.log('test_Socket_Tcp_Bind_002 bind success'); + tcp.close(); + done(); + })} catch(err) { + console.log('test_Socket_Tcp_Bind_002 bind fail'); + expect().assertFail(); + tcp.close(); + done(); + }; + }) + + /** + * @tc.number: TEST_SOCKET_TCP_CONNECT_001 + * @tc.name : test_Socket_Tcp_Connect_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Connect_Error_001', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + try { + await tcp.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_Tcp_Connect_001 bind success') + tcp.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }, async err => { + console.info('test_Socket_Tcp_Connect_001 err' + JSON.stringify((err))); + expect(err.code == 2301101); + expect(err.message == 'Network unreachable'); + tcp.close(); + done(); + }) + } catch (err) { + console.log('test_Socket_Tcp_Connect_001 error' + JSON.stringify(err)); + expect().assertFail(); + tcp.close(); + done(); + } + }) + + + /** + * @tc.number: TEST_SOCKET_TCP_CONNECT_ERROR_002 + * @tc.name : test_Socket_Tcp_Connect_Error_002 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Connect_Error_002', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + try { + console.log('test_Socket_Tcp_Connect_002 bind success') + tcp.connect({ address: { address: serverIpAddressError, port: 65656, family: 1 }, timeout: 6000 }, async err => { + console.info('test_Socket_Tcp_Connect_002 err' + JSON.stringify((err))); + expect(err.code == 2301088); + expect(err.message == 'Not a socket'); + tcp.close(); + done(); + }) + } catch (err) { + console.log('test_Socket_Tcp_Connect_002 error' + JSON.stringify(err)); + expect().assertFail(); + tcp.close(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TCP_CONNECT_PROMISE_ERROR_001 + * @tc.name : test_Socket_Tcp_Connect_Promise_Error_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Connect_Promise_Error_001', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + try { + await tcp.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_Tcp_Connect_Promise_Error_001 bind success') + let promise = tcp.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }); + promise.catch(async err => { + console.log('test_Socket_Tcp_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect(err.code==2301101); + tcp.close(); + done(); + }) + } catch (err) { + console.log('test_Socket_Tcp_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect().assertFail(); + tcp.close(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TCP_CONNECT_PROMISE_ERROR_002 + * @tc.name : test_Socket_Tcp_Connect_Promise_Error_002 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tcp_Connect_Promise_Error_002', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + try { + console.log('test_Socket_Tcp_Connect_Promise_Error_002 bind success') + let promise = tcp.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }); + promise.catch(async err => { + console.log('test_Socket_Tcp_Connect_Promise_Error_002 error' + JSON.stringify(err)); + expect(err.code==2301088); + tcp.close(); + done(); + }) + } catch (err) { + console.log('test_Socket_Tcp_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: test_Socket_Send_Tcp_Error_001 + * @tc.name : test_Socket_Send_Tcp_Error_001 + * @tc.desc : Send data through the TCP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Tcp_Error_001', 0, function (done) { + let tcp = socket.constructTCPSocketInstance(); + tcp.send({ + data: '你好!123,string' + }, err => { + if(err){ + console.log('test_Socket_Send_Tcp_Error_001 err' + JSON.stringify(err)) + + done(); + }else{ + expect(false).assertTrue(); + done(); + } + }) + }); + + /** + * @tc.number: test_Socket_Send_Tcp_Error_002 + * @tc.name : test_Socket_Send_Tcp_Error_002 + * @tc.desc : Send data through the TCP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Tcp_Error_002', 0, async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + let promise = tcp.send({ + data: '你好!123,string' + }); + promise.catch(err => { + if(err){ + console.log('test_Socket_Send_Tcp_Error_002 err' + JSON.stringify(err)) + + done(); + }else{ + expect(false).assertTrue(); + done(); + } + }) + }); + + /** + * @tc.number: test_Socket_Close_Tcp_Error_001 + * @tc.name : test_Socket_Close_Tcp_Error_001 + * @tc.desc : Send data through the TCP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Tcp_Error_001', 0, function (done) { + + let tcp = socket.constructTCPSocketInstance(); + tcp.close(err => { + console.log('test_Socket_Close_Tcp_Error_001'+JSON.stringify(err)); + expect(err==undefined ).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Close_Tcp_Error_002 + * @tc.name : test_Socket_Close_Tcp_Error_002 + * @tc.desc : Send data through the TCP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Tcp_Error_002', 0, function (done) { + + let tcp = socket.constructTCPSocketInstance(); + let promise = tcp.close(); + promise.then(async (err) => { + console.log('test_Socket_Close_Tcp_Error_002' + JSON.stringify(err)); + expect(err == undefined).assertTrue(); + tcp.close(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_getRemoteAddress_Error_Tcp_001 + * @tc.name : test_Socket_getRemoteAddress_Error_Tcp_001 + * @tc.desc : Obtain the peer socket address. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteAddress_Error_Tcp_001', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + tcp.getRemoteAddress(async (err, data) => { + console.log('test_Socket_getRemoteAddress_Error_Tcp_001' + JSON.stringify(err)); + expect(err.code==2301088); + tcp.close(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_getRemoteAddress_Error_Tcp_002 + * @tc.name : test_Socket_getRemoteAddress_Error_Tcp_002 + * @tc.desc : Obtain the peer socket address. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteAddress_Error_Tcp_002', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + let promise = tcp.getRemoteAddress(); + promise.catch(async err => { + console.log('test_Socket_getRemoteAddress_Error_Tcp_002' + JSON.stringify(err)); + expect(err.code==2301088); + tcp.close(); + done(); + }) + }); + + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_TCP_ERROR_001 + * @tc.name : test_Socket_setExtraOptions_Tcp_Error_001 + * @tc.desc : Set other properties of the TCP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_Tcp_Error_001', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + // @ts-ignore + tcp.setExtraOptions({ + keepAlive: true, + OOBInline: true, + TCPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + },(err)=>{ + if(err){ + console.log('test_Socket_setExtraOptions_Tcp_Error_001 error err :' + JSON.stringify(err)); + expect(err.code == 2301009).assertTrue(); + tcp.close(); + done(); + } else { + console.log('test_Socket_setExtraOptions_Tcp_Error_001 success'); + tcp.close(); + done(); + } + }); + }); + + + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_TCP_001 + * @tc.name : test_Socket_getState_Error_Tcp_001 + * @tc.desc : Obtain the TCPSocket status. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_Tcp_001', 0,async function (done) { + let tcp = socket.constructTCPSocketInstance(); + tcp.getState(async (err, data) => { + console.log("test_Socket_getState_Error_Tcp_001"+JSON.stringify(data)); + expect(err == undefined).assertTrue(); + tcp.close((err)=>{ + if(err){ + console.log('test_Socket_getState_Error_Tcp_002 close err' + JSON.stringify(err)); + done(); + }else { + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + setTimeout(function (){ + done(); + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + },3000) + } + }); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_TCP_001 + * @tc.name : test_Socket_getState_Error_Tcp_001 + * @tc.desc : Obtain the TCPSocket status. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_Tcp_002', 0,async function (done) { + + let tcp = socket.constructTCPSocketInstance(); + let promise = tcp.getState(); + promise.then(async data => { + console.log('test_Socket_getState_Error_Tcp_002' + JSON.stringify(data)); + expect(data != null).assertTrue(); + tcp.close((err)=>{ + if(err){ + console.log('test_Socket_getState_Error_Tcp_002 close err' + JSON.stringify(err)); + tcp.close(); + done(); + }else { + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + setTimeout(function (){ + tcp.close(); + done(); + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + },3000) + } + }); + }) + }); + + + /** + * @tc.number: TEST_SOCKET_UDP_BIND_001 + * @tc.name : test_Socket_Udp_Bind_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Udp_Bind_001', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + try { + await udp.bind({ address: '127.0.0.1', port: 0, family: 1 }); + console.log('test_Socket_Udp_Bind_001 success') + udp.close(); + done(); + } catch (err) { + console.log('test_Socket_Udp_Bind_001 error' + JSON.stringify(err)) + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: test_Socket_Udp_Bind_002 + * @tc.name : test_Socket_Udp_Bind_002 + * @tc.desc : Connect to the specified IP address and port. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Udp_Bind_002', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + try{ + let promise = udp.bind({ address: '127.0.0.1', port: 0, family: 1 }); + promise.then(async () => { + console.log('bind success'); + udp.close(); + done(); + })} catch(err) { + console.log('bind fail'); + expect().assertFail(); + done(); + }; + }) + + /** + * @tc.number: test_Socket_Send_Udp_001 + * @tc.name : test_Socket_Send_Udp_001 + * @tc.desc : Send data through the UDP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Udp_001', 0, async function (done) { + let udp = socket.constructUDPSocketInstance(); + await udp.bind({ address: '127.0.0.1', port: 0, family: 1 }); + udp.send({ + data: '你好!123,string', + address: { + address: '127.0.0.1', + port: 8888, + family: 1 + } + }, async err => { + console.log('test_Socket_Send_Udp_001 err' + JSON.stringify(err)) + expect(err == undefined).assertTrue(); + udp.close(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Send_Udp_Error_002 + * @tc.name : test_Socket_Send_Udp_Error_002 + * @tc.desc : Send data through the UDP Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Udp_002', 0, async function (done) { + + let udp = socket.constructUDPSocketInstance(); + await udp.bind({ address: '127.0.0.1', port: 0, family: 1 }); + let promise = udp.send({ + data: '你好!123,string', + address: { + address: '127.0.0.1', + port: 8888, + family: 1 + } + }); + promise.then(async err => { + console.log('test_Socket_Send_Udp_002' + JSON.stringify(err)); + expect(err == undefined).assertTrue(); + udp.close(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Close_Udp_Error_001 + * @tc.name : test_Socket_Close_Udp_Error_001 + * @tc.desc : Send data through the UDP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Udp_Error_001', 0, function (done) { + + let udp = socket.constructUDPSocketInstance(); + udp.close(err => { + expect(err == undefined).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Close_Udp_Error_002 + * @tc.name : test_Socket_Close_Udp_Error_002 + * @tc.desc : Send data through the UDP Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Udp_Error_002', 0, function (done) { + + let udp = socket.constructUDPSocketInstance(); + let promise = udp.close(); + promise.then((err) => { + console.log('test_Socket_Close_ UDP_Error_002' + JSON.stringify(err)); + expect(err == undefined).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_UDP_001 + * @tc.name : test_Socket_getState_Error_Udp_001 + * @tc.desc : Obtain the UDPSocket status. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_Udp_001', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + udp.getState(async (err, data) => { + expect(err == undefined).assertTrue(); + udp.close(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_UDP_001 + * @tc.name : test_Socket_getState_Error_Udp_001 + * @tc.desc : Obtain the UDPSocket status. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_Udp_002', 0,async function (done) { + let udp = socket.constructUDPSocketInstance(); + let promise=udp.getState(); + promise.then(async data => { + console.log('test_Socket_getState_Error_ UDP_002' + JSON.stringify(data)); + expect(data.isBound == false).assertTrue(); + expect(data.isClose == false).assertTrue(); + expect(data.isConnected == false).assertTrue(); + udp.close((err)=>{ + if(err){ + console.log('test_Socket_getState_Error_Tcp_002 close err' + JSON.stringify(err)); + udp.close(); + done(); + }else { + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + setTimeout(function (){ + udp.close(); + done(); + console.log('test_Socket_getState_Error_Tcp_002 close success' + JSON.stringify(err)); + },3000) + } + }); + }) + }); + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_UDP_ERROR_002 + * @tc.name : test_Socket_setExtraOptions_Udp_Error_002 + * @tc.desc : Set other properties of the UDP Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_Udp_Error_002', 0,async function (done) { + + let udp = socket.constructUDPSocketInstance(); + try { + let promise = udp.setExtraOptions({ + // @ts-ignore + keepAlive: true, + OOBInline: true, + TCPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + }); + promise.then(()=>{ + console.log('test_Socket_setExtraOptions_Udp_Error_002' ); + done(); + }).catch(err=>{ + console.log('test_Socket_setExtraOptions_Udp_Error_002 err :' + JSON.stringify(err)); + expect(err.code == 2301088).assertTrue(); + done(); + }) + }catch (err){ + expect().assertFail(); + done(); + } + }); + + /** + * @tc.number: TEST_SOCKET_TLS_BIND_001 + * @tc.name : test_Socket_Tls_Bind_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tls_Bind_001', 0,async function (done) { + + let udp = socket.constructUDPSocketInstance(); + try { + await udp.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_Udp_Bind_001 success') + done(); + } catch (err) { + console.log('test_Socket_Udp_Bind_001 error' + JSON.stringify(err)) + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: test_Socket_TLS_Bind_002 + * @tc.name : test_Socket_Tls_Bind_002 + * @tc.desc : Connect to the specified IP address and port. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Tls_Bind_002', 0,async function (done) { + + let tls = socket.constructUDPSocketInstance(); + try{ + let promise = tls.bind({ address: localIpAdressError, port: 0, family: 1 }); + promise.then(() => { + console.log('bind success'); + done(); + })} catch(err) { + console.log('bind fail'); + expect().assertFail(); + done(); + }; + }) + + /** + * @tc.number: test_Socket_Close_TLS_Error_001 + * @tc.name : test_Socket_Close_Tls_Error_001 + * @tc.desc : Send data through the Tls Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Tls_Error_001', 0, function (done) { + let tls = socket.constructUDPSocketInstance(); + tls.close(err => { + expect(err == undefined).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Close_TLS_Error_002 + * @tc.name : test_Socket_Close_Tls_Error_002 + * @tc.desc : Send data through the TLS Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Close_Tls_Error_002', 0, function (done) { + let tls = socket.constructUDPSocketInstance(); + let promise = tls.close(); + promise.then((err) => { + console.log('test_Socket_Close_tls_Error_002' + JSON.stringify(err)); + expect(err == undefined).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Send_TLS_Error_001 + * @tc.name : test_Socket_Send_Tls_Error_001 + * @tc.desc : Send data through the Tls Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Tls_Error_001', 0, function (done) { + + let tls = socket.constructUDPSocketInstance(); + tls.send({ + data: '你好!123,string', + address: { + address: serverIpAddressError, + port: 8888, + family: 1 + } + }, err => { + console.log('test_Socket_Send_Tls_Error_001 err' + JSON.stringify(err)) + expect(err.code == 2301032).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: test_Socket_Send_TLS_Error_002 + * @tc.name : test_Socket_Send_Tls_Error_002 + * @tc.desc : Send data through the Tls Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_Send_Tls_Error_002', 0, async function (done) { + + let tls = socket.constructUDPSocketInstance(); + let promise = tls.send({ + data: '你好!123,string', + address: { + address: serverIpAddressError, + port: 8888, + family: 1 + } + }); + + promise.catch(err => { + console.log('test_Socket_Send_Udp_Error_002' + JSON.stringify(err)); + expect(err.code == 2301032).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: TEST_SOCKET_TLS_CONNECT_001 + * @tc.name : test_Socket_tls_Connect_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_tls_Connect_Error_001', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + try { + await tls.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_tls_Connect_001 bind success') + // @ts-ignore + tls.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }, err => { + console.info('test_Socket_tls_Connect_001 err' + JSON.stringify((err))); + expect(err.code == 2301101); + expect(err.message == 'Network unreachable'); + done(); + }) + } catch (err) { + console.log('test_Socket_tls_Connect_001 error' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TLS_CONNECT_ERROR_002 + * @tc.name : test_Socket_tls_Connect_Error_002 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_tls_Connect_Error_002', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + try { + console.log('test_Socket_tls_Connect_002 bind success') + // @ts-ignore + tls.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }, err => { + console.info('test_Socket_tls_Connect_002 err' + JSON.stringify((err))); + expect(err.code == 2301088); + expect(err.message == 'Not a socket'); + done(); + }) + } catch (err) { + console.log('test_Socket_tls_Connect_002 error' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TLS_CONNECT_PROMISE_ERROR_001 + * @tc.name : test_Socket_tls_Connect_Promise_Error_001 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_tls_Connect_Promise_Error_001', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + try { + await tls.bind({ address: localIpAdressError, port: 0, family: 1 }); + console.log('test_Socket_tls_Connect_Promise_Error_001 bind success') + // @ts-ignore + let promise = tls.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }); + promise.catch(err => { + console.log('test_Socket_tls_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect(err.code==2301101); + done(); + }) + } catch (err) { + console.log('test_Socket_tls_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: TEST_SOCKET_TLS_CONNECT_PROMISE_ERROR_002 + * @tc.name : test_Socket_tls_Connect_Promise_Error_002 + * @tc.desc : Connect to the specified IP address and port. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_tls_Connect_Promise_Error_002', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + try { + console.log('test_Socket_tls_Connect_Promise_Error_002 bind success') + // @ts-ignore + let promise = tls.connect({ address: { address: serverIpAddressError, port: 8888, family: 1 }, timeout: 6000 }); + promise.catch(err => { + console.log('test_Socket_tls_Connect_Promise_Error_002 error' + JSON.stringify(err)); + expect(err.code==2301088); + done(); + }) + } catch (err) { + console.log('test_Socket_tls_Connect_Promise_Error_001 error' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number: test_Socket_getRemoteAddress_Error_TLS_001 + * @tc.name : test_Socket_getRemoteAddress_Error_TLS_001 + * @tc.desc : Obtain the peer socket address. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteAddress_Error_TLS_001', 0,async function (done) { + let TLS = socket.constructTLSSocketInstance(); + TLS.getRemoteAddress((err, data) => { + console.log('test_Socket_getRemoteAddress_Error_TLS_001' + JSON.stringify(err)); + expect(err.code==2301088); + done(); + }) + }); + + /** + * @tc.number: test_Socket_getRemoteAddress_Error_TLS_002 + * @tc.name : test_Socket_getRemoteAddress_Error_TLS_002 + * @tc.desc : Obtain the peer socket address. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteAddress_Error_TLS_002', 0,async function (done) { + let TLS = socket.constructTLSSocketInstance(); + let promise = TLS.getRemoteAddress(); + promise.catch(err => { + console.log('test_Socket_getRemoteAddress_Error_TLS_002' + JSON.stringify(err)); + expect(err.code==2301088); + done(); + }) + }); + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_TLS_001 + * @tc.name : test_Socket_getState_Error_TLS_001 + * @tc.desc : Obtain the TLSSocket status. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_TLS_001', 0,async function (done) { + let TLS = socket.constructTLSSocketInstance(); + TLS.getState((err, data) => { + expect(err == undefined).assertTrue(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETSTATE_ERROR_TLS_001 + * @tc.name : test_Socket_getState_Error_TLS_001 + * @tc.desc : Obtain the TLSSocket status. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getState_Error_TLS_002', 0,async function (done) { + let TLS = socket.constructTLSSocketInstance(); + let promise=TLS.getState(); + promise.then(data => { + console.log('test_Socket_getState_Error_TLS_002' + JSON.stringify(data)); + expect(data.isBound == false).assertTrue(); + expect(data.isClose == true).assertTrue(); + expect(data.isConnected == false).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_TLS_ERROR_001 + * @tc.name : test_Socket_setExtraOptions_TLS_Error_001 + * @tc.desc : Set other properties of the TLS Socket connection. Use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_TLS_Error_001', 0,async function (done) { + let TLS = socket.constructTLSSocketInstance(); + TLS.setExtraOptions({ + keepAlive: true, + OOBInline: true, + // @ts-ignore + TLSNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + }, err => { + console.log('test_Socket_setExtraOptions_TLS_Error_001' + JSON.stringify(err)); + expect(err.code == 2303600).assertTrue(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_SETEXTRAOPTIONS_TLS_ERROR_002 + * @tc.name : test_Socket_setExtraOptions_TLS_Error_002 + * @tc.desc : Set other properties of the TLS Socket connection. Use the promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_setExtraOptions_TLS_Error_002', 0,async function (done) { + + let TLS = socket.constructTLSSocketInstance(); + let promise = TLS.setExtraOptions({ + keepAlive: true, + OOBInline: true, + // @ts-ignore + TLSNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, + }); + promise.catch(err => { + console.log('test_Socket_setExtraOptions_Tls_Error_001' + JSON.stringify(err)); + expect(err.code == 2303600).assertTrue(); + done(); + }) + }); + + /** + * @tc.number: TEST_SOCKET_GETCERTIFICATE_TLS_ERROR_001 + * @tc.name : test_Socket_getCertificate_TLS_Error_001 + * @tc.desc : After the TLSSocket communication connection is successful, obtain the local digital certificate. This interface is only applicable for bidirectional authentication, and use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getCertificate_TLS_Error_001', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getCertificate((err, data) => { + if (err) { + console.log("getCertificate callback error = " + JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getCertificate callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETCERTIFICATE_TLS_ERROR_002 + * @tc.name : test_Socket_getCertificate_TLS_Error_002 + * @tc.desc : After the TLSSocket communication connection, obtain the local digital certificate. This interface is only applicable for bidirectional authentication, using the Promise method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getCertificate_TLS_Error_002', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getCertificate((err, data) => { + if (err) { + console.log("getCertificate callback error = " + JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getCertificate callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETREMOTECERTIFICATE_TLS_ERROR_001 + * @tc.name : test_Socket_getRemoteCertificate_TLS_Error_001 + * @tc.desc : After the TLSSocket communication connection is successful, obtain the digital certificate of the server and use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteCertificate_TLS_Error_001', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + tls.getRemoteCertificate((err, data) => { + if (err) { + console.log("getRemoteCertificate callback error = " + JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getRemoteCertificate callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: test_Socket_getRemoteCertificate_TLS_Error_002 + * @tc.name : test_Socket_getRemoteCertificate_TLS_Error_002 + * @tc.desc : After the TLSSocket communication connection is successful, obtain the digital certificate of the server and use the callback method as an asynchronous method. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getRemoteCertificate_TLS_Error_002', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getRemoteCertificate().then(data => { + // @ts-ignore + console.log('test_Socket_getRemoteCertificate_TLS_Error_002'+data); + done(); + }).catch(err => { + console.error('test_Socket_getRemoteCertificate_TLS_Error_002 catch'+JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETPROTOCOL_TLS_ERROR_001 + * @tc.name : test_Socket_getProtocol_TLS_Error_001 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getProtocol_TLS_Error_001', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + tls.getProtocol((err, data) => { + if (err) { + console.log("getProtocol callback error = " + JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getProtocol callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: test_Socket_GETPROTOCOL_TLS_Error_002 + * @tc.name : test_Socket_getProtocol_TLS_Error_002 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getProtocol_TLS_Error_002', 0,async function (done) { + + let tls = socket.constructTLSSocketInstance(); + tls.getProtocol().then(data => { + console.log(data); + done(); + }).catch(err => { + console.error('test_Socket_getProtocol_TLS_Error_002'+ JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETCIPHERSUITE_TLS_ERROR_001 + * @tc.name : test_Socket_getCipherSuite_TLS_Error_001 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getCipherSuite_TLS_Error_001', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getCipherSuite((err, data) => { + if (err) { + console.log("getCipherSuite callback error = " + JSON.stringify(err)); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getCipherSuite callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: test_Socket_GETCIPHERSUITE_TLS_Error_002 + * @tc.name : test_Socket_getCipherSuite_TLS_Error_002 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getCipherSuite_TLS_Error_002', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getCipherSuite().then(data => { + console.log('getCipherSuite success:' + JSON.stringify(data)); + done(); + }).catch(err => { + console.error(err); + expect(err.code==2303600).assertTrue(); + done(); + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETSIGNATUREALGORITHMS_TLS_ERROR_001 + * @tc.name : test_Socket_getSignatureAlgorithms_TLS_Error_001 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getSignatureAlgorithms_TLS_Error_001', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getSignatureAlgorithms((err, data) => { + if (err) { + console.log("getSignatureAlgorithms callback error = " + err); + expect(err.code==2303600).assertTrue(); + done(); + } else { + console.log("getSignatureAlgorithms callback = " + data); + done(); + } + }); + }); + + /** + * @tc.number: TEST_SOCKET_GETSIGNATUREALGORITHMS_TLS_ERROR_002 + * @tc.name : test_Socket_getSignatureAlgorithms_TLS_Error_002 + * @tc.desc : + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('test_Socket_getSignatureAlgorithms_TLS_Error_002', 0,async function (done) { + let tls = socket.constructTLSSocketInstance(); + tls.getSignatureAlgorithms().then(data => { + console.log("getSignatureAlgorithms success" + data); + done(); + }).catch(err => { + console.error(err); + expect(err.code==2303600).assertTrue(); + done(); + }); + }); + + console.log("************* socket Test end*************"); + + }) +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/module.json b/telephony/crossplatform/socket/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..080e5abe494f60be63e37d1f8bffdc441f5f7c10 --- /dev/null +++ b/telephony/crossplatform/socket/src/main/module.json @@ -0,0 +1,47 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/telephony/crossplatform/socket/src/main/resources/base/element/color.json b/telephony/crossplatform/socket/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/telephony/crossplatform/socket/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/resources/base/element/string.json b/telephony/crossplatform/socket/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/telephony/crossplatform/socket/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/telephony/crossplatform/socket/src/main/resources/base/media/icon.png b/telephony/crossplatform/socket/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/crossplatform/socket/src/main/resources/base/media/icon.png differ diff --git a/telephony/crossplatform/socket/src/main/resources/base/profile/test_pages.json b/telephony/crossplatform/socket/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/telephony/crossplatform/socket/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +}