From c7b8903227c5533c7b3ca01760b0cd8ae312e042 Mon Sep 17 00:00:00 2001 From: zhangpa2021 Date: Mon, 21 Mar 2022 17:46:37 +0800 Subject: [PATCH] =?UTF-8?q?ipc=E7=94=A8=E4=BE=8B=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangpa2021 --- communication/dsoftbus/rpc/Test.json | 7 +- .../js/default/test/RpcClientJsunit.test.js | 143 +++++++++++++----- 2 files changed, 108 insertions(+), 42 deletions(-) mode change 100644 => 100755 communication/dsoftbus/rpc/Test.json diff --git a/communication/dsoftbus/rpc/Test.json b/communication/dsoftbus/rpc/Test.json old mode 100644 new mode 100755 index 83cd1860d..fa2986307 --- a/communication/dsoftbus/rpc/Test.json +++ b/communication/dsoftbus/rpc/Test.json @@ -10,10 +10,15 @@ "kits": [ { "test-file-name": [ - "ActsRpcHapTest.hap" + "ActsRpcHapTest.hap", + "./resource/dsoftbus/ipcserver/entry-release-standard-signed.hap" ], "type": "AppInstallKit", "cleanup-apps": true } ] + + + + } diff --git a/communication/dsoftbus/rpc/src/main/js/default/test/RpcClientJsunit.test.js b/communication/dsoftbus/rpc/src/main/js/default/test/RpcClientJsunit.test.js index 2038a17a4..4060359d5 100755 --- a/communication/dsoftbus/rpc/src/main/js/default/test/RpcClientJsunit.test.js +++ b/communication/dsoftbus/rpc/src/main/js/default/test/RpcClientJsunit.test.js @@ -51,6 +51,8 @@ describe('ActsRpcClientJsTest', function(){ const CODE_TRANSACTION = 27; const CODE_IPCSKELETON = 28; const CODE_FILESDIR = 29; + const CODE_WRITE_REMOTEOBJECTARRAY_1 = 30; + const CODE_WRITE_REMOTEOBJECTARRAY_2 = 31; function connectAbility() { let want = { @@ -125,8 +127,65 @@ describe('ActsRpcClientJsTest', function(){ constructor(descriptor) { super(descriptor) } + + onRemoteRequest(code, data, reply, option) { + console.info("TestAbilityStub: onRemoteRequest called, code: " + code) + let descriptor = data.readInterfaceToken() + if (descriptor !== "TestAbilityStub") { + console.error("received unknown descriptor: " + descriptor) + return false + } + switch (code) { + case 1: + { + let tmp1 = data.readByte() + let tmp2 = data.readByte() + let tmp3 = data.readShort() + let tmp4 = data.readShort() + let tmp5 = data.readInt() + let tmp6 = data.readInt() + let tmp7 = data.readLong() + let tmp8 = data.readLong() + let tmp9 = data.readFloat() + let tmp10 = data.readFloat() + let tmp11 = data.readDouble() + let tmp12 = data.readDouble() + let tmp13 = data.readBoolean() + let tmp14 = data.readBoolean() + let tmp15 = data.readChar() + let tmp16 = data.readString() + let s = new MySequenceable(null, null) + data.readSequenceable(s) + reply.writeNoException() + reply.writeByte(tmp1) + reply.writeByte(tmp2) + reply.writeShort(tmp3) + reply.writeShort(tmp4) + reply.writeInt(tmp5) + reply.writeInt(tmp6) + reply.writeLong(tmp7) + reply.writeLong(tmp8) + reply.writeFloat(tmp9) + reply.writeFloat(tmp10) + reply.writeDouble(tmp11) + reply.writeDouble(tmp12) + reply.writeBoolean(tmp13) + reply.writeBoolean(tmp14) + reply.writeChar(tmp15) + reply.writeString(tmp16) + reply.writeSequenceable(s) + return true + } + default: + { + console.error("default case, code: " + code) + return false + } + } + } } + class TestListener extends rpc.RemoteObject { constructor(descriptor, checkResult) { super(descriptor); @@ -1234,7 +1293,7 @@ describe('ActsRpcClientJsTest', function(){ console.log("SUB_Softbus_IPC_MessageParcel_6000:run writeChar success, result is " + result); expect(result == true).assertTrue() var readresult = data.readChar(); - expect(result == 'a').assertTrue() + expect(readresult == 'a').assertTrue() } catch (error) { console.log("SUB_Softbus_IPC_MessageParcel_6000:error = " + error); @@ -1707,20 +1766,6 @@ describe('ActsRpcClientJsTest', function(){ var result = data.writeRawData(token, token.length); console.log("SUB_Softbus_IPC_MessageParcel_7300:run writeRawData success, result is " + result); expect(result == false).assertTrue(); - if (gIRemoteObject == undefined) - { - console.log("SUB_Softbus_IPC_MessageParcel_7300: gIRemoteObject is undefined"); - } - await gIRemoteObject.sendRequest(CODE_WRITE_RAWDATA, data, reply, option).then((result) => { - console.log("SUB_Softbus_IPC_MessageParcel_7300: sendRequest success, result is " + result.errCode); - var newReadResult = result.reply.readRawData(token.length); - expect(newReadResult[0] == token[0]).assertTrue(); - expect(newReadResult[1] == token[1]).assertTrue(); - expect(newReadResult[2] == token[2]).assertTrue(); - expect(newReadResult[3] == token[3]).assertTrue(); - expect(newReadResult[4] == token[4]).assertTrue(); - }); - data.reclaim(); reply.reclaim(); done(); @@ -2579,6 +2624,8 @@ describe('ActsRpcClientJsTest', function(){ reply.reclaim() console.log("test done") }) + console.log("---------------------end SUB_Softbus_IPC_MessageParcel_9300---------------------------"); + }) }) /* @@ -2589,12 +2636,19 @@ describe('ActsRpcClientJsTest', function(){ */ it('SUB_Softbus_IPC_MessageParcel_9400', 0, async function(done) { console.log("---------------------start SUB_Softbus_IPC_MessageParcel_9400---------------------------"); - try{ - function checkResult(num, str) { - expect(num).assertEqual(123) - expect(str).assertEqual("rpcListenerTest") + + let count = 0; + function checkResult(num, str) { + expect(num).assertEqual(123) + expect(str).assertEqual("rpcListenerTest") + count++ + console.info("check result done, count: " + count) + if (count == 3) { done() } + } + + try{ let option = new rpc.MessageOption() let data = rpc.MessageParcel.create() let reply = rpc.MessageParcel.create() @@ -2607,20 +2661,20 @@ describe('ActsRpcClientJsTest', function(){ console.info("SUB_Softbus_IPC_MessageParcel_9400 result is:" + result) expect(data.writeInt(123)).assertTrue() expect(data.writeString("rpcListenerTest")).assertTrue() - await gIRemoteObject.sendRequest(CODE_WRITE_REMOTEOBJECTARRAY, data, reply, option) - .then(function(result) { - console.info("SUB_Softbus_IPC_MessageParcel_9400: sendRequest done, error code: " + result.errCode) - expect(result.errCode).assertEqual(0) - }) - .catch(function(e) { - console.error("SUB_Softbus_IPC_MessageParcel_9400: send request got exception: " + e) - expect(0).assertEqual(1) - }) - .finally(() => { - data.reclaim() - reply.reclaim() - console.log("test done") - }) + await gIRemoteObject.sendRequest(CODE_WRITE_REMOTEOBJECTARRAY_1, data, reply, option) + .then( ( result) => { + console.info("SUB_Softbus_IPC_MessageParcel_9500:sendRequest done, error code: " + result.errCode) + expect(result.errCode).assertEqual(0) + }) + .catch(function(e) { + console.error("SUB_Softbus_IPC_MessageParcel_9400: send request got exception: " + e) + expect(0).assertEqual(1) + }) + .finally(() => { + data.reclaim() + reply.reclaim() + console.log("test done") + }) done(); data.reclaim(); reply.reclaim(); @@ -2639,12 +2693,18 @@ describe('ActsRpcClientJsTest', function(){ */ it('SUB_Softbus_IPC_MessageParcel_9500', 0, async function(done) { console.log("---------------------start SUB_Softbus_IPC_MessageParcel_9500---------------------------"); - try{ - function checkResult(num, str) { - expect(num).assertEqual(123) - expect(str).assertEqual("rpcListenerTest") + let count = 0; + function checkResult(num, str) { + expect(num).assertEqual(123) + expect(str).assertEqual("rpcListenerTest") + count++ + console.info("check result done, count: " + count) + if (count == 3) { done() } + } + + try{ let option = new rpc.MessageOption() let data = rpc.MessageParcel.create() let reply = rpc.MessageParcel.create() @@ -2659,7 +2719,8 @@ describe('ActsRpcClientJsTest', function(){ console.info("SUB_Softbus_IPC_MessageParcel_9500 result is:" + result) expect(data.writeInt(123)).assertTrue() expect(data.writeString("rpcListenerTest")).assertTrue() - gIRemoteObject.sendRequest(CODE_WRITE_REMOTEOBJECTARRAY, data, reply, option,(err, result) => { + await gIRemoteObject.sendRequest(CODE_WRITE_REMOTEOBJECTARRAY_2, data, reply, option) + .then( ( result) => { console.info("SUB_Softbus_IPC_MessageParcel_9500:sendRequest done, error code: " + result.errCode) expect(result.errCode).assertEqual(0) }) @@ -2756,7 +2817,7 @@ describe('ActsRpcClientJsTest', function(){ try{ expect(rpc.MessageOption.TF_SYNC).assertEqual(0); - expect(rpc.MessageOption.TF_AYNC).assertEqual(1); + expect(rpc.MessageOption.TF_ASYNC).assertEqual(1); expect(rpc.MessageOption.TF_WAIT_TIME).assertEqual(4); @@ -3197,7 +3258,7 @@ describe('ActsRpcClientJsTest', function(){ let size = bytes.length + 10; let result = ashmem.writeToAshmem(bytes, 3, 0); console.log("SUB_Softbus_IPC_Ashmem_1600: run writeToAshmem success, result is " + result); - expect(result == true).assertTrue() + expect(result == true).assertTrue(); ashmem.closeAshmem() @@ -3873,7 +3934,7 @@ describe('ActsRpcClientJsTest', function(){ * @tc.desc Function test * @tc.level 0 */ - it("SUB_Softbus_IPC_RemoteProxy_0500", 0, async function(done){ + it("SUB_Softbus_IPC_RemoteProxy_0500", 0, async function(){ console.log("SUB_Softbus_IPC_RemoteProxy_0500 is starting-------------") try { -- GitLab