!277 [OpenHarmony_master][xts_dcts] filemanagement 用例优化

Merge pull request !277 from guoxiaoyu/gxy0304
This commit is contained in:
openharmony_ci 2023-03-06 02:44:27 +00:00 committed by Gitee
commit 9616381185
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 103 additions and 58 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -15,12 +15,12 @@
import rpc from "@ohos.rpc";
import fileio from '@ohos.fileio';
import deviceManager from '@ohos.distributedHardware.deviceManager';
import featureAbility from "@ohos.ability.featureAbility";
import TestService from "./testService"
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
let gIRemoteObject = null;
let connectId = null;
var testservice = null;
describe('FileioDistributedTest', function(){
console.info("----------SUB_Storage_Fileio_Distributed JS Test is starting----------");
const DISTRIBUTED_FILE_CONTENT = 'content';
@ -103,38 +103,14 @@ describe('FileioDistributedTest', function(){
}
}
beforeAll(async function (done) {
beforeAll(async function(done) {
console.info('beforeAll called fileio server');
function deviceManagerCallback(error, deviceManager) {
console.info("got deviceManager: " + deviceManager + ", error: " + error);
let deviceList = deviceManager.getTrustedDeviceListSync();
let deviceId = deviceList[0].deviceId;
console.info("online device id: " + deviceId);
let want = {
"bundleName": "com.ohos.fileiotest",
"abilityName": "com.ohos.fileiotest.ServiceAbility",
"deviceId": deviceId,
"flags": 256
}
let connect = {
onConnect: function (elementName, remoteProxy) {
console.info('fileioClient: onConnect called,proxy: ' + (remoteProxy instanceof rpc.RemoteProxy));
gIRemoteObject = remoteProxy;
done();
},
onDisconnect: function (elementName) {
console.info("fileioClient: onDisconnect");
},
onFailed: function () {
console.info("fileioClient: onFailed");
gIRemoteObject = null;
}
}
connectId = featureAbility.connectAbility(want, connect);
connectId.info("connect ability got id: " + connectId);
}
deviceManager.createDeviceManager('com.ohos.fileiotest', deviceManagerCallback);
testservice = new TestService
await testservice.toConnectAbility().then(data => {
gIRemoteObject = data;
console.info("fileioClient: toConnectAbility data is " + data);
})
done();
console.info("beforeAll done");
})
beforeEach(function () {

View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2023 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 deviceManager from '@ohos.distributedHardware.deviceManager';
import featureAbility from '@ohos.ability.featureAbility';
var results;
var bundleName = "com.ohos.fileiotest";
var abilityName = "com.ohos.fileiotest.ServiceAbility";
var deviceList;
export default class TestService {
constructor() {
}
getDeviceList(deviceManager) {
deviceList = deviceManager.getTrustedDeviceListSync();
console.info("getDeviceList success, deviceList id: " + JSON.stringify(deviceList))
}
toConnectAbility() {
console.info("fileioClient: toConnectAbility")
return new Promise(resolve=>{
let self = this;
deviceManager.createDeviceManager('com.ohos.fileiotest', (error, deviceManager) => {
self.getDeviceList(deviceManager);
console.info("fileioClient: got deviceManager: " + deviceManager)
let deviceId = deviceList[0].deviceId
console.info("fileioClient: deviceid : " + deviceId)
console.info("fileioClient: online deviceList id: " + JSON.stringify(deviceList))
let want = {
"bundleName": bundleName,
"abilityName": abilityName,
"deviceId": deviceId,
"flags": 256
}
let connect = {
onConnect: function (elementName, remoteProxy) {
console.log('fileioClient: onConnect called, remoteProxy: ' + remoteProxy);
resolve(remoteProxy)
},
onDisconnect: function (elementName) {
console.log("fileioClient: onDisconnect")
},
onFailed: function () {
console.log("fileioClient: onFailed")
}
}
let connectId = featureAbility.connectAbility(want, connect)
console.info("fileioClient: connect ability got id: " + connectId)
})
})
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -13,11 +13,24 @@
* limitations under the License.
*/
import {Core} from 'deccjsunit/index';
import featureAbility from '@ohos.ability.featureAbility';
export default {
onCreate() {
console.info("Application onCreate");
console.info('AceApplication onCreate');
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
})
},
onDestroy() {
console.info("Application onDestroy");
console.info('AceApplication onDestroy');
}
};
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -13,31 +13,19 @@
* limitations under the License.
*/
import router from '@system.router'
import featureAbility from '@ohos.ability.featureAbility';
export default {
data: {
title: ""
title: ''
},
onInit() {
this.grantPermission();
this.title = this.$t('strings.world');
},
onclick: function () {
router.replace({
uri: "pages/second/second"
})
onShow() {
console.info('onShow finish')
},
grantPermission() {
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
})
onReady() {
},
}
}