分布式js测试框架

Signed-off-by: songdawei <songdawei1@huawei.com>
This commit is contained in:
songdawei 2022-05-24 11:53:55 +00:00
parent 7321715bbd
commit fb554f6b07
9 changed files with 175 additions and 35 deletions

View File

@ -1,3 +1,18 @@
/*
* Copyright (C) 2022 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 app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import apiMessage from '../../../../../../../../../../testtools/disjsTest/common/apiMessage.js'
@ -12,11 +27,11 @@ describe('addTest', function () {
beforeAll(async function (done) {
console.info(logTag + 'beforeAll')
testservice = new testService();
testservice = new TestService();
await testservice.toConnectAbility().then(data=>{
gIRemoteObject = data;
console.log(logTag + "toConnectAbility data is" + data);
remoteHelpers = new remoteHelper(testservice,gIRemoteObject);
remoteHelpers = new RemoteHelper(testservice,gIRemoteObject);
})
done();
})

View File

@ -1,3 +1,18 @@
/*
* Copyright (C) 2022 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 Stub from '../../../../../../../../../testtools/disjsTest/server/service.js'
export default {

View File

@ -1,10 +1,25 @@
/*
* Copyright (C) 2022 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 apiMessage from '../common/apiMessage.js'
import apiResult from '../common/apiResult.js'
import rpc from '@ohos.rpc'
var logTag = "RpcClient";
var CODE_INVOKE =1;
var results;
export default class remoteHelper{
export default class RemoteHelper{
testservice = undefined
gIRemoteObject = undefined
constructor(testservice,gIRemoteObject){
@ -14,7 +29,7 @@ export default class remoteHelper{
async add(a,b) {
console.log(logTag+"_methodName is add");
let message = new apiMessage("openHarmony","testApi","add"," ",["number","number"],[String(a),String(b)]," ");
let message = new ApiMessage("openHarmony","testApi","add"," ",["number","number"],[String(a),String(b)]," ");
var messageParcel = rpc.MessageParcel.create();
console.log(logTag + "create object successfully.");
@ -23,7 +38,7 @@ export default class remoteHelper{
var writeResult = messageParcel.writeSequenceable(message);
await this.gIRemoteObject.sendRequest(CODE_INVOKE, messageParcel, messageParcelreply, option);
console.log(logTag + "sendRequest got result");
var ret = new apiMessage(null, null, null, null, null, null,null)
var ret = new ApiMessage(null, null, null, null, null, null,null)
var dataReply = messageParcelreply.readSequenceable(ret);
console.log(logTag + "run readSequenceable success, result is" + dataReply);
results = JSON.parse(ret._apiResult);
@ -33,12 +48,22 @@ export default class remoteHelper{
}
sub(a,b) {
async sub(a,b) {
console.log(logTag+"_methodName is sub");
let message = new apiMessage("openHarmony","testApi","sub"," ",["number","number"],[String(a),String(b)]," ");
this.testservice.invoke(this.gIRemoteObject,message).then(apiresult=>{
console.log(logTag + "end sendRequest" + apiresult._result);
return apiresult._result;
})
let message = new ApiMessage("openHarmony","testApi","sub"," ",["number","number"],[String(a),String(b)]," ");
var messageParcel = rpc.MessageParcel.create();
console.log(logTag + "create object successfully.");
var messageParcelreply = rpc.MessageParcel.create();
var option = new rpc.MessageOption();
var writeResult = messageParcel.writeSequenceable(message);
await this.gIRemoteObject.sendRequest(CODE_INVOKE, messageParcel, messageParcelreply, option);
console.log(logTag + "sendRequest got result");
var ret = new ApiMessage(null, null, null, null, null, null,null)
var dataReply = messageParcelreply.readSequenceable(ret);
console.log(logTag + "run readSequenceable success, result is" + dataReply);
results = JSON.parse(ret._apiResult);
console.log(logTag + " read success, results is" + results._result);
return results._result;
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright (C) 2022 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 rpc from '@ohos.rpc';
import process from '@ohos.process';
@ -14,7 +29,7 @@ var bundleName = "ohos.dcts.distributedisjsserver";
var abilityName = "ohos.dcts.distributedisjsserver.ServiceAbility";
var deviceList;
export default class testService {
export default class TestService {
callback;
onCreate() {
@ -63,7 +78,7 @@ export default class testService {
let self = this;
deviceManager.createDeviceManager('ohos.dcts.distributedisjsserver', (error, deviceManager) => {
self.getDeviceList(deviceManager);
console.info(logTag + "got deviceManager: " + deviceManager + ", error: " + error)
console.info(logTag + "got deviceManager: " + deviceManager)
let deviceId = deviceList[0].deviceId
console.info(logTag + "online deviceList id: " + JSON.stringify(deviceList))
let want = {
@ -74,7 +89,6 @@ export default class testService {
}
let connect = {
onConnect: function (elementName, remoteProxy) {
console.log('RpcClient: onConnect called, instance of proxy: ' + (remoteProxy instanceof rpc.RemoteProxy));
console.log('RpcClient: onConnect called, remoteProxy: ' + remoteProxy);
resolve(remoteProxy)
},

View File

@ -1,18 +1,33 @@
/*
* Copyright (C) 2022 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.
*/
var logTag = 'RpcServer'
export default class apiMessage {
export default class ApiMessage {
_deviceName = null;
_className = null;
_methodName = null;
_api_session = null;
_apiSession = null;
_parameterTypes = null;
_parameters = null;
_apiResult = null;
constructor(deviceName, className, methodName, api_session, parameterTypes, parameters, apiResult) {
constructor(deviceName, className, methodName, apiSession, parameterTypes, parameters, apiResult) {
this._deviceName = deviceName;
this._className = className;
this._methodName = methodName;
this._api_session = api_session;
this._apiSession = apiSession;
this._parameterTypes = parameterTypes;
this._parameters = parameters;
this._apiResult = apiResult;
@ -23,7 +38,7 @@ export default class apiMessage {
messageParcel.writeString(this._deviceName);
messageParcel.writeString(this._className);
messageParcel.writeString(this._methodName);
messageParcel.writeString(this._api_session);
messageParcel.writeString(this._apiSession);
console.log(logTag + "writeString successfully.");
messageParcel.writeStringArray(this._parameterTypes);
messageParcel.writeStringArray(this._parameters);
@ -37,11 +52,11 @@ export default class apiMessage {
this._deviceName = messageParcel.readString();
this._className = messageParcel.readString();
this._methodName = messageParcel.readString();
this._api_session = messageParcel.readString();
this._apiSession = messageParcel.readString();
this._parameterTypes = messageParcel.readStringArray();
this._parameters = messageParcel.readStringArray();
this._apiResult = messageParcel.readString();
console.log(logTag + "unmarshalling successfully.");
return true;
}
}
}

View File

@ -1,5 +1,19 @@
/*
* Copyright (C) 2022 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.
*/
export default class apiResult {
export default class ApiResult {
_resultCode = 0;
_result = null;
@ -7,4 +21,4 @@ export default class apiResult {
this._resultCode = resultCode;
this._result = result;
}
}
}

View File

@ -1,4 +1,18 @@
// @ts-nocheck
/*
* Copyright (C) 2022 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 rpc from '@ohos.rpc';
import apiMessage from '../common/apiMessage.js'
import testBundleManager from './testBundleManager.js'
@ -19,12 +33,12 @@ export default class Stub extends rpc.RemoteObject {
case CODE_INVOKE:
{
console.info(logTag +" case CODE_INVOKE start")
let testBundle = new apiMessage(null, null, null, null, null, null, null)
let testBundle = new ApiMessage(null, null, null, null, null, null, null)
var tmp = data.readSequenceable(testBundle);
console.log( logTag +" The server's readSequenceable result is " + tmp + JSON.stringify(testBundle));
let test_BundleManager = new testBundleManager();
let testBundleResult = test_BundleManager.invoke(testBundle);
console.log( logTag +" testBundleManager invoke success result is " + JSON.stringify(testBundleResult));
console.log( logTag +" read result is " + tmp + JSON.stringify(testBundle));
let testBundleManager = new TestBundleManager();
let testBundleResult = testBundleManager.invoke(testBundle);
console.log( logTag +" invoke result is " + JSON.stringify(testBundleResult));
testBundle._apiResult=JSON.stringify(testBundleResult);
console.log(logTag +" The testBundle is " + JSON.stringify(testBundle));

View File

@ -1,5 +1,20 @@
/*
* Copyright (C) 2022 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.
*/
var logTag = "RpcServer";
export default class testApi{
export default class TestApi{
constructor(){
}

View File

@ -1,9 +1,22 @@
// @ts-nocheck
/*
* Copyright (C) 2022 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 testApi from './testApi.js'
import apiResult from '../common/apiResult.js'
var logTag = "RpcServer";
export default class testBundleManager{
export default class TestBundleManager{
_classname;
_methodName;
_parameterTypes;
@ -18,10 +31,10 @@ export default class testBundleManager{
this._parameterTypes = testBundle._parameterTypes;
this._parameters = testBundle._parameters;
let result = new apiResult();
let result = new ApiResult();
if(this._methodName == "add") {
let test = new testApi();
let test = new TestApi();
let resultNum = test.add(this._parameters[0], this._parameters[1]);
console.log(logTag+"_methodName invoke success,result is"+resultNum);
result._resultCode = true;
@ -30,7 +43,7 @@ export default class testBundleManager{
}
else if(this._methodName == "sub")
{
let test = new testApi();
let test = new TestApi();
let resultNum = test.sub(this._parameters[0], this._parameters[1]);
console.log(logTag+"_methodName invoke success,result is"+resultNum);
result._resultCode = true;