diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index a8391365941ac19c4cfaa570195b6f87253f97c2..cc494a3ba0aabb80249797008d5eec89edc2ae07 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -54,6 +54,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 = [ diff --git a/multimedia/userfilemgr/common.js b/multimedia/userfilemgr/common.js new file mode 100755 index 0000000000000000000000000000000000000000..0bb8bbe1a44620d926591c97bf76c0a7b2649be1 --- /dev/null +++ b/multimedia/userfilemgr/common.js @@ -0,0 +1,161 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_album/AppScope/app.json b/multimedia/userfilemgr/userfilemgr_album/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..103cf8e6368fd2a71f15ca4506e1ce4e48a58669 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "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 + } + } +} diff --git a/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/media/app_icon.png b/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_album/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_album/BUILD.gn b/multimedia/userfilemgr/userfilemgr_album/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5a3ec53b4fd3bf74893236475cea777e1237f996 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/BUILD.gn @@ -0,0 +1,40 @@ +# 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" +} diff --git a/multimedia/userfilemgr/userfilemgr_album/Test.json b/multimedia/userfilemgr/userfilemgr_album/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1304522e8816791b36a1fd4ac987fb023ce66d80 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/Test.json @@ -0,0 +1,60 @@ +{ + "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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..14f230e140160dc5f94ecc462304621178f4cf64 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +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; + } +} diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/index/index.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..ac301f98781abd45f4d9d98fd7ffecfde9053ed9 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/second/second.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/List.test.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..3eb3b9f14c2b370bf89120b391eb435ea36ccca1 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 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) +} diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyCallback.test.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..fa801a080c030fd28760ca7e275d1e590e5d8a91 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyCallback.test.ets @@ -0,0 +1,120 @@ +/* + * 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); + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyPromise.test.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..402b363e4f065cf6cc528c05c9a93e4a73b8b0f7 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumCommitModifyPromise.test.ets @@ -0,0 +1,118 @@ +/* + * 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); + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1bc62eb5df94099511cc1afff05a7050605445cc --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets @@ -0,0 +1,122 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..145348be5fbf7ef394c39260b9b6d26b59031613 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets @@ -0,0 +1,130 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/module.json b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..806a9cad84b819f0f66516ebf3909fd080036564 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/module.json @@ -0,0 +1,83 @@ +{ + "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" + } + ] + } +} diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..32237ee203edf64926964fb238fa44e396ddf577 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/media/icon.png b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/profile/main_pages.json b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..96b478210df9884592229ae2db6f6bb7f86c14f4 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_album/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_album/signature/openharmony_sx.p7b b/multimedia/userfilemgr/userfilemgr_album/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_album/signature/openharmony_sx.p7b differ diff --git a/multimedia/userfilemgr/userfilemgr_base/AppScope/app.json b/multimedia/userfilemgr/userfilemgr_base/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..25f1a749f8b57b96979879112a1f5bd21548a92c --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "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 + } + } +} diff --git a/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/media/app_icon.png b/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_base/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_base/BUILD.gn b/multimedia/userfilemgr/userfilemgr_base/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7a40f4adae56a18a7708946f290bd6cb402927d6 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/BUILD.gn @@ -0,0 +1,40 @@ +# 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" +} diff --git a/multimedia/userfilemgr/userfilemgr_base/Test.json b/multimedia/userfilemgr/userfilemgr_base/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..16338711826c78dd04fe847fb103b8263081e56f --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/Test.json @@ -0,0 +1,60 @@ +{ + "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 diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +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; + } +} diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +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 diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/index/index.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..624cad290665fcd29dcd579d9582a300479e8ad7 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,68 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/second/second.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/List.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..76b4d9cb3ae3b90c02b043aafbdf026f78f758cf --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,27 @@ +/* + * 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) +} diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsCallback.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..febe59e5c54250d912f4f29dfdc3ae1d45bb4ceb --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsCallback.test.ets @@ -0,0 +1,193 @@ +/* + * 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(); + } + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsPromise.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9d5ce2001049bf2a8927a38932d3e156554ccd9 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getAlbumsPromise.test.ets @@ -0,0 +1,179 @@ +/* + * 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(); + } + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsCallback.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0dee964f546163674e80e87c985304485a5a879 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsCallback.test.ets @@ -0,0 +1,170 @@ +/* + * 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(); + } + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsPromise.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2873129cb8c61eca21b7023e4d9c786fc39d130 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getFileAssetsPromise.test.ets @@ -0,0 +1,158 @@ +/* + * 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(); + } + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getUserFileMgr.test.ets b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getUserFileMgr.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..64851258fe3bf5813edfd133aee16c028465d72f --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/ets/test/getUserFileMgr.test.ets @@ -0,0 +1,58 @@ +/* + * 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(); + } + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/module.json b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..fe145668c4e2f9bbcd00e1a64078cb2538ba2689 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/module.json @@ -0,0 +1,83 @@ +{ + "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" + } + ] + } +} diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/media/icon.png b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/profile/main_pages.json b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_base/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_base/signature/openharmony_sx.p7b b/multimedia/userfilemgr/userfilemgr_base/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_base/signature/openharmony_sx.p7b differ diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/app.json b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..25f1a749f8b57b96979879112a1f5bd21548a92c --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "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 + } + } +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/media/app_icon.png b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_fileAsset/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/BUILD.gn b/multimedia/userfilemgr/userfilemgr_fileAsset/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..56621e4c637cedeae5904b50daff381b12d72a68 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/BUILD.gn @@ -0,0 +1,40 @@ +# 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" +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/Test.json b/multimedia/userfilemgr/userfilemgr_fileAsset/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..381aa4ed78e0d989267d626e4d2d845f57d3b6b8 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/Test.json @@ -0,0 +1,68 @@ +{ + "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 diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +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; + } +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +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 diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/index/index.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..624cad290665fcd29dcd579d9582a300479e8ad7 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,68 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/second/second.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/List.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..9ed9e432c7ab0cca4e2ffd221f24bc0330c73195 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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) +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyCallback.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..8ba9ab76196adc4a14fdb225eb6557832f03f4bd --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyCallback.test.ets @@ -0,0 +1,128 @@ +/* + * 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) + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyPromise.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..a145e129735b4cbdd6a28783bd2a8e0f01ce5732 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetCommitModifyPromise.test.ets @@ -0,0 +1,119 @@ +/* + * 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) + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoriteCallback.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoriteCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..273bbbde3ebcac0f075781770dedb9105f8b6dbe --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoriteCallback.test.ets @@ -0,0 +1,257 @@ +/* + * 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) + }); + }); +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoritePromise.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoritePromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c6cfb7d0ccfe16b451a4f90b8c3b12c6d214118 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetFavoritePromise.test.ets @@ -0,0 +1,233 @@ +/* + * 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) + }); + }); +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailCallback.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..097fbfddf57e4dd1ac4a66d58e5a9e1b5a6e6373 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailCallback.test.ets @@ -0,0 +1,202 @@ +/* + * 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) + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailPromise.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..71602272ac4e1042cfecc2652ce54d0b85f571a5 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetGetThumbnailPromise.test.ets @@ -0,0 +1,171 @@ +/* + * 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) + }); + }); +} + diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenCallback.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..356f097c7bdffa8b2a572a5282f45ba9869ff764 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenCallback.test.ets @@ -0,0 +1,429 @@ +/* + * 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) + }); + }); +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenPromise.test.ets b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..70536a80e6f5cc48403ffe74ca88eb1c17b28c4b --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/ets/test/fileAssetOpenPromise.test.ets @@ -0,0 +1,405 @@ +/* + * 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) + }); + }); +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/module.json b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..fe145668c4e2f9bbcd00e1a64078cb2538ba2689 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/module.json @@ -0,0 +1,83 @@ +{ + "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" + } + ] + } +} diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/media/icon.png b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/profile/main_pages.json b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_fileAsset/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_fileAsset/signature/openharmony_sx.p7b b/multimedia/userfilemgr/userfilemgr_fileAsset/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_fileAsset/signature/openharmony_sx.p7b differ diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/app.json b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..103cf8e6368fd2a71f15ca4506e1ce4e48a58669 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "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 + } + } +} diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/media/app_icon.png b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_noPermission/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/BUILD.gn b/multimedia/userfilemgr/userfilemgr_noPermission/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..635e201ddbfee370429e10ea34a8bd7cc075bea6 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/BUILD.gn @@ -0,0 +1,40 @@ +# 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" +} diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/Test.json b/multimedia/userfilemgr/userfilemgr_noPermission/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..11f9996f03f8c419e5cb9fc419a8a36d491b925b --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/Test.json @@ -0,0 +1,45 @@ +{ + "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 diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..14f230e140160dc5f94ecc462304621178f4cf64 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +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; + } +} diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +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 diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/index/index.ets b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..ac301f98781abd45f4d9d98fd7ffecfde9053ed9 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/second/second.ets b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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 diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/List.test.ets b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..8742e87b83310b1cb4ee61555e7ea131f20bde6b --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * 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) +} diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionCallback.test.ets b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..2f47d0fc4edcf83f091bd0e70bef62901a263b53 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionCallback.test.ets @@ -0,0 +1,240 @@ +/* + * 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, +} from '../../../../../../common'; + + +export default function userFileMgrNoPermissionCallback(abilityContext) { + describe('userFileMgrNoPermissionCallback', 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'); + }); + + const getFileAssetsTest = async function (done, testNum, media_type) { + try { + await userfile_mgr.getFileAssets(media_type, allFetchOp(), async (err, fetchFileResult) => { + if (err != undefined) { + console.info(`${testNum}, err: ${err}`); + expect(true).assertTrue(); + done(); + return; + } + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const createAssetTest = async function (done, testNum, type, name, path) { + try { + await userfile_mgr.createAsset(type, name, path, async (err, creatAsset) => { + if (err != undefined) { + console.info(`${testNum}, err: ${err}`); + expect(true).assertTrue(); + done(); + return; + } + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const getAlbumsTest = async function (done, testNum, media_type) { + try { + await userfile_mgr.getAlbums(media_type, allFetchOp(), async (err, albumList) => { + if (err != undefined) { + console.info(`${testNum}, err: ${err}`); + expect(true).assertTrue(); + done(); + return; + } + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_01 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_01'; + let media_type = [IMAGE_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_02 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_02'; + let media_type = [AUDIO_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_03 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_CALLBACK_03'; + let media_type = [VIDEO_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + //--------------------------------------------------------------------------------------- + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_01 + * @tc.name : createAsset + * @tc.desc : createAsset(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_01'; + let type = IMAGE_TYPE; + let name = new Date().getTime() + '.jpg'; + let path = 'Pictures/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_02 + * @tc.name : createAsset + * @tc.desc : createAsset(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_02'; + let type = AUDIO_TYPE; + let name = new Date().getTime() + '.mp3'; + let path = 'Audios/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_03 + * @tc.name : createAsset + * @tc.desc : createAsset(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_CALLBACK_03'; + let type = VIDEO_TYPE; + let name = new Date().getTime() + '.mp4'; + let path = 'Videos/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + //-------------------------------------------------------------------------------------- + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_01 + * @tc.name : getAlbums + * @tc.desc : getAlbums(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_01'; + let media_type = [IMAGE_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_02 + * @tc.name : getAlbums + * @tc.desc : getAlbums(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_02'; + let media_type = [AUDIO_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_03 + * @tc.name : getAlbums + * @tc.desc : getAlbums(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_CALLBACK_03'; + let media_type = [VIDEO_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionPromise.test.ets b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f984139985e580da527fd8342a2374560a2066ca --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/ets/test/userFileMgrNoPermissionPromise.test.ets @@ -0,0 +1,219 @@ +/* + * 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, +} from '../../../../../../common'; + + +export default function userFileMgrNoPermissionPromise(abilityContext) { + describe('userFileMgrNoPermissionPromise', 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'); + }); + + const getFileAssetsTest = async function (done, testNum, media_type) { + try { + await userfile_mgr.getFileAssets(media_type, allFetchOp()); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(true).assertTrue(); + done(); + } + } + + const createAssetTest = async function (done, testNum, type, name, path) { + try { + await userfile_mgr.createAsset(type, name, path); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(true).assertTrue(); + done(); + } + } + + const getAlbumsTest = async function (done, testNum, media_type) { + try { + await userfile_mgr.getAlbums(media_type, allFetchOp()); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(true).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_01 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_01'; + let media_type = [IMAGE_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_02 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_02'; + let media_type = [AUDIO_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_03 + * @tc.name : getFileAssets + * @tc.desc : getFileAssets(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETFILEASSETS_NOPERMISSION_PROMISE_03'; + let media_type = [VIDEO_TYPE]; + await getFileAssetsTest(done, testNum, media_type); + }); + + //--------------------------------------------------------------------------------------- + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_01 + * @tc.name : createAsset + * @tc.desc : createAsset(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_01'; + let type = IMAGE_TYPE; + let name = new Date().getTime() + '.jpg'; + let path = 'Pictures/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_02 + * @tc.name : createAsset + * @tc.desc : createAsset(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_02'; + let type = AUDIO_TYPE; + let name = new Date().getTime() + '.mp3'; + let path = 'Audios/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_03 + * @tc.name : createAsset + * @tc.desc : createAsset(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_CREATEASSET_NOPERMISSION_PROMISE_03'; + let type = VIDEO_TYPE; + let name = new Date().getTime() + '.mp4'; + let path = 'Videos/Create/'; + await createAssetTest(done, testNum, type, name, path); + }); + + //-------------------------------------------------------------------------------------- + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_01 + * @tc.name : getAlbums + * @tc.desc : getAlbums(image) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_01', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_01'; + let media_type = [IMAGE_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_02 + * @tc.name : getAlbums + * @tc.desc : getAlbums(audio) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_02', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_02'; + let media_type = [AUDIO_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + + /** + * @tc.number : SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_03 + * @tc.name : getAlbums + * @tc.desc : getAlbums(video) with no permission + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_03', 0, async function (done) { + const testNum = 'SUB_USERFILE_MGR_GETALBUMS_NOPERMISSION_PROMISE_03'; + let media_type = [VIDEO_TYPE]; + await getAlbumsTest(done, testNum, media_type); + }); + }); +} + + diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/module.json b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..806a9cad84b819f0f66516ebf3909fd080036564 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/module.json @@ -0,0 +1,83 @@ +{ + "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" + } + ] + } +} diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/element/string.json b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..32237ee203edf64926964fb238fa44e396ddf577 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/media/icon.png b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/profile/main_pages.json b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..96b478210df9884592229ae2db6f6bb7f86c14f4 --- /dev/null +++ b/multimedia/userfilemgr/userfilemgr_noPermission/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/userfilemgr/userfilemgr_noPermission/signature/openharmony_sx.p7b b/multimedia/userfilemgr/userfilemgr_noPermission/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/userfilemgr/userfilemgr_noPermission/signature/openharmony_sx.p7b differ