!596 优化用例

Merge pull request !596 from 张攀/master
This commit is contained in:
openharmony_ci 2024-03-09 10:01:59 +00:00 committed by Gitee
commit 4ef90a1250
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 130 additions and 140 deletions

View File

@ -14,10 +14,10 @@
*/
import rpc from "@ohos.rpc";
import TestService from "./testService"
import TestService from "./testService";
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import { UiDriver, BY } from '@ohos.UiTest'
import { UiDriver, BY } from '@ohos.UiTest';
export default function RpcJsUnitTest() {
@ -132,7 +132,7 @@ export default function RpcJsUnitTest() {
_checkResult(_num, _str);
}, 2 * 1000);
console.info("result:" + result);
return result
return result;
}
}
@ -145,7 +145,7 @@ export default function RpcJsUnitTest() {
let descriptor = data.readInterfaceToken();
if (descriptor !== "TestAbilityStub") {
console.error("received unknown descriptor: " + descriptor);
return false
return false;
}
switch (code) {
case 1:
@ -172,12 +172,12 @@ export default function RpcJsUnitTest() {
reply.writeChar(tmp8);
reply.writeString(tmp9);
reply.writeSequenceable(s);
return true
return true;
}
default:
{
console.error("default case, code: " + code);
return false
return false;
}
}
}
@ -192,7 +192,7 @@ export default function RpcJsUnitTest() {
let descriptor = data.readInterfaceToken();
if (descriptor !== "TestAbilityMessageStub") {
console.error("received unknown descriptor: " + descriptor);
return false
return false;
}
switch (code) {
case 1:
@ -219,12 +219,12 @@ export default function RpcJsUnitTest() {
reply.writeChar(tmp8);
reply.writeString(tmp9);
reply.writeParcelable(s);
return true
return true;
}
default:
{
console.error("default case, code: " + code);
return false
return false;
}
}
}
@ -269,7 +269,7 @@ export default function RpcJsUnitTest() {
}
asObject() {
console.info("server remote");
return this.remote
return this.remote;
}
}
@ -287,12 +287,13 @@ export default function RpcJsUnitTest() {
async function getPermission() {
console.info(`getPermission is start`);
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
let context = featureAbility.getContext()
let context = featureAbility.getContext();
context.requestPermissionsFromUser(permissions, 666, (data) => {
console.info("request success" + JSON.stringify(data));
})
}
async function driveFn() {
try {
let driver = await UiDriver.create();
@ -312,17 +313,16 @@ export default function RpcJsUnitTest() {
beforeAll(async function (done) {
console.info('beforeAll called rpc');
testservice = new TestService;
await getPermission();
sleep(5000);
await driveFn();
sleep(2000);
testservice = new TestService
testservice.toStartAbility();
sleep(2000);
await testservice.toConnectAbility().then(data => {
gIRemoteObject = data;
console.info("RpcClient: toConnectAbility data is " + data);
console.info("RpcClient: toConnectAbility data is: " + data);
})
done();
console.info("beforeAll done");

View File

@ -16,8 +16,9 @@
import deviceManager from '@ohos.distributedDeviceManager';
import featureAbility from '@ohos.ability.featureAbility';
var bundleName = "com.acts.rpc.test.server";
var serverBundleName = "com.acts.rpc.test.server";
var abilityName = "com.acts.rpc.test.server.ServiceAbility";
var mainAbilityName = "com.acts.rpc.test.server.MainAbility";
var deviceList;
export default class TestService {
@ -25,25 +26,24 @@ export default class TestService {
}
getDeviceList(deviceManager) {
deviceList = deviceManager.getAvailableDeviceListSync();
console.info("getDeviceList success, deviceList id: " + JSON.stringify(deviceList))
console.info("getDeviceList success, deviceList id: " + JSON.stringify(deviceList));
}
toConnectAbility() {
console.info("RpcClient: toConnectAbility")
console.info("RpcClient: toConnectAbility");
return new Promise(resolve=>{
let self = this;
let dmInstance = deviceManager.createDeviceManager('ohos.rpc.test');
self.getDeviceList(dmInstance);
console.info("RpcClient: got deviceManager: " + dmInstance)
let networkId = deviceList[0].networkId
console.info("RpcClient: deviceid : " + networkId)
console.info("RpcClient: online deviceList id: " + JSON.stringify(deviceList))
console.info("RpcClient: got deviceManager: " + dmInstance);
let networkId = deviceList[0].networkId;
console.info("RpcClient: deviceid : " + networkId);
console.info("RpcClient: online deviceList id: " + JSON.stringify(deviceList));
let want = {
"bundleName": bundleName,
"bundleName": serverBundleName,
"abilityName": abilityName,
"deviceId": networkId,
"flags": 256
@ -51,18 +51,44 @@ export default class TestService {
let connect = {
onConnect: function (elementName, remoteProxy) {
console.log('RpcClient: onConnect called, remoteProxy: ' + remoteProxy);
resolve(remoteProxy)
resolve(remoteProxy);
},
onDisconnect: function (elementName) {
console.log("RpcClient: onDisconnect")
console.log("RpcClient: onDisconnect");
},
onFailed: function () {
console.log("RpcClient: onFailed")
console.log("RpcClient: onFailed");
}
}
let connectId = featureAbility.connectAbility(want, connect)
console.info("RpcClient: connect ability got id: " + connectId)
let connectId = featureAbility.connectAbility(want, connect);
console.info("RpcClient: connect ability got id: " + connectId);
})
}
toStartAbility() {
console.info("RpcClient: toStartAbility");
let self = this;
let dmInstance = deviceManager.createDeviceManager('ohos.rpc.test');
self.getDeviceList(dmInstance);
console.info("RpcClient: got deviceManager: " + dmInstance);
let networkId = deviceList[0].networkId;
console.info("RpcClient: deviceid : " + networkId);
console.info("RpcClient: online deviceList id: " + JSON.stringify(deviceList));
try{
let wantValue = {
"bundleName": serverBundleName,
"abilityName": mainAbilityName,
"deviceId": networkId
};
featureAbility.startAbility({
want: wantValue
}).then((data) => {
console.info("RpcClient startAbility success. data=" + JSON.stringify(data));
}).catch((err) => {
console.info("RpcClient startAbility err: " + err.code + err.message);
});
}catch(error){
console.info("RpcClient startAbility:error = " + error);
}
}
}

View File

@ -13,47 +13,57 @@
* limitations under the License.
*/
import Ability from '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import AcCtrl from '@ohos.abilityAccessCtrl';
import {Core} from 'deccjsunit/index';
let AcManager = AcCtrl.createAtManager()
export default class MainAbility extends Ability {
let AcManager = AcCtrl.createAtManager();
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.info('AceApplication onCreate');
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
const core = Core.getInstance();
core.init();
const configService = core.getDefaultService('config');
configService.setConfig(this);
console.info('Calc[IndexPage] grantPermission')
console.info('Calc[IndexPage] grantPermission');
AcManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser')
})
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser');
});
}
onDestroy() {
console.info("onDestroy")
console.info("onDestroy");
}
onWindowStageCreate(windowStage) {
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.info("onWindowStageCreate")
}
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('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() {
// Main window is destroyed, release UI related resources
console.info("onWindowStageDestroy")
console.info("onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.info("onForeground")
console.info("onForeground");
}
onBackground() {
// Ability has back to background
console.info("onBackground")
console.info("onBackground");
}
};

View File

@ -28,7 +28,7 @@ struct Index {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
Text('RPC SERVER')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}

View File

@ -15,48 +15,6 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import fileio from '@ohos.fileio';
import wantAgent from '@ohos.wantAgent';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
function startContinuousTask() {
let wantAgentInfo = {
wants: [
{
bundleName: "com.ohos.rpcquesttest",
abilityName: "com.ohos.rpcquesttest.ServiceAbility"
}
],
operationType: wantAgent.OperationType.START_SERVICE,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try{
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.MULTI_DEVICE_CONNECTION, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => {
console.error("Operation startBackgroundRunning failed Cause: " + err);
});
}catch(error){
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}
});
}
function stopContinuousTask() {
try{
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => {
console.error("Operation stopBackgroundRunning failed Cause: " + err);
});
}catch(error){
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}
}
class MySequenceable {
num = null;
@ -93,14 +51,14 @@ class Stub extends rpc.RemoteObject {
console.info("onRemoteRequest readstring is " + tmp1);
let result = reply.writeString("onRemoteRequest invoking");
console.info("onRemoteRequest writestring is " + result);
return true
return true;
} else if (code === 38){
console.info("case 38 start");
let tmp1 = data.readString();
console.info("onRemoteRequest readstring is " + tmp1);
let result = reply.writeString(tmp1);
console.info("onRemoteRequest writestring is " + result);
return true
return true;
}else {
console.error("default case " + code);
return super.onRemoteRequest(code, data, reply, option);
@ -108,7 +66,7 @@ class Stub extends rpc.RemoteObject {
} catch (error) {
console.info("onRemoteRequest: " + error);
}
return false
return false;
}
onRemoteMessageRequest(code, data, reply, option) {
try{
@ -122,7 +80,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readByteArray result is " + tmp1.length);
let result = reply.writeByteArray(tmp1);
console.info("The server's writeByteArray result is " + result);
return true
return true;
}
case 2:
{
@ -131,7 +89,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readIntArray " + tmp1.length);
let result = reply.writeIntArray(tmp1);
console.info("The server's writeIntArray result is " + result);
return true
return true;
}
case 3:
{
@ -140,7 +98,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readFloatArray result is " + tmp1.length);
let result = reply.writeFloatArray(tmp1);
console.info("The server's writeFloatArray result is " + result);
return true
return true;
}
case 4:
{
@ -149,7 +107,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readShortArray result is " + tmp1.length);
let result = reply.writeShortArray(tmp1);
console.info("The server's writeShortArray result is " + result);
return true
return true;
}
case 5:
{
@ -158,7 +116,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readLongArray result is " + tmp1.length);
let result = reply.writeLongArray(tmp1);
console.info("The server's writeLongArray result is " + result);
return true
return true;
}
case 6:
{
@ -167,7 +125,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readDoubleArray result is " + tmp1.length);
let result = reply.writeDoubleArray(tmp1);
console.info("The server's writeDoubleArray result is " + result);
return true
return true;
}
case 7:
{
@ -176,7 +134,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readBooleanArray result is " + tmp1.length);
let result = reply.writeBooleanArray(tmp1);
console.info("The server's writeBooleanArray result is " + result);
return true
return true;
}
case 8:
{
@ -185,7 +143,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readCharArray result is " + tmp1.length);
let result = reply.writeCharArray(tmp1);
console.info("The server's writeCharArray result is " + result);
return true
return true;
}
case 9:
{
@ -194,7 +152,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readStringArray result is " + tmp1.length);
let result = reply.writeStringArray(tmp1);
console.info("The server's writeStringArray result is " + result);
return true
return true;
}
case 10:
{
@ -203,7 +161,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readShort result is " + tmp1);
let result = reply.writeShort(tmp1);
console.info("The server's writeShort result is " + result);
return true
return true;
}
case 11:
{
@ -212,7 +170,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readLong result is " + tmp1);
let result = reply.writeLong(tmp1);
console.info("The server's writeLong result is " + result);
return true
return true;
}
case 12:
{
@ -221,7 +179,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readDouble result is " + tmp1);
let result = reply.writeDouble(tmp1);
console.info("The server's writeDouble result is " + result);
return true
return true;
}
case 13:
{
@ -230,7 +188,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readBoolean result is " + tmp1);
let result = reply.writeBoolean(tmp1);
console.info("The server's writeBoolean result is " + result);
return true
return true;
}
case 14:
{
@ -239,7 +197,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readChar result is " + tmp1);
let result = reply.writeChar(tmp1);
console.info("The server's writeChar result is " + result);
return true
return true;
}
case 15:
{
@ -248,7 +206,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readString result is " + tmp1.length);
let result = reply.writeString(tmp1);
console.info("The server's writeString result is " + result);
return true
return true;
}
case 16:
{
@ -257,7 +215,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readByte result is " + tmp1);
let result = reply.writeByte(tmp1);
console.info("The server's writeByte result is " + result);
return true
return true;
}
case 17:
{
@ -266,7 +224,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readInt result is " + tmp1);
let result = reply.writeInt(tmp1);
console.info("The server's writeInt result is " + result);
return true
return true;
}
case 18:
{
@ -275,7 +233,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readFloat result is " + tmp1);
let result = reply.writeFloat(tmp1);
console.info("The server's writeFloat result is " + result);
return true
return true;
}
case 19:
{
@ -288,7 +246,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's writeInt result is " + size1);
let result = reply.writeRawData(tmp1, tmp1.length);
console.info("The server's writeRawData result is " + result);
return true
return true;
}
case 20:
{
@ -318,7 +276,7 @@ class Stub extends rpc.RemoteObject {
})
reply.writeNoException();
console.info("case 20 end");
return true
return true;
}
case 21:
{
@ -328,7 +286,7 @@ class Stub extends rpc.RemoteObject {
console.info("server's readParcelable result is " + tmp1);
let result = reply.writeParcelable(s);
console.info("server's writeParcelable result is " + result);
return true
return true;
}
case 22:
{
@ -340,7 +298,7 @@ class Stub extends rpc.RemoteObject {
reply.writeNoException();
console.info("writeNoException result is ");
var result = reply.writeInt(tmp);
return true
return true;
}
case 23:
{
@ -351,7 +309,7 @@ class Stub extends rpc.RemoteObject {
console.info("readParcelableArray result success");
let result = reply.writeParcelableArray(s);
console.info("writeParcelableArray result is " + result);
return true
return true;
}
case 24:
{
@ -376,7 +334,7 @@ class Stub extends rpc.RemoteObject {
})
}
console.info("The server's writeRemoteObjectArray result is " + result);
return true
return true;
}
case 25:
{
@ -402,7 +360,7 @@ class Stub extends rpc.RemoteObject {
let result8 = reply.writeChar(tmp8);
let result9 = reply.writeString(tmp9);
let result10 = reply.writeParcelable(s);
return true
return true;
}
case 26:
{
@ -429,10 +387,9 @@ class Stub extends rpc.RemoteObject {
let result8 = reply.writeCharArray(tmp8);
let result9 = reply.writeStringArray(tmp9);
let result10 = reply.writeParcelableArray(s);
return true
return true;
}
case 27:
{
console.info("case 27 start");
var ashmem = data.readAshmem();
@ -453,7 +410,7 @@ class Stub extends rpc.RemoteObject {
console.info("unmapAshmem success " );
ashmem.closeAshmem();
console.info("closeAshmem success ");
return true
return true;
}
case 28:
{
@ -463,7 +420,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's readParcelable result is " + s);
var result = reply.writeParcelable(s);
console.info("The server's writeParcelable result is " + s);
return true
return true;
}
case 29:
{
@ -480,7 +437,7 @@ class Stub extends rpc.RemoteObject {
var result4 = reply.writeShort(tmp4);
var result5 = reply.writeShort(tmp5);
console.info("The server's writeShort result is " + result1);
return true
return true;
}
case 30:
{
@ -497,7 +454,7 @@ class Stub extends rpc.RemoteObject {
var result4 = reply.writeByte(tmp4);
var result5 = reply.writeByte(tmp5);
console.info("The server's writeByte result is " + result1);
return true
return true;
}
case 31:
{
@ -514,7 +471,7 @@ class Stub extends rpc.RemoteObject {
var result4 = reply.writeInt(tmp4);
var result5 = reply.writeInt(tmp5);
console.info("The server's writeInt result is " + result1);
return true
return true;
}
case 32:
{
@ -539,7 +496,7 @@ class Stub extends rpc.RemoteObject {
reply.writeInt(rpc.IPCSkeleton.getCallingUid());
reply.writeInt(rpc.IPCSkeleton.flushCommands(this));
console.info("IPCSkeleton the server result success");
return true
return true;
}
case 33:
{
@ -558,7 +515,7 @@ class Stub extends rpc.RemoteObject {
reply.writeInt(rpc.IPCSkeleton.getCallingUid());
reply.writeInt(rpc.IPCSkeleton.flushCommands(this));
console.info("IPCSkeleton the server result success");
return true
return true;
}
case 34:
{
@ -591,7 +548,7 @@ class Stub extends rpc.RemoteObject {
})
}
reply.writeNoException();
return true
return true;
}
case 35:
{
@ -621,7 +578,7 @@ class Stub extends rpc.RemoteObject {
})
}
reply.writeNoException();
return true
return true;
}
case 36:
{
@ -630,7 +587,7 @@ class Stub extends rpc.RemoteObject {
console.info("The server's getSize and readInterfaceToken result is " + tmp.length);
let result = reply.writeInterfaceToken(tmp);
console.info("The server's setSize and writeInterfaceToken result is " + result);
return true
return true;
}
case 37:
{
@ -639,7 +596,7 @@ class Stub extends rpc.RemoteObject {
console.info("onRemoteRequest readstring is " + tmp1);
let result = reply.writeString("onRemoteMessageRequest invoking");
console.info("onRemoteRequest writestring is " + result);
return true
return true;
}
default:
this.onRemoteRequest(code, data, reply, option);
@ -651,32 +608,29 @@ class Stub extends rpc.RemoteObject {
}
}
export default class ServiceAbility extends ServiceExtension {
onCreate(want) {
// Called to return a FormBindingData object.
console.info("IpcStageServer ServiceAbility onCreate")
console.info("IpcStageServer ServiceAbility onCreate");
}
onConnect(want) {
// Called when the form provider is notified that a temporary form is successfully
console.info("IpcStageServer ServiceAbility onConnect")
console.info("IpcStageServer ServiceAbility onConnect");
return new Stub("rpcTestAbility");
}
onDisconnect(want) {
// Called to notify the form provider to update a specified form.
console.info("IpcStageServer ServiceAbility onDisconnect")
console.info("IpcStageServer ServiceAbility onDisconnect");
}
onRequest(want, startId){
console.info("IpcStageServer ServiceAbility onRequest")
console.info("IpcStageServer ServiceAbility onRequest");
}
onDestroy() {
// Called to notify the form provider that a specified form has been destroyed.
console.info("IpcStageServer ServiceAbility onCronDestroyeate")
console.info("IpcStageServer ServiceAbility onCronDestroyeate");
}
};

View File

@ -1,5 +1,5 @@
{
"src": [
"pages/index"
"pages/Index"
]
}