From 02526510afc17bd72a84720a49fc02ee01547ffe Mon Sep 17 00:00:00 2001 From: hu0475 Date: Sat, 15 Jul 2023 18:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90telephony=E5=AD=90=E7=B3=BB?= =?UTF-8?q?=E7=BB=9FConnection=E6=A8=A1=E5=9D=97=E7=9A=84=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=B5=8B=E8=AF=95=E5=A5=97=20=E5=AE=8C?= =?UTF-8?q?=E6=88=90telephony=E5=AD=90=E7=B3=BB=E7=BB=9FWebSocket=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E8=B7=A8=E5=B9=B3=E5=8F=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hu0475 --- telephony/BUILD.gn | 2 +- .../telephonyConnectionetstest/BUILD.gn | 6 +- .../src/main/ets/test/Connection.test.ets | 72 ++------------- .../telephonyWebSocketetstest/BUILD.gn | 6 +- .../src/main/ets/test/WebSocket.test.ets | 90 ++++++++++++++++++- 5 files changed, 107 insertions(+), 69 deletions(-) diff --git a/telephony/BUILD.gn b/telephony/BUILD.gn index b4de3644f..f81255a93 100644 --- a/telephony/BUILD.gn +++ b/telephony/BUILD.gn @@ -14,8 +14,8 @@ group("telephony") { testonly = true deps = [ - "crossplatform/telephony_http_test:ActsCrossplatformTelephonyHttpEtsTest", "crossplatform:crossplatform", + "crossplatform/telephony_http_test:ActsCrossplatformTelephonyHttpEtsTest", "telephonyjstest:telephonyjstest", ] } diff --git a/telephony/crossplatform/telephonyConnectionetstest/BUILD.gn b/telephony/crossplatform/telephonyConnectionetstest/BUILD.gn index 6f04401f5..6390bc9a9 100644 --- a/telephony/crossplatform/telephonyConnectionetstest/BUILD.gn +++ b/telephony/crossplatform/telephonyConnectionetstest/BUILD.gn @@ -20,6 +20,7 @@ ohos_js_hap_suite("ActsCrossplatformConnectionTest") { ] ets2abc = true certificate_profile = "./signature/openharmony_sx.p7b" + # hap_name: HAP的名字,可选,默认为目标名 hap_name = "ActsCrossplatformConnectionTest" subsystem_name = "communication" @@ -28,6 +29,7 @@ ohos_js_hap_suite("ActsCrossplatformConnectionTest") { ohos_app_scope("windowStage_app_profile") { # app_profile: HAP的AppScope中的app.json,只在Stage模型下使用 app_profile = "AppScope/app.json" + # sources: 资源文件路径 sources = [ "AppScope/resources" ] } @@ -38,8 +40,10 @@ ohos_js_assets("windowStage_js_assets") { ohos_resources("windowStage_resources") { # sources: 资源文件路径 sources = [ "src/main/resources" ] + # deps: 当前目标的依赖 deps = [ ":windowStage_app_profile" ] + # hap_profile: HAP的config.json,Stage模型对应module.json hap_profile = "src/main/module.json" -} \ No newline at end of file +} diff --git a/telephony/crossplatform/telephonyConnectionetstest/src/main/ets/test/Connection.test.ets b/telephony/crossplatform/telephonyConnectionetstest/src/main/ets/test/Connection.test.ets index f6905b7ab..63d364843 100644 --- a/telephony/crossplatform/telephonyConnectionetstest/src/main/ets/test/Connection.test.ets +++ b/telephony/crossplatform/telephonyConnectionetstest/src/main/ets/test/Connection.test.ets @@ -52,24 +52,24 @@ export default function connectionTest() { * @tc.level : Level 2 */ it('testHasDefaultNet001', 0, function (done) { - console.log('testHasDefaultNet001 1') + console.log('testHasDefaultNet001 1'); connection.hasDefaultNet((error, value) => { - console.log('testHasDefaultNet001 2') + console.log('testHasDefaultNet001 2'); if (!error) { - console.log('testHasDefaultNet001 3') + console.log('testHasDefaultNet001 3'); console.log(`testHasDefaultNet001 case success,data:` + value); - console.log('testHasDefaultNet001 4') + console.log('testHasDefaultNet001 4'); expect(value).assertTrue(); done(); } else { - console.log('testHasDefaultNet001 6') + console.log('testHasDefaultNet001 6'); console.log(`testHasDefaultNet001 error, case failed,errCode:` + error.code); - console.log('testHasDefaultNet001 7') + console.log('testHasDefaultNet001 7'); expect().assertFail(); done(); } }); - console.log('testHasDefaultNet001 9') + console.log('testHasDefaultNet001 9'); }); /* @@ -176,34 +176,6 @@ export default function connectionTest() { } }); - /** - * @tc.number: TEST_ON_NET_BLOCK_STATUS_CHANGE_001 - * @tc.name : testOn_NetBlockStatusChange001 - * @tc.desc : Subscribe to network blocking status events, using the callback method as an asynchronous method. - * @tc.size : MediumTest - * @tc.type : Method - * @tc.level : Level 2 - */ - it('testOn_NetBlockStatusChange001', 0, function (done) { - let netConn = connection.createNetConnection(); - netConn.register((error) => { - if (!error) { - netConn.on('netBlockStatusChange',(data) => { - console.log("success11:" + data); - }); - netConn.unregister((error) => { - console.log("result11:" + error); - }); - expect(true).assertTrue(); - done(); - } else { - console.log(`register failed,errCode:` + error.code); - expect().assertFail(); - done(); - } - }); - }); - /** * @tc.number: TEST_ON_NET_CAPABILITIES_CHANGE_001 * @tc.name : testOn_NetCapabilitiesChange001 @@ -218,34 +190,7 @@ export default function connectionTest() { if (!error) { netConn.on('netCapabilitiesChange',(data) => { console.log("success11:" + data); - }); - netConn.unregister((error) => { - console.log("result11:" + error); - }); - expect(true).assertTrue(); - done(); - } else { - console.log(`register failed,errCode:` + error.code); - expect().assertFail(); - done(); - } - }); - }); - - /** - * @tc.number: TEST_ON_NET_CONNECTION_PROPERTIES_CHANGE_001 - * @tc.name : testOn_NetConnectionPropertiesChange001 - * @tc.desc : Subscribe to network connection information change events. - * @tc.size : MediumTest - * @tc.type : Method - * @tc.level : Level 2 - */ - it('testOn_NetConnectionPropertiesChange001', 0, function (done) { - let netConn = connection.createNetConnection(); - netConn.register((error) => { - if (!error) { - netConn.on('netConnectionPropertiesChange',(data) => { - console.log("success11:" + data); + expect(data.netCap.bearerTypes.length >= 0).assertTrue(); }); netConn.unregister((error) => { console.log("result11:" + error); @@ -358,6 +303,5 @@ export default function connectionTest() { done(); }); - }) } diff --git a/telephony/crossplatform/telephonyWebSocketetstest/BUILD.gn b/telephony/crossplatform/telephonyWebSocketetstest/BUILD.gn index b6d19de03..8eccd552b 100644 --- a/telephony/crossplatform/telephonyWebSocketetstest/BUILD.gn +++ b/telephony/crossplatform/telephonyWebSocketetstest/BUILD.gn @@ -20,6 +20,7 @@ ohos_js_hap_suite("ActsCrossplatformWebSocketTest") { ] ets2abc = true certificate_profile = "./signature/openharmony_sx.p7b" + # hap_name: HAP的名字,可选,默认为目标名 hap_name = "ActsCrossplatformWebSocketTest" subsystem_name = "communication" @@ -28,6 +29,7 @@ ohos_js_hap_suite("ActsCrossplatformWebSocketTest") { ohos_app_scope("windowStage_app_profile") { # app_profile: HAP的AppScope中的app.json,只在Stage模型下使用 app_profile = "AppScope/app.json" + # sources: 资源文件路径 sources = [ "AppScope/resources" ] } @@ -38,8 +40,10 @@ ohos_js_assets("windowStage_js_assets") { ohos_resources("windowStage_resources") { # sources: 资源文件路径 sources = [ "src/main/resources" ] + # deps: 当前目标的依赖 deps = [ ":windowStage_app_profile" ] + # hap_profile: HAP的config.json,Stage模型对应module.json hap_profile = "src/main/module.json" -} \ No newline at end of file +} diff --git a/telephony/crossplatform/telephonyWebSocketetstest/src/main/ets/test/WebSocket.test.ets b/telephony/crossplatform/telephonyWebSocketetstest/src/main/ets/test/WebSocket.test.ets index 27dcc534e..7ead9be7c 100644 --- a/telephony/crossplatform/telephonyWebSocketetstest/src/main/ets/test/WebSocket.test.ets +++ b/telephony/crossplatform/telephonyWebSocketetstest/src/main/ets/test/WebSocket.test.ets @@ -19,8 +19,6 @@ export default function webSocketTest() { describe('webSocketTest', function () { console.log("************* webSocket Test start*************"); - let serverIpAddress: string = "ws://192.168.1.100:8081/string"; - /* * @tc.number: TEST_CREATE_WEB_SOCKET_001 * @tc.name : testCreateWebSocket001 @@ -32,6 +30,17 @@ export default function webSocketTest() { it('testCreateWebSocket001', 0, async function (done) { var mWebSocket = webSocket.createWebSocket(); expect(mWebSocket != null).assertTrue(); + mWebSocket.close((error, value) => { + if (!error) { + console.log(`case success:` + value); + expect(value).assertTrue(); + done(); + } else { + console.log(`error, case failed,errCode:` + error.code); + expect(error.code).assertEqual(2302999); + done(); + } + }); done(); }); @@ -161,6 +170,54 @@ export default function webSocketTest() { }); }); + /* + * @tc.number: TEST_CONNECT_004 + * @tc.name : testConnect004 + * @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('testConnect004', 0, async function (done) { + let mWebSocket = webSocket.createWebSocket(); + mWebSocket.connect(null).then(value => { + console.log(`case success11:` + value); + expect(value).assertTrue(); + done(); + }).catch((error) => { + console.log(`error, case failed,errCode:` + error.code); + expect(error.code).assertEqual(401); + done(); + }); + }); + + /* + * @tc.number: TEST_CONNECT_005 + * @tc.name : testConnect005 + * @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('testConnect005', 0, async function (done) { + let mWebSocket = webSocket.createWebSocket(); + let webSocketRequestOptions: webSocket.WebSocketRequestOptions = { + header: { + key: "value", + key2: "value2" + } + } + mWebSocket.connect("ws://19211.16811.1.100:8081/string", webSocketRequestOptions).then(value => { + console.log(`case success11:` + value); + expect(value).assertTrue(); + done(); + }).catch((error) => { + console.log(`error, case failed,errCode:` + error.code); + expect(error.code).assertEqual(-1); + done(); + }); + }); + /* * @tc.number: TEST_SEND_001 * @tc.name : testSend001 @@ -234,6 +291,35 @@ export default function webSocketTest() { }); }); + /* + * @tc.number: TEST_SEND_004 + * @tc.name : testSend004 + * @tc.desc : Sends data through a WebSocket connection. + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it('testSend004', 0, async function (done) { + let mWebSocket = webSocket.createWebSocket(); + var str = "Hello, server!(arrayBuffer promise mode)"; + var buf = new ArrayBuffer(str.length); + var message = new Uint8Array(buf); + for (var i = 0, strLen = str.length; i < strLen; i++) { + message[i] = str.charCodeAt(i); + } + mWebSocket.send(message.buffer, (error, value) => { + if (!error) { + console.log(`case success:` + value); + expect(value).assertTrue(); + done(); + } else { + console.log(`error, case failed,errCode:` + error.code); + expect(error.code).assertEqual(2302999); + done(); + } + }); + }); + /* * @tc.number: TEST_CLOSE_001 * @tc.name : testClose001 -- GitLab