提交 21c4f0e0 编写于 作者: Y yangbo

add userfilemgr xts

Signed-off-by: Nyangbo <yangbo258@h-partners.com>
上级 7327f966
......@@ -59,6 +59,10 @@ group("multimedia") {
"medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap",
"medialibrary/mediaLibrary_mediafetchoptions:mediaLibrary_mediafetchoptions_hap",
"medialibrary/mediaLibrary_trash:mediaLibrary_trash_js_hap",
"userfilemgr/userfilemgr_album:userfilemgr_album_js_hap",
"userfilemgr/userfilemgr_base:userfilemgr_base_js_hap",
"userfilemgr/userfilemgr_fileAsset:userfilemgr_fileAsset_js_hap",
"userfilemgr/userfilemgr_noPermission:userfilemgr_noPermission_js_hap",
]
} else {
deps = [
......
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
const presetsCount = {
ActsUserFileMgrAlbum: { albumsCount: 9, assetsCount: 9 },
ActsUserFileMgrBase: { albumsCount: 42, assetsCount: 84 },
}
const IMAGE_TYPE = userfile_manager.MediaType.IMAGE;
const VIDEO_TYPE = userfile_manager.MediaType.VIDEO;
const AUDIO_TYPE = userfile_manager.MediaType.AUDIO;
const FILEKEY = userfile_manager.FileKey;
const sleep = async function sleep(times) {
if (times == undefined) {
times = 10
}
await new Promise(res => setTimeout(res, times));
}
const allFetchOp = function () {
return {
selections: '',
selectionArgs: [],
};
}
const fetchOps = function (testNum, path) {
let ops = {
selections: 'relative_path' + '= ?',
selectionArgs: [path],
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
const nameFetchOps = function (testNum, path, displayName) {
let ops = {
selections: 'relative_path' + '= ? AND ' + FILEKEY.DISPLAY_NAME + '= ?',
selectionArgs: [path, displayName],
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
const albumFetchOps = function (testNum, path, albumName) {
let ops = {
selections: 'relative_path' + '= ? AND ' + 'bucket_display_name' + '= ?',
selectionArgs: [path, albumName],
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
const checkPresetsAssets = async function (userfilemgr, hapName) {
console.info('checkPresetsAssets start')
let albumList = await userfilemgr.getAlbums([IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE], allFetchOp());
let albumsCount = albumList.length;
let fetchFileResult = await userfilemgr.getFileAssets([IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE],
allFetchOp());
let assetsCount = await fetchFileResult.getCount();
console.info(`${hapName}:: assetsCount: ${assetsCount} albumsCount: ${albumsCount},
presetsassetsCount: ${presetsCount[hapName].assetsCount}
presetsalbumsCount: ${presetsCount[hapName].albumsCount}`);
console.info('checkPresetsAssets end')
}
const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) {
if (!fetchFileResult) {
console.info(`${testNum}:: fetchFileResult error:`);
expect(false).assertTrue();
done();
return false
}
let count = await fetchFileResult.getCount();
if (count != expectCount) {
console.info(`${testNum}:: count:expectCount - ${count} : ${expectCount}`);
expect(count).assertEqual(expectCount);
done();
}
return count == expectCount;
}
const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
if (!Array.isArray(albumList)) {
console.info(`${testNum}:: albumList error:`);
expect(false).assertTrue();
done();
return false
}
let albumsCount = albumList.length;
if (albumsCount != expectCount) {
console.info(`${testNum}:: albumsCount: expectCount - ${albumsCount} : ${expectCount}`);
expect(albumsCount).assertEqual(expectCount);
done();
}
return albumsCount == expectCount;
}
const getPermission = async function (name = 'ohos.acts.multimedia.userfilemgr') {
console.info('getPermission start', name)
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.userfilemgr', 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1);
let resultReadImageVideo = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_IMAGEVIDEO", 1);
let resultReadAudio = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_AUDIO", 1);
let resultReadDocument = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_DOCUMENT", 1);
let resultWriteImageVideo = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_IMAGEVIDEO", 1);
let resultWriteAudio = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_AUDIO", 1);
let resultWriteDocument = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_DOCUMENT", 1);
let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION");
let isGrantedReadImageVideo = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_IMAGEVIDEO");
let isGrantedReadAudio = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_AUDIO");
let isGrantedReadDocument = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_DOCUMENT");
let isGrantedWriteImageVideo = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_IMAGEVIDEO");
let isGrantedWriteAudio = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_AUDIO");
let isGrantedWriteDocument = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_DOCUMENT");
if (result1 != 0 || isGranted1 !=0 || !(resultReadImageVideo == 0 && resultReadAudio == 0 && resultReadDocument == 0) ||
!(resultWriteImageVideo == 0 && resultWriteAudio == 0 && resultWriteDocument == 0) ||
!(isGrantedReadImageVideo == 0 && isGrantedReadAudio == 0 && isGrantedReadDocument == 0) ||
!(isGrantedWriteImageVideo == 0 && isGrantedWriteAudio == 0 && isGrantedWriteDocument == 0)) {
console.info('getPermission failed')
}
console.info('getPermission end')
}
const isNum = function (value) {
return typeof value === 'number' && !isNaN(value);
}
export {
getPermission,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
sleep,
allFetchOp,
fetchOps,
nameFetchOps,
albumFetchOps,
checkPresetsAssets,
checkAssetsCount,
checkAlbumsCount,
isNum,
};
\ No newline at end of file
{
"app":{
"bundleName":"ohos.acts.multimedia.userfilemgr",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("userfilemgr_album_js_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsUserFileMgrAlbum"
}
ohos_app_scope("medialibrary_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("mediaLibrary_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("mediaLibrary_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":medialibrary_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for userfilemgr Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.userfilemgr",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{Static,DynamicCb,DynamicPro}",
"mkdir -pv /storage/media/100/local/files/Audios/{Static,DynamicCb,DynamicPro}",
"mkdir -pv /storage/media/100/local/files/Videos/{Static,DynamicCb,DynamicPro}",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsUserFileMgrAlbum.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 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 file from '@system.file';
import { Core, ExpectExtend, InstrumentLog, ReportExtend } from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* 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 albumCommitModifyCallback from './albumCommitModifyCallback.test.ets'
import albumCommitModifyPromise from './albumCommitModifyPromise.test.ets'
import albumGetFileAssetsCallback from './albumGetFileAssetsCallback.test.ets'
import albumGetFileAssetsPromise from './albumGetFileAssetsPromise.test.ets'
export default function testsuite(abilityContext) {
albumCommitModifyCallback(abilityContext)
albumCommitModifyPromise(abilityContext)
albumGetFileAssetsCallback(abilityContext)
albumGetFileAssetsPromise(abilityContext)
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
getPermission,
} from '../../../../../../common';
export default function albumCommitModifyCallback(abilityContext) {
describe('albumCommitModifyCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const albumCommitModify = async function (done, testNum, media_type, fetchOp, expectAlbumCount) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const newName = 'albumName' + media_type.toString();
album.albumName = newName;
album.commitModify(async () => {
expect(true).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum}, failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_01
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
getPermission,
} from '../../../../../../common';
export default function albumCommitModifyPromise(abilityContext) {
describe('albumCommitModifyPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const albumCommitModify = async function (done, testNum, media_type, fetchOp, expectAlbumCount) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const newName = 'albumName' + media_type.toString();
album.albumName = newName;
await album.commitModify();
expect(true).assertTrue();
done();
} catch (error) {
console.info(`${testNum}, failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02
* @tc.name : commitModify
* @tc.desc : audio album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03
* @tc.name : commitModify
* @tc.desc : video album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
} from '../../../../../../common';
export default function albumGetFileAssetsCallback(abilityContext) {
describe('albumGetFileAssetsCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const checkAlbumAssetsCount = async function (done, testNum, media_type, fetchOp, expectAssetsCount, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
// check album length
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
album.getFileAssets(media_type, allFetchOp(), (error, fetchFileResult) => {
if (error != undefined) {
console.info(`${testNum} fetchFileResult error: ${error}`);
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}
expectAssetsCount: ${expectAssetsCount}`);
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
done();
});
} catch (error) {
console.info(`${testNum}, error: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in IMAGE_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in AUDIO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in VIDEO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
});
}
\ No newline at end of file
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
} from '../../../../../../common';
export default function albumGetFileAssetsPromise(abilityContext) {
describe('albumGetFileAssetsPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
// Exception request
const abnormalFetchOp = {
selections: 'date_added < 0',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,1',
}
const checkAlbumAssetsCount = async function (done, testNum, media_type, fetchOp, expectAssetsCount, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
// check album length
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
let op: userfile_manager.MediaFetchOptions = allFetchOp();
let fetchFileResult = await album.getFileAssets(media_type, op);
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}
expectAssetsCount: ${expectAssetsCount}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
done();
} catch (error) {
console.info(`${testNum}, error: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in IMAGE_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in AUDIO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in VIDEO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
});
}
\ No newline at end of file
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "ohos.acts.multimedia.userfilemgr.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
}
]
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
{
"app":{
"bundleName":"ohos.acts.multimedia.userfilemgr",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("userfilemgr_base_js_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsUserFileMgrBase"
}
ohos_app_scope("medialibrary_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("mediaLibrary_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("mediaLibrary_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":medialibrary_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for userfilemgr Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.userfilemgr",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/Static",
"mkdir -pv /storage/media/100/local/files/Videos/Static",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"for d in Static; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsUserFileMgrBase.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 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 file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* 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 getAlbumsCallback from './getAlbumsCallback.test.ets'
import getAlbumsPromise from './getAlbumsPromise.test.ets'
import getFileAssetsCallback from './getFileAssetsCallback.test.ets'
import getFileAssetsPromise from './getFileAssetsPromise.test.ets'
import getUserFileMgr from './getUserFileMgr.test.ets'
export default function testsuite(abilityContext) {
getAlbumsCallback(abilityContext)
getAlbumsPromise(abilityContext)
getFileAssetsCallback(abilityContext)
getFileAssetsPromise(abilityContext)
getUserFileMgr(abilityContext)
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
getPermission,
} from '../../../../../../common';
export default function getAlbumsCallback(abilityContext) {
describe('getAlbumsCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
function printAlbumMessage(testNum, album) {
console.info(`${testNum}
album.albumName: ${album.albumName}
album.albumUri: ${album.albumUri}
album.dateModified: ${album.dateModified}
album.count: ${album.count}
album.relativePath: ${album.relativePath}
album.coverUri: ${album.coverUri}`);
}
const props = {
albumName: 'Static',
albumUri: 'datashare:///userfile_mgr/album/',
count: 1
}
const checkProps = async function (done, testNum, album, relativePaths) {
printAlbumMessage(testNum, album);
if (album.coverUri == undefined) {
console.info(`${testNum}, album.coverUri is undefined`);
expect(false).assertTrue();
done();
return;
}
expect(album.albumName).assertEqual(props.albumName);
expect(album.count).assertEqual(props.count);
if (Array.isArray(relativePaths)) {
let i = relativePaths.indexOf(album.relativePath);
if (i > -1) {
relativePaths.splice(i, 1)
} else {
expect(false).assertTrue();
done();
}
} else {
expect(album.relativePath).assertEqual(relativePaths);
}
}
const checkAlbumInfo = async function (done, testNum, media_type, fetchOp, relativePaths, expectAlbumCount) {
try {
userfile_mgr.getAlbums(media_type, fetchOp, async (err, albumList) => {
if(err) {
console.info(`${testNum}, err: ${err}`)
expect(false).assertTrue();
done();
return;
}
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
checkProps(done, testNum, album, relativePaths);
done();
});
} catch (error) {
console.info(`${testNum}, failed: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let relativePaths = 'Pictures/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02
* @tc.name : getAlbums
* @tc.desc : Audio type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let relativePaths = 'Audios/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03
* @tc.name : getAlbums
* @tc.desc : Video type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let relativePaths = 'Videos/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04
* @tc.name : getAlbums
* @tc.desc : getAlbums by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04';
try {
let media_type = [-1];
let currentFetchOp = allFetchOp();
userfile_mgr.getAlbums(media_type, currentFetchOp, async (err, albumList) => {
console.info(`${testNum}, err: ${err}`);
if (err != undefined) {
expect(true).assertTrue();
done();
return;
}
expect(false).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum}, error: ${error}`);
expect(true).assertTrue();
done();
}
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
} from '../../../../../../common';
export default function getAlbumsPromise(abilityContext) {
describe('getAlbumsPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbum');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
function printAlbumMessage(testNum, album) {
console.info(`${testNum}
album.albumName: ${album.albumName}
album.albumUri: ${album.albumUri}
album.dateModified: ${album.dateModified}
album.count: ${album.count}
album.relativePath: ${album.relativePath}
album.coverUri: ${album.coverUri}`);
}
const props = {
albumName: 'Static',
albumUri: 'datashare:///userfile_mgr/album/',
count: 1
}
const checkProps = async function (done, testNum, album, relativePaths) {
printAlbumMessage(testNum, album);
if (album.coverUri == undefined) {
console.info(`${testNum}, album.coverUri is undefined`);
expect(false).assertTrue();
done();
return;
}
expect(album.albumName).assertEqual(props.albumName);
expect(album.count).assertEqual(props.count);
if (Array.isArray(relativePaths)) {
let i = relativePaths.indexOf(album.relativePath);
if (i > -1) {
relativePaths.splice(i, 1)
} else {
expect(false).assertTrue();
done();
}
} else {
expect(album.relativePath).assertEqual(relativePaths);
}
}
const checkAlbumInfo = async function (done, testNum, media_type, fetchOp, relativePaths, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
checkProps(done, testNum, album, relativePaths);
done();
} catch (error) {
console.info(`${testNum}, failed: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_01
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let relativePaths = 'Pictures/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_02
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let relativePaths = 'Audios/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_03
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let relativePaths = 'Videos/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_04
* @tc.name : getAlbums
* @tc.desc : getAlbums by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_04';
try {
let media_type = [-1];
let currentFetchOp = allFetchOp();
try {
await userfile_mgr.getAlbums(media_type, currentFetchOp);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum}, error1: ${error}`);
expect(true).assertTrue();
done();
}
} catch (error) {
console.info(`${testNum}, error2: ${error}`);
expect(false).assertTrue();
done();
}
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
allFetchOp,
fetchOps,
} from '../../../../../../common';
export default function getFileAssetsCallback(abilityContext) {
describe('getFileAssetsCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrBase');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep(500)
});
afterAll(function () {
console.info('afterAll case');
});
const props = {
image: {
displayName: '01.jpg',
mediaType: IMAGE_TYPE.toString(),
},
video: {
displayName: '01.mp4',
relativePath: 'Videos/Static/',
mediaType: VIDEO_TYPE.toString(),
},
audio: {
displayName: '01.mp3',
mediaType: AUDIO_TYPE.toString(),
},
}
async function checkFileAssetAttr(done, testNum, media_type, fetchOps, type, count) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, count);
if (!checkAssetCountPass) return;
fetchFileResult.getFirstObject(async (err, asset) => {
if (err) {
console.info(`${testNum} err : ${err}`)
expect.assertFail();
done();
return;
}
expect(asset.displayName).assertEqual(props[type].displayName);
expect(asset.mediaType.toString()).assertEqual(props[type].mediaType);
done();
});
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_01
* @tc.name : getFileAssets
* @tc.desc : query image assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOps = fetchOps(testNum, 'Pictures/Static/');
let type = 'image';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_02
* @tc.name : getFileAssets
* @tc.desc : query audio assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOps = fetchOps(testNum, 'Audios/Static/');
let type = 'audio';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_03
* @tc.name : getFileAssets
* @tc.desc : query video assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOps = fetchOps(testNum, 'Videos/Static/');
let type = 'video';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_04
* @tc.name : getFileAssets
* @tc.desc : query assets by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_CALLBACK_04';
try {
let media_type = [-1];
let currentFetchOps = allFetchOp();
userfile_mgr.getFileAssets(media_type, fetchOps, async (err, fetchFileResult) => {
console.info(`${testNum}, err: ${err}`);
if (err != undefined) {
expect(true).assertTrue();
done();
return;
}
expect(false).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(true).assertTrue();
done();
}
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
} from '../../../../../../common';
export default function getFileAssetsPromise(abilityContext) {
describe('getFileAssetsPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrBase');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep(200)
});
afterAll(function () {
console.info('afterAll case');
});
const props = {
image: {
displayName: '01.jpg',
mediaType: IMAGE_TYPE.toString(),
},
video: {
displayName: '01.mp4',
mediaType: VIDEO_TYPE.toString(),
},
audio: {
displayName: '01.mp3',
mediaType: AUDIO_TYPE.toString(),
},
}
async function checkFileAssetAttr(done, testNum, media_type, fetchOps, type, count, typesArr) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, count);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
expect(asset.displayName).assertEqual(props[type].displayName);
expect(asset.mediaType.toString()).assertEqual(props[type].mediaType);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_01
* @tc.name : getFileAssets
* @tc.desc : query image assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOps = fetchOps(testNum, 'Pictures/Static/');
let type = 'image';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count, null);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_02
* @tc.name : getFileAssets
* @tc.desc : query audio assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOps = fetchOps(testNum, 'Audios/Static/');
let type = 'audio';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count, null);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_03
* @tc.name : getFileAssets
* @tc.desc : query video assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOps = fetchOps(testNum, 'Videos/Static/');
let type = 'video';
let count = 1;
await checkFileAssetAttr(done, testNum, media_type, currentFetchOps, type, count, null);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_04
* @tc.name : getFileAssets
* @tc.desc : query assets by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_PROMISE_04';
try {
let media_type = [-1];
let currentFetchOps = fetchOps(testNum, 'Pictures/Static/');
try {
await userfile_mgr.getFileAssets(media_type, currentFetchOps);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error1 :${error}`);
expect(true).assertTrue();
done();
}
} catch (error) {
console.info(`${testNum}:: error2 :${error}`);
expect(false).assertTrue();
done();
}
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import { sleep } from '../../../../../../common';
export default function getUserFileMgr(abilityContext) {
describe('getUserFileMgr', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
/**
* @tc.number : SUB_USERFILE_MGR_GETUSERFILEMGR_00
* @tc.name : getUserFileMgr
* @tc.desc : Obtains a userFileMgr instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETUSERFILEMGR_00', 0, async function (done) {
try {
expect(userfile_mgr != undefined).assertTrue();
done();
} catch (error) {
console.info(`SUB_USERFILE_MGR_GETUSERFILEMGR_00 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
});
}
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "ohos.acts.multimedia.userfilemgr.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
}
]
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
{
"app":{
"bundleName":"ohos.acts.multimedia.userfilemgr",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("userfilemgr_fileAsset_js_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsUserFileMgrFileAsset"
}
ohos_app_scope("medialibrary_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("mediaLibrary_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("mediaLibrary_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":medialibrary_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for userfilemgr Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.userfilemgr",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Videos/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Audios/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in ModifyCb ModifyPro R_Cb R_Pro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in ModifyCb ModifyPro R_Cb R_Pro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in ModifyCb ModifyPro R_Cb R_Pro; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsUserFileMgrFileAsset.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 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 file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* 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 fileAssetCommitModifyCallback from './fileAssetCommitModifyCallback.test.ets'
import fileAssetCommitModifyPromise from './fileAssetCommitModifyPromise.test.ets'
import fileAssetFavoriteCallback from './fileAssetFavoriteCallback.test.ets'
import fileAssetFavoritePromise from './fileAssetFavoritePromise.test.ets'
import fileAssetGetThumbnailCallback from './fileAssetGetThumbnailCallback.test.ets'
import fileAssetGetThumbnailPromise from './fileAssetGetThumbnailPromise.test.ets'
import fileAssetOpenCallback from './fileAssetOpenCallback.test.ets'
import fileAssetOpenPromise from './fileAssetOpenPromise.test.ets'
export default function testsuite(abilityContext) {
fileAssetCommitModifyCallback(abilityContext)
fileAssetCommitModifyPromise(abilityContext)
fileAssetFavoriteCallback(abilityContext)
fileAssetFavoritePromise(abilityContext)
fileAssetGetThumbnailCallback(abilityContext)
fileAssetGetThumbnailPromise(abilityContext)
fileAssetOpenCallback(abilityContext)
fileAssetOpenPromise(abilityContext)
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
getPermission,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetCommitModifyCallback(abilityContext) {
describe('fileAssetCommitModifyCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAsset')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const checkCommitModify = async function (done, testNum, media_type, fetchOp, prop, val) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const oldVal = asset[prop]
asset[prop] = val;
await asset.commitModify(async (err) => {
if (err) {
console.info(`${testNum} err : ${err}`)
expect.assertFail();
done();
return;
}
asset[prop] = oldVal;
await asset.commitModify();
await fetchFileResult.close();
done();
});
} catch (error) {
console.info(`${testNum} error : ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_01
* @tc.name : commitModify
* @tc.desc : image asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/ModifyCb/', '01.jpg');
let prop = 'displayName'
let val = IMAGE_TYPE.toString() + '.jpg'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_02
* @tc.name : commitModify
* @tc.desc : audio asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/ModifyCb/', '01.mp3');
let prop = 'displayName'
let val = AUDIO_TYPE.toString() + '.mp3'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_03
* @tc.name : commitModify
* @tc.desc : video asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/ModifyCb/', '01.mp4');
let prop = 'displayName'
let val = VIDEO_TYPE.toString() + '.mp4'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetCommitModifyPromise(abilityContext) {
describe('fileAssetCommitModifyPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAsset')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const checkCommitModify = async function (done, testNum, media_type, fetchOp, prop, val) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const oldVal = asset[prop]
asset[prop] = val;
await asset.commitModify();
asset[prop] = oldVal;
await asset.commitModify();
await fetchFileResult.close();
done();
} catch (error) {
console.info(`${testNum} error : ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_01
* @tc.name : commitModify
* @tc.desc : image asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/ModifyPro/', '01.jpg');
let prop = 'displayName'
let val = IMAGE_TYPE.toString() + '.jpg'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_02
* @tc.name : commitModify
* @tc.desc : audio asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/ModifyPro/', '01.mp3');
let prop = 'displayName'
let val = AUDIO_TYPE.toString() + '.mp3'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_03
* @tc.name : commitModify
* @tc.desc : video asset modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/ModifyPro/', '01.mp4');
let prop = 'displayName'
let val = VIDEO_TYPE.toString() + '.mp4'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
nameFetchOps,
checkAssetsCount,
getPermission,
} from '../../../../../../common';
export default function fileAssetFavoriteCallback(abilityContext) {
describe('fileAssetFavoriteCallback', function () {
var userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFavorite');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const favoriteDefaultState = async function (done, testNum, media_type, fetchOp) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
asset.isFavorite(async (err, isFavorite) => {
if (err) {
expect(false).assertTrue();
await fetchFileResult.close();
done();
return;
}
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
done()
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
const favoriteByTrue = async function (done, testNum, media_type, fetchOp) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
asset.favorite(true, async (err) => {
if(err) {
console.info(`${testNum} failed err: ${err}`)
expect(false).assertTrue();
done();
return;
}
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(true);
await fetchFileResult.close();
done();
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
const favoriteByFalse = async function (done, testNum, media_type, fetchOp) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
await asset.favorite(true);
asset.favorite(false, async (err) => {
if(err) {
console.info(`${testNum} failed err: ${err}`)
expect(false).assertTrue();
done();
return;
}
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
done();
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(image) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '01.jpg')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002
* @tc.name : favorite
* @tc.desc : favorite(image) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '02.jpg')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003
* @tc.name : favorite
* @tc.desc : favorite(image) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '03.jpg')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(audio) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '01.mp3')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002
* @tc.name : favorite
* @tc.desc : favorite(audio) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '02.mp3')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003
* @tc.name : favorite
* @tc.desc : favorite(audio) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '03.mp3')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(video) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '01.mp4')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002
* @tc.name : favorite
* @tc.desc : favorite(video) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '02.mp4')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003
* @tc.name : favorite
* @tc.desc : favorite(video) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '03.mp4')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
nameFetchOps,
checkAssetsCount,
} from '../../../../../../common';
export default function fileAssetFavoritePromise(abilityContext) {
describe('fileAssetFavoritePromise', function () {
var userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFavorite');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const favoriteDefaultState = async function (done, testNum, media_type, fetchOp) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
done()
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
const favoriteByTrue = async function (done, testNum, media_type, fetchOp) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
await asset.favorite(true);
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(true);
await fetchFileResult.close();
done();
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
const favoriteByFalse = async function (done, testNum, media_type, fetchOp) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
await asset.favorite(true);
await asset.favorite(false);
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
done();
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(image) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '01.jpg')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002
* @tc.name : favorite
* @tc.desc : favorite(image) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '02.jpg')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003
* @tc.name : favorite
* @tc.desc : favorite(image) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '03.jpg')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(audio) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '01.mp3')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002
* @tc.name : favorite
* @tc.desc : favorite(audio) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '02.mp3')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003
* @tc.name : favorite
* @tc.desc : favorite(audio) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '03.mp3')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001
* @tc.name : isFavorite
* @tc.desc : isFavorite(video) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '01.mp4')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002
* @tc.name : favorite
* @tc.desc : favorite(video) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '02.mp4')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003
* @tc.name : favorite
* @tc.desc : favorite(video) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '03.mp4')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import image from '@ohos.multimedia.image';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetGetThumbnailCallback(abilityContext) {
describe('fileAssetGetThumbnailCallback', function () {
image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { });
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrGetThumbnailTest');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
async function testGetThumbnail(done, testNum, media_type, dOp, size) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
if (size == 'default') {
size = { width: 256, height: 256 };
asset.getThumbnail(async (err, pixelmap) => {
console.info(`${testNum}:: err1 :${err}`);
if (err != undefined) {
expect(false).assertTrue();
done();
return;
}
await pixelmap.getImageInfo((err, info) => {
console.info(`${testNum}:: err2 :${err}`);
if (err != undefined) {
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}:: width :${info.size.width} height :${info.size.height}`);
expect(info.size.width).assertEqual(size.width);
expect(info.size.height).assertEqual(size.height);
done();
});
})
} else {
asset.getThumbnail(size, async (err, pixelmap) => {
console.info(`${testNum}:: err1 :${err}`);
if (err != undefined) {
expect(false).assertTrue();
done();
return;
}
await pixelmap.getImageInfo((err, info) => {
console.info(`${testNum}:: err2 :${err}`);
if (err != undefined) {
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}:: width :${info.size.width} height :${info.size.height}`);
expect(info.size.width).assertEqual(size.width);
expect(info.size.height).assertEqual(size.height);
done();
});
})
}
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_001';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_002';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_001';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_002';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_001';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_002';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import image from '@ohos.multimedia.image';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetGetThumbnailPromise(abilityContext) {
describe('fileAssetGetThumbnailPromise', function () {
image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { });
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrGetThumbnailTest');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
async function testGetThumbnail(done, testNum, media_type, dOp, size,) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
console.info(`${testNum}:displayName ${asset.displayName}`)
let pixelmap;
if (size == 'default') {
size = { width: 256, height: 256 };
pixelmap = await asset.getThumbnail()
} else {
pixelmap = await asset.getThumbnail(size)
}
let info = await pixelmap.getImageInfo();
console.info(`${testNum}:: width :${info.size.width} height :${info.size.height}`);
expect(info.size.width).assertEqual(size.width);
expect(info.size.height).assertEqual(size.height);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_001
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_002
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
});
});
}
/*
* Copyright (C) 2021 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
nameFetchOps,
isNum,
} from '../../../../../../common';
export default function fileAssetOpenCallback(abilityContext) {
describe('fileAssetOpenCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAsset')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const rOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset.open('r', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
expect.assertFail();
done();
return;
}
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
console.log(' bytesRead: ' + res.bytesRead)
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
try {
await fileio.write(fd, buf);
expect.assertFail();
} catch (error) {
expect(true).assertTrue();
await asset.close(fd);
}
done();
});
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
expect.assertFail();
await asset.close(fd);
done();
}
}
const wOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset1 = await fetchFileResult.getNextObject();
asset.open('w', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
expect.assertFail();
done();
return;
}
expect(isNum(fd)).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
console.info(`${testNum} :: write: ${write}`);
expect(write).assertEqual(assetProps.write);
let buf1 = new ArrayBuffer(4096);
try {
await fileio.read(fd, buf1);
expect.assertFail();
} catch (error) {
expect(true).assertTrue();
}
done();
});
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
expect(false).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
}
const rwOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset.open('rw', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
expect.assertFail();
done();
return;
}
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
asset1 = await fetchFileResult.getNextObject();
fd1 = await asset1.open('r');
expect(isNum(fd1)).assertTrue();
let buf1 = new ArrayBuffer(4096);
await fileio.read(fd1, buf1);
let write = await fileio.write(fd, buf1);
expect(write).assertEqual(assetProps.write);
console.info(`res.bytesRead:${res.bytesRead},write:${write}`)
console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd);
await asset1.close(fd1);
done();
});
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
await asset.close(fd);
await asset1.close(fd1);
expect.assertFail();
done();
}
}
const closeTest = async function (done, testNum, media_type, fetchOp) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
asset.close(fd, async (err) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
expect.assertFail();
done();
return;
}
let count = 0
let buf = new ArrayBuffer(4096);
try {
await fileio.read(fd, buf);
} catch (error) {
count++
}
try {
await fileio.write(fd, buf);
} catch (error) {
count++
}
await sleep(1000)
expect(count).assertEqual(2);
done();
});
} catch (error) {
console.info(`${testNum} error:${error}`)
await asset.close(fd);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_001
* @tc.name : open('r')
* @tc.desc : open -r the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_001';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_002
* @tc.name : open('w')
* @tc.desc : open -w the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_002';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_003';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_001
* @tc.name : open('r')
* @tc.desc : open -r the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_001';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_002
* @tc.name : open('w')
* @tc.desc : open -w the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_002';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_003';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_001
* @tc.name : open('r')
* @tc.desc : open -r the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_001';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_002
* @tc.name : open('w')
* @tc.desc : open -w the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_002';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_003';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
//------------------------------------------------------------------------------------
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_01
* @tc.name : close
* @tc.desc : asset close the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/openClose/', '01.jpg');
await closeTest(done, testNum, media_type, fetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_02
* @tc.name : close
* @tc.desc : asset close the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/openClose/', '01.mp3');
await closeTest(done, testNum, media_type, fetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_03
* @tc.name : close
* @tc.desc : asset close the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/openClose/', '01.mp4');
await closeTest(done, testNum, media_type, fetchOp)
});
});
}
/*
* Copyright (C) 2021 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
nameFetchOps,
isNum,
} from '../../../../../../common';
export default function fileAssetOpenPromise(abilityContext) {
describe('fileAssetOpenPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAsset')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const rOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
console.log(' bytesRead: ' + res.bytesRead)
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
try {
await fileio.write(fd, buf);
expect.assertFail();
} catch (error) {
expect(true).assertTrue();
await asset.close(fd);
done();
}
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
expect.assertFail();
await asset.close(fd);
done();
}
}
const wOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset1 = await fetchFileResult.getNextObject();
fd = await asset.open('w');
expect(isNum(fd)).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
console.info(`${testNum} :: write: ${write}`);
expect(write).assertEqual(assetProps.write);
let buf1 = new ArrayBuffer(4096);
try {
await fileio.read(fd, buf1);
expect.assertFail();
} catch (error) {
expect(true).assertTrue();
}
done();
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
expect(false).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
}
const rwOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
fd = await asset.open('rw');
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
asset1 = await fetchFileResult.getNextObject();
fd1 = await asset1.open('r');
expect(isNum(fd1)).assertTrue();
let buf1 = new ArrayBuffer(4096);
await fileio.read(fd1, buf1);
let write = await fileio.write(fd, buf1);
expect(write).assertEqual(assetProps.write);
console.info(`res.bytesRead:${res.bytesRead},write:${write}`)
console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd);
await asset1.close(fd1);
done();
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
await asset.close(fd);
await asset1.close(fd1);
expect.assertFail();
done();
}
}
const closeTest = async function (done, testNum, media_type, fetchOp) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
await asset.close(fd);
let count = 0
let buf = new ArrayBuffer(4096);
try {
await fileio.read(fd, buf);
} catch (error) {
count++
}
try {
await fileio.write(fd, buf);
} catch (error) {
count++
}
await sleep(1000)
expect(count).assertEqual(2);
done();
} catch (error) {
console.info(`${testNum} error:${error}`)
await asset.close(fd);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_001
* @tc.name : open('r')
* @tc.desc : open -r the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_002
* @tc.name : open('w')
* @tc.desc : open -w the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_003';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_001
* @tc.name : open('r')
* @tc.desc : open -r the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_002
* @tc.name : open('w')
* @tc.desc : open -w the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_003';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_001
* @tc.name : open('r')
* @tc.desc : open -r the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_002
* @tc.name : open('w')
* @tc.desc : open -w the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_003
* @tc.name : open('rw')
* @tc.desc : open -rw the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_003';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
});
//--------------------------------------------------------------------------------
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_01
* @tc.name : close
* @tc.desc : asset close the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/openClose/', '02.jpg');
await closeTest(done, testNum, media_type, fetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_02
* @tc.name : close
* @tc.desc : asset close the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/openClose/', '02.mp3');
await closeTest(done, testNum, media_type, fetchOp)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03
* @tc.name : close
* @tc.desc : asset close the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/openClose/', '02.mp4');
await closeTest(done, testNum, media_type, fetchOp)
});
});
}
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "ohos.acts.multimedia.userfilemgr.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.READ_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_IMAGEVIDEO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_AUDIO",
"reason":"use ohos.permission.WRITE_MEDIA"
},
{
"name": "ohos.permission.WRITE_DOCUMENT",
"reason":"use ohos.permission.WRITE_MEDIA"
}
]
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
{
"app":{
"bundleName":"ohos.acts.multimedia.userfilemgr",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("userfilemgr_noPermission_js_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsUserFileMgrNoPermission"
}
ohos_app_scope("medialibrary_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("mediaLibrary_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("mediaLibrary_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":medialibrary_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for userfilemgr Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.userfilemgr",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
]
},
{
"type": "ShellKit",
"run-command": [
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsUserFileMgrNoPermission.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 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 file from '@system.file';
import { Core, ExpectExtend, InstrumentLog, ReportExtend } from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* 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 userFileMgrNoPermissionCallback from './userFileMgrNoPermissionCallback.test.ets'
import userFileMgrNoPermissionPromise from './userFileMgrNoPermissionPromise.test.ets'
export default function testsuite(abilityContext) {
userFileMgrNoPermissionCallback(abilityContext)
userFileMgrNoPermissionPromise(abilityContext)
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册