diff --git a/telephony/BUILD.gn b/telephony/BUILD.gn index b4de3644f882454facb96ae121b765db8e7e31f0..f81255a935b6ad8fdec22d636958dafe100077d2 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 6f04401f5c70fa1202518d4af4bb02021020866c..6390bc9a97218219610b8e63fd2f2fdffa5536b3 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 f6905b7abbe8f7591f091c4bb5cf586febc8ee71..63d36484359af5aac0c746d354c7c82c1f565979 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 b6d19de0379d42884e8a451ffaef2133c800d156..8eccd552b9db69ad6b2765effc335f6805101995 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 27dcc534ead12e7275ea9955098642d1e1fbeca1..7ead9be7cc756dc8f0178359539c49ea354de5ed 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