diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index 3c4fc742493c9edfef7a5b2f1885f1e6fbaff011..a544093e7d4527d4438a8b83221eee8f14d2ffbd 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") @@ -43,6 +43,7 @@ group("multimedia") { "medialibrary/mediaLibrary_fileKey:mediaLibrary_fileKey_hap", "medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap", "medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap", + "medialibrary/mediaLibrary_js:mediaLibrary_js_hap", "medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap", ] } else { diff --git a/multimedia/medialibrary/mediaLibrary_js/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_js/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "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/medialibrary/mediaLibrary_js/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_js/BUILD.gn b/multimedia/medialibrary/mediaLibrary_js/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7dc770916b0338190261b5070315d0328504b2b3 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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("mediaLibrary_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 = "ActsMediaLibraryJs" +} + +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/medialibrary/mediaLibrary_js/Test.json b/multimedia/medialibrary/mediaLibrary_js/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..8b026bf4f617a81ec948da0efa6a35fb741e1ad5 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/Test.json @@ -0,0 +1,63 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "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", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,On,Off,OnAlbum,OffAlbum}", + "mkdir -pv /storage/media/100/local/files/Videos//{Static,On,Off}", + "mkdir -pv /storage/media/100/local/files/Audios/{Static,On,Off}", + "mkdir -pv /storage/media/100/local/files/Documents/{Static,On,Off}", + + "for d in Static On Off OnAlbum OffAlbum; 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 On Off; 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 On Off; 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;", + "for d in Static On Off; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; 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": [ + "ActsMediaLibraryJs.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..624cad290665fcd29dcd579d9582a300479e8ad7 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b6d8ffb46998974b3e2f02b4b3cc899ef4f4c227 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets' +import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' + +export default function testsuite(abilityContext) { + mediaLibraryTestPromise(abilityContext) + mediaLibraryTestPromiseOnOffTest(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..263b91dcbd460146c8fa197bda646d8f6545b026 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets @@ -0,0 +1,708 @@ +/* + * 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 mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import fileio from '@ohos.fileio'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, + isNum, +} from '../../../../../../common'; + + +export default function mediaLibraryTestPromiseTest(abilityContext) { + describe('mediaLibraryTestPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + + let imageAndVideofetchOp = { + selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' + + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)', + selectionArgs: ['Videos/Static/', 'Pictures/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString()], + }; + let imageAndVideoAndfilefetchOp = { + selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' + + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)', + selectionArgs: ['Documents/Static/', 'Videos/Static/', 'Pictures/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString(), FILE_TYPE.toString()], + order: FILEKEY.DATE_ADDED + " DESC", + }; + let imageAndVideoAndfileAndAudiofetchOp = { + selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' + + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)', + selectionArgs: ['Documents/Static/', 'Videos/Static/', 'Pictures/Static/', 'Audios/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString(), FILE_TYPE.toString(), AUDIO_TYPE.toString(),], + order: FILEKEY.DATE_ADDED + " DESC", + }; + + async function copyFile(fd1, fd2) { + let stat = await fileio.fstat(fd1); + let buf = new ArrayBuffer(stat.size); + await fileio.read(fd1, buf); + await fileio.write(fd2, buf); + } + + const props = { + image: { + mimeType: 'image/*', + displayName: '01.jpg', + relativePath: 'Pictures/Static/', + size: 348113, + mediaType: IMAGE_TYPE.toString(), + title: '01', + width: 1279, + height: 1706, + orientation: 0, + duration: '0', + albumId: '1118', + }, + video: { + mimeType: 'video/mp4', + displayName: '01.mp4', + relativePath: 'Videos/Static/', + size: 4853005, + mediaType: VIDEO_TYPE.toString(), + title: '01', + width: 1280, + height: 720, + orientation: 0, + duration: '10100', + }, + audio: { + mimeType: 'audio/mpeg', + displayName: '01.mp3', + relativePath: 'Audios/Static/', + size: 1958311, + mediaType: AUDIO_TYPE.toString(), + title: '01', + artist: '元数据测试', + width: 219600, + height: 219600, + orientation: 0, + duration: '219600', + }, + file: { + mimeType: 'file/*', + displayName: '01.dat', + relativePath: 'Documents/Static/', + size: 10, + mediaType: FILE_TYPE.toString(), + title: '01', + width: 0, + height: 0, + orientation: 0, + duration: '0', + } + } + + async function checkFileAssetAttr(done, testNum, fetchOps, type, count, typesArr) { + try { + const fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, count); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + if (count > 1) { + type = asset.mimeType.match(/[a-z]+/g)[0] + } + if (type == 'audio') { + expect(asset.artist).assertEqual(props[type].artist); + } + if (typesArr) { + let assetList = await fetchFileResult.getAllObject(); + for (const assetItem of assetList) { + expect(typesArr.includes(assetItem.mimeType)).assertTrue(); + } + } + if (!isNum(asset.dateTaken)) { + expect(false).assertTrue(); + done(); + return; + } + expect(asset.mimeType).assertEqual(props[type].mimeType); + expect(asset.displayName).assertEqual(props[type].displayName); + expect(asset.relativePath).assertEqual(props[type].relativePath); + expect(asset.size).assertEqual(props[type].size); + expect(asset.mediaType.toString()).assertEqual(props[type].mediaType); + expect(asset.title.toString()).assertEqual(props[type].title); + expect(asset.width).assertEqual(props[type].width); + expect(asset.height).assertEqual(props[type].height); + expect(asset.orientation).assertEqual(props[type].orientation); + expect(asset.duration.toString()).assertEqual(props[type].duration); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + const checkGetPublicDirectory = async (done, testNum, dir, val) => { + try { + const res = await media.getPublicDirectory(dir); + expect(res).assertEqual(val); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + const getFileAssetsAbnormal = async (done, testNum, fetchOps) => { + try { + await media.getFileAssets(fetchOps); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(true).assertTrue(); + done(); + } + } + const getFileAssetsZero = async (done, testNum, fetchOps) => { + try { + let fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 0); + expect(checkAssetCountPass).assertTrue(); + + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + const createAssetTest = async (done, testNum, fetchOps, type, name, path) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + const creatAsset = await media.createAsset(type, name, path); + const fd = await asset.open('rw'); + const creatAssetFd = await creatAsset.open('rw'); + await copyFile(fd, creatAssetFd); + await creatAsset.close(creatAssetFd); + await asset.close(fd); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + const createAssetSameNameTest = async (done, testNum, fetchOps, type, name, path) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + const creatAsset = await media.createAsset(type, name, path); + const fd = await asset.open('rw'); + const creatAssetFd = await creatAsset.open('rw'); + await copyFile(fd, creatAssetFd); + await creatAsset.close(creatAssetFd); + await asset.close(fd); + try { + await media.createAsset(type, name, path); + expect(false).assertTrue(); + done(); + } catch (error) { + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 + * @tc.name : getMediaLibrary + * @tc.desc : Obtains a MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { + try { + expect(media != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001'; + let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = 'image'; + let count = 1; + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002'; + let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE); + let type = 'video'; + let count = 1; + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003'; + let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE); + let type = 'audio'; + let count = 1; + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004'; + let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE); + let type = 'file'; + let count = 1; + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005'; + let currentFetchOps = imageAndVideofetchOp; + let type = 'video'; + let count = 2; + let typesArr = ['image/*', 'video/mp4'] + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006'; + let currentFetchOps = imageAndVideoAndfilefetchOp; + let type = 'file'; + let count = 3; + let typesArr = ['image/*', 'video/mp4', 'file/*'] + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006'; + let currentFetchOps = imageAndVideoAndfileAndAudiofetchOp; + let type = 'audio'; + let count = 4; + let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg'] + await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + '= ?', + selectionArgs: [], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008'; + await getFileAssetsZero(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + 'abc= ?', + selectionArgs: [AUDIO_TYPE.toString()], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009'; + await getFileAssetsAbnormal(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + '= ?', + selectionArgs: [111], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010'; + await getFileAssetsZero(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { + let currentFetchOps = { + selections: 'abc' + '= ?', + selectionArgs: [AUDIO_TYPE.toString()], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011'; + await getFileAssetsAbnormal(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_CAMERA + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001'; + let dir = mediaLibrary.DirectoryType.DIR_CAMERA; + let val = 'Camera/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002'; + let dir = mediaLibrary.DirectoryType.DIR_VIDEO; + let val = 'Videos/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003'; + let dir = mediaLibrary.DirectoryType.DIR_IMAGE; + let val = 'Pictures/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004'; + let dir = mediaLibrary.DirectoryType.DIR_AUDIO; + let val = 'Audios/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004'; + let dir = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + let val = 'Documents/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory 110 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { + try { + await media.getPublicDirectory(110); + console.info('MediaLibraryTest : getPublicDirectory 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getPublicDirectory 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001'; + let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = IMAGE_TYPE; + let name = new Date().getTime() + '.jpg'; + let path = 'Pictures/Create/'; + await createAssetTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002'; + let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = IMAGE_TYPE; + let name = new Date().getTime() + '.jpg'; + let path = 'Pictures/Create/'; + await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path) + + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003'; + let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE); + let type = VIDEO_TYPE; + let name = new Date().getTime() + '.mp4'; + let path = 'Videos/Create/'; + await createAssetTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004'; + let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE); + let type = VIDEO_TYPE; + let name = new Date().getTime() + '.mp4'; + let path = 'Videos/Create/'; + await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005'; + let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE); + let type = AUDIO_TYPE; + let name = new Date().getTime() + '.mp3'; + let path = 'Audios/Create/'; + await createAssetTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006'; + let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE); + let type = AUDIO_TYPE; + let name = new Date().getTime() + '.mp3'; + let path = 'Audios/Create/'; + await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007'; + let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE); + let type = FILE_TYPE; + let name = new Date().getTime() + '.dat'; + let path = 'Documents/Create/'; + await createAssetTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008'; + let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE); + let type = FILE_TYPE; + let name = new Date().getTime() + '.dat'; + let path = 'Documents/Create/'; + await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001'; + let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = IMAGE_TYPE; + let name = new Date().getTime() + '.jpg'; + let path = 'Pictures/Create/Temp'; + await createAssetTest(done, testNum, currentFetchOps, type, name, path) + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..834e008af429a52dfc2824812105299b27c9a174 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets @@ -0,0 +1,444 @@ +/* + * 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 mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + albumFetchOps, + getPermission, + checkAlbumsCount, +} from '../../../../../../common'; + +export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { + describe('mediaLibraryTestPromiseOnOffTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + + const onTest = async (done, testNum, type, fetchOps) => { + try { + let conut = 0; + media.on(type, () => { conut++; }); + const fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await sleep(1000) + expect(conut > 0).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + const offTest = async (done, testNum, type, fetchOps) => { + try { + let conut = 0; + media.on(type, () => { + conut++; + }); + await sleep(200) + const fetchFileResult = await media.getFileAssets(fetchOps); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + media.off(type); + await sleep(200) + await asset.commitModify(); + await sleep(1000) + expect(conut).assertEqual(0); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001 + * @tc.name : ON + * @tc.desc : ON Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) { + let type = 'imageChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001'; + let currentFetchOps = fetchOps('Pictures/On/', IMAGE_TYPE); + await onTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002 + * @tc.name : ON + * @tc.desc : ON Video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) { + let type = 'videoChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002'; + let currentFetchOps = fetchOps('Videos/On/', VIDEO_TYPE); + await onTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003 + * @tc.name : ON + * @tc.desc : ON Audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) { + let type = 'audioChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003'; + let currentFetchOps = fetchOps('Audios/On/', AUDIO_TYPE); + await onTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004 + * @tc.name : ON + * @tc.desc : ON File ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) { + let type = 'fileChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004'; + let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE); + await onTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005 + * @tc.name : ON + * @tc.desc : ON ALBUM + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005' + try { + let conut = 0; + media.on('albumChange', () => { + conut++; + }); + let currentFetchOps = albumFetchOps('Pictures/', 'OnAlbum', IMAGE_TYPE); + const albumList = await media.getAlbums(currentFetchOps); + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, 1); + if (!albumCountPass) return; + const album = albumList[0]; + const oldName = album.albumName + album.albumName = album.albumName + 'changename'; + await album.commitModify(); + await sleep(1000) + expect(conut > 0).assertTrue(); + album.albumName = oldName; + await album.commitModify(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON DEVICE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('deviceChange', () => { + console.info('MediaLibraryTest : on 006 callback'); + conut++; + }); + let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE); + const fetchFileResult = await media.getFileAssets(currentFetchOps); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut == 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON REMOTE_FILE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('remoteFileChange', () => { + console.info('MediaLibraryTest : on 007 callback'); + conut++; + }); + + let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE); + const fetchFileResult = await media.getFileAssets(currentFetchOps); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut == 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001 + * @tc.name : off + * @tc.desc : off Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) { + let type = 'imageChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001'; + let currentFetchOps = fetchOps('Pictures/Off/', IMAGE_TYPE); + await offTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002 + * @tc.name : off + * @tc.desc : off video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) { + let type = 'videoChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002'; + let currentFetchOps = fetchOps('Videos/Off/', VIDEO_TYPE); + await offTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003 + * @tc.name : off + * @tc.desc : off audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) { + let type = 'audioChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003'; + let currentFetchOps = fetchOps('Audios/Off/', AUDIO_TYPE); + await offTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004 + * @tc.name : off + * @tc.desc : off file ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) { + let type = 'fileChange' + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004'; + let currentFetchOps = fetchOps('Documents/Off/', FILE_TYPE); + await offTest(done, testNum, type, currentFetchOps) + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 + * @tc.name : off + * @tc.desc : off device ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006', 0, async function (done) { + try { + media.on('deviceChange', () => { + console.info('MediaLibraryTest : off 006 failed'); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE); + const fetchFileResult = await media.getFileAssets(currentFetchOps); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'deviceChange'; + media.off('deviceChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 006 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007 + * @tc.name : off + * @tc.desc : off remoteFile ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007', 0, async function (done) { + try { + media.on('remoteFileChange', () => { + console.info('MediaLibraryTest : off 007 failed'); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + + media.off('remoteFileChange'); + let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE); + const fetchFileResult = await media.getFileAssets(currentFetchOps); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'remoteFileChange'; + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 007 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001 + * @tc.name : release + * @tc.desc : Release MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) { + try { + await media.release(); + console.info('MediaLibraryTest : release 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : release 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + }); +} + + diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..82fb1970953e8e320b149a3885c079feaf97b750 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "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.mediaLibrary.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_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js/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/medialibrary/mediaLibrary_js/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_js/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_js/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/List.test.ets index 139c43ebc9d0bdcb15ab1f27da0bf207f92f2377..efca2799fbe7de97e65c8c414b938819252f80c2 100755 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/List.test.ets @@ -17,8 +17,6 @@ import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets' import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets' import fileTestCallBackTest from './fileTestCallBack.test.ets' import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets' -import mediaLibraryTestPromiseTest from './mediaLibraryTestPromise.test.ets' -import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' export default function testsuite(abilityContext) { getPermissionTest() @@ -26,6 +24,4 @@ export default function testsuite(abilityContext) { fileAssetTestCallbackTest(abilityContext) fileTestCallBackTest(abilityContext) mediaLibraryTestCallBackTest(abilityContext) - mediaLibraryTestPromiseTest(abilityContext) - mediaLibraryTestPromiseOnOffTest(abilityContext) } diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets deleted file mode 100755 index 91bec658c0769f483fed29eebb7001ccc9e18f81..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets +++ /dev/null @@ -1,917 +0,0 @@ -/* - * 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 mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, -} from '../../../../../../common'; -let fileKeyObj = mediaLibrary.FileKey; -let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; -let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; -let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; -let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; -let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - -let imageType = mediaLibrary.MediaType.IMAGE; -let videoType = mediaLibrary.MediaType.VIDEO; -let audioType = mediaLibrary.MediaType.AUDIO; -let fileType = mediaLibrary.MediaType.FILE; - -let imagesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; -let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; -let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let filesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], -}; - -let imageRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Static01/', imageType.toString()], -}; -let videoRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Static01/', videoType.toString()], -}; -let audioRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Static01/', audioType.toString()], -}; -let fileRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Static01/', fileType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", -}; - -let imageAndVideofetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString()], -}; -let imageAndVideoAndfilefetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString(), fileType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", -}; -let imageAndVideoAndfileAndAudiofetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', 'Audios/Static01/', imageType.toString(), videoType.toString(), fileType.toString(), audioType.toString(),], - order: fileKeyObj.DATE_ADDED + " DESC", -}; - - -let allTypefetchOp = { - selections: '', - selectionArgs: [], -}; - -async function copyFile(fd1, fd2) { - let stat = await fileio.fstat(fd1); - let buf = new ArrayBuffer(stat.size); - await fileio.read(fd1, buf); - await fileio.write(fd2, buf); -} - -const props = { - image: { - mimeType: 'image/*', - displayName: '01.jpg', - relativePath: 'Pictures/Static01/', - size: '348113', - mediaType: imageType.toString(), - title: '01', - width: '1279', - height: '1706', - orientation: '0', - duration: '0', - albumId: '1118', - }, - video: { - mimeType: 'video/mp4', - displayName: '01.mp4', - relativePath: 'Videos/Static01/', - size: '4853005', - mediaType: videoType.toString(), - title: '01', - width: '1280', - height: '720', - orientation: '0', - duration: '10100', - }, - audio: { - mimeType: 'audio/mpeg', - displayName: '01.mp3', - relativePath: 'Audios/Static01/', - size: '1958311', - mediaType: audioType.toString(), - title: '01', - artist: '元数据测试', - width: '219600', - height: '219600', - orientation: '0', - duration: '219600', - }, - file: { - mimeType: 'file/*', - displayName: '01.dat', - relativePath: 'Documents/Static01/', - size: '10', - mediaType: fileType.toString(), - title: '01', - width: '0', - height: '0', - orientation: '0', - duration: '0', - } -} -function isNum(value) { - return typeof value === 'number' && !isNaN(value); -} -async function checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) { - expect(fetchFileResult != undefined).assertTrue(); - expect(fetchFileResult.getCount() == count).assertTrue(); - let asset = await fetchFileResult.getFirstObject(); - - if (count > 1) { - type = asset.mimeType.match(/[a-z]+/g)[0] - } - if (type == 'audio' && asset.artist != props[type].artist) { - expect(false).assertTrue(); - done(); - } - if (typesArr) { - let assetList = await fetchFileResult.getAllObject(); - for (const assetItem of assetList) { - expect(typesArr.includes(assetItem.mimeType)).assertTrue(); - } - } - if(!isNum(asset.dateTaken)) { - expect(false).assertTrue(); - done(); - } - if ( - asset.mimeType != props[type].mimeType || - asset.displayName != props[type].displayName || - asset.relativePath != props[type].relativePath || - asset.size != props[type].size || - asset.mediaType != props[type].mediaType || - asset.title != props[type].title || - asset.width != props[type].width || - asset.height != props[type].height || - asset.orientation != props[type].orientation || - asset.duration != props[type].duration - ) { - expect(false).assertTrue(); - done(); - } -} - -export default function mediaLibraryTestPromiseTest(abilityContext){ - describe('mediaLibraryTestPromiseTest', function () { - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(abilityContext); - - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { }); - - var timestamp = new Date().getTime(); - var jpgName = timestamp + '.jpg'; - var videoName = timestamp + '.mp4'; - var audioName = timestamp + '.mp3'; - var fileName = timestamp + '.mp3'; - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 - * @tc.name : getMediaLibrary - * @tc.desc : Obtains a MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { - try { - expect(media != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageRelativefetchOp); - let count = 1; - let type = 'image'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoRelativefetchOp); - let count = 1; - let type = 'video'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioRelativefetchOp); - let count = 1; - let type = 'audio'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(fileRelativefetchOp); - let count = 1; - let type = 'file'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); - let count = 2; - let type = 'video'; - let typesArr = ['image/*', 'video/mp4'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp); - let count = 3; - let type = 'file'; - let typesArr = ['image/*', 'video/mp4', 'file/*'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp); - let count = 4; - let type = 'audio'; - let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', - selectionArgs: ['abc'], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 008 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['abc', audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 009 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 009 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 010 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 010 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 011 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 011 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_CAMERA - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { - try { - let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; - - const dicResult = await media.getPublicDirectory(DIR_CAMERA); - - expect(dicResult == 'Camera/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { - try { - let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; - - const dicResult = await media.getPublicDirectory(DIR_VIDEO); - console.log(dicResult); - expect(dicResult == 'Videos/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { - try { - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - - const dicResult = await media.getPublicDirectory(DIR_IMAGE); - - expect(dicResult == 'Pictures/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { - try { - let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; - - const dicResult = await media.getPublicDirectory(DIR_AUDIO); - - expect(dicResult == 'Audios/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { - try { - let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - - const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS); - - expect(dicResult == 'Documents/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory 110 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { - try { - await media.getPublicDirectory(110); - console.info('MediaLibraryTest : getPublicDirectory 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getPublicDirectory 006 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 002 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 002 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 003 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 004 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 004 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(audioType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 005 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 006 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(audioType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 007 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(fileType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 008 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const filePath = path + "image/"; - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(imageType, jpgName, filePath); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - console.info('MediaLibraryTest : createAsset 009 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets deleted file mode 100755 index 3d7848207a4b3a9d8eb9082eafb5792739d90391..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets +++ /dev/null @@ -1,647 +0,0 @@ -/* - * 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 mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -export default function mediaLibraryTestPromiseOnOffTest(abilityContext){ - describe('mediaLibraryTestPromiseOnOffTest', function () { - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(function () { }); - afterAll(function () { }); - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - let fileType = mediaLibrary.MediaType.FILE; - - let imagesfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic01/', imageType.toString()], - }; - let videosfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic01/', videoType.toString()], - }; - let audiosfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic01/', audioType.toString()], - }; - let filesfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic01/', fileType.toString()], - }; - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001 - * @tc.name : ON - * @tc.desc : ON Image ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) { - try { - let conut = 0; - media.on('imageChange', () => { - console.info('MediaLibraryTest : on 001 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 001 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002 - * @tc.name : ON - * @tc.desc : ON Video ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) { - try { - let conut = 0; - media.on('videoChange', () => { - console.info('MediaLibraryTest : on 002 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 002 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003 - * @tc.name : ON - * @tc.desc : ON Audio ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) { - try { - let conut = 0; - media.on('audioChange', () => { - console.info('MediaLibraryTest : on 003 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 003 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004 - * @tc.name : ON - * @tc.desc : ON File ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) { - try { - let conut = 0; - media.on('fileChange', () => { - console.info('MediaLibraryTest : on 004 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 004 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005 - * @tc.name : ON - * @tc.desc : ON ALBUM ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) { - try { - let conut = 0; - media.on('albumChange', () => { - console.info('MediaLibraryTest : on 005 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 005 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('albumChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 - * @tc.name : ON - * @tc.desc : ON DEVICE ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) { - try { - let conut = 0; - expect(true).assertTrue(); - done(); - media.on('deviceChange', () => { - console.info('MediaLibraryTest : on 006 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('deviceChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 - * @tc.name : ON - * @tc.desc : ON REMOTE_FILE ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) { - try { - let conut = 0; - expect(true).assertTrue(); - done(); - media.on('remoteFileChange', () => { - console.info('MediaLibraryTest : on 007 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('remoteFileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001 - * @tc.name : off - * @tc.desc : off Image ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) { - try { - media.on('imageChange', () => { - console.info('MediaLibraryTest : off 001 failed'); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('imageChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 001 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002 - * @tc.name : off - * @tc.desc : off video ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) { - try { - media.on('videoChange', () => { - console.info('MediaLibraryTest : off 002 failed'); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('videoChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 002 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 002 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003 - * @tc.name : off - * @tc.desc : off audio ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) { - try { - media.on('audioChange', () => { - console.info('MediaLibraryTest : off 003 failed'); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('audioChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 003 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 003 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004 - * @tc.name : off - * @tc.desc : off file ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) { - try { - media.on('fileChange', () => { - console.info('MediaLibraryTest : off 004 failed'); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('fileChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 004 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 004 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005 - * @tc.name : off - * @tc.desc : off album ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { - try { - media.on('albumChange', () => { - console.info('MediaLibraryTest : off 005 failed'); - expect(false).assertTrue(); - media.off('albumChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'albumChange'; - media.off('albumChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 005 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 005 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 - * @tc.name : off - * @tc.desc : off device ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006', 0, async function (done) { - try { - media.on('deviceChange', () => { - console.info('MediaLibraryTest : off 006 failed'); - expect(false).assertTrue(); - media.off('deviceChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'deviceChange'; - media.off('deviceChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 006 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007 - * @tc.name : off - * @tc.desc : off remoteFile ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007', 0, async function (done) { - try { - media.on('remoteFileChange', () => { - console.info('MediaLibraryTest : off 007 failed'); - expect(false).assertTrue(); - media.off('remoteFileChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - - media.off('remoteFileChange'); - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'remoteFileChange'; - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 007 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001 - * @tc.name : release - * @tc.desc : Release MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) { - try { - await media.release(); - console.info('MediaLibraryTest : release 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : release 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} - -