diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index a544093e7d4527d4438a8b83221eee8f14d2ffbd..093d7235a627eaa301433d33541c06c94f3747bc 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -36,6 +36,7 @@ group("multimedia") { "media/media_js_standard/recorderProfile:recorder_profile_js_hap", "media/media_js_standard/videoPlayer:video_player_js_hap", "medialibrary/mediaLibrary_album:mediaLibrary_album_hap", + "medialibrary/mediaLibrary_base:mediaLibrary_base_hap", "medialibrary/mediaLibrary_favorite:mediaLibrary_favorite_hap", "medialibrary/mediaLibrary_file:mediaLibrary_file_hap", "medialibrary/mediaLibrary_fileAsset:mediaLibrary_fileAsset_hap", @@ -43,8 +44,6 @@ 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 { deps = [ diff --git a/multimedia/medialibrary/common.js b/multimedia/medialibrary/common.js index 34e9a1e621d75cf13f938154e33cf633c245872f..0e96c42e7d8087d95522891570f230de9179782e 100755 --- a/multimedia/medialibrary/common.js +++ b/multimedia/medialibrary/common.js @@ -17,16 +17,16 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; import bundle from '@ohos.bundle'; const presetsCount = { - ActsMediaLibraryAlbum: { assetsCount: 19, albumsCount: 7 }, - ActsMediaLibraryFavorite: { assetsCount: 32, albumsCount: 6 }, - //ActsMediaLibraryAlbumFileResultPro test case create 1 album 5 assets - ActsMediaLibraryAlbumFileResultPro: { assetsCount: 123, albumsCount: 6 }, - //ActsMediaLibraryAlbumFileResultCb test case create 1 album 5 assets - ActsMediaLibraryAlbumFileResultCb: { assetsCount: 118, albumsCount: 5 }, - ActsMediaLibraryFileKey: { assetsCount: 4, albumsCount: 4 }, - ActsMediaLibraryFileAsset: { assetsCount: 4, albumsCount: 4 }, - ActsMediaLibraryFile: { assetsCount: 4, albumsCount: 4 }, - ActsMediaLibraryGetThumbnail: { assetsCount: 3, albumsCount: 3 }, + ActsMediaLibraryAlbum: { albumsCount: 7, assetsCount: 19 }, + ActsMediaLibraryFavorite: { albumsCount: 6, assetsCount: 32 }, + ActsMediaLibraryAlbumFileResultCb: { albumsCount: 5, assetsCount: 118 }, + ActsMediaLibraryFile: { albumsCount: 6, assetsCount: 21 }, + ActsMediaLibraryFileAsset: { albumsCount: 27, assetsCount: 72 }, + ActsMediaLibraryFileAssetUri: { albumsCount: 3, assetsCount: 6 }, + ActsMediaLibraryFileKey: { albumsCount: 2, assetsCount: 2 }, + ActsMediaLibraryFileResult: { albumsCount: 4, assetsCount: 13 }, + ActsMediaLibraryGetThumbnail: { albumsCount: 3, assetsCount: 3 }, + ActsMediaLibraryBase: { albumsCount: 11, assetsCount: 11 }, } const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE; @@ -122,10 +122,9 @@ const checkPresetsAssets = async function (media, hapName) { let albumsCount = albumList.length; let fetchFileResult = await media.getFileAssets(allFetchOp()); let assetsCount = await fetchFileResult.getCount(); - console.info(`${hapName}:: assetsCount: ${assetsCount}`); - console.info(`${hapName}:: albumsCount: ${albumsCount}`); - console.info(`${hapName}:: presetsassetsCount: ${presetsCount[hapName].assetsCount}`); - console.info(`${hapName}:: presetsalbumsCount: ${presetsCount[hapName].albumsCount}`); + console.info(`${hapName}:: assetsCount: ${assetsCount} albumsCount: ${albumsCount} + presetsassetsCount: ${presetsCount[hapName].assetsCount} + presetsalbumsCount: ${presetsCount[hapName].albumsCount}`); console.info('checkPresetsAssets end') } diff --git a/multimedia/medialibrary/mediaLibrary_js/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_base/AppScope/app.json similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/AppScope/app.json rename to multimedia/medialibrary/mediaLibrary_base/AppScope/app.json diff --git a/multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_base/AppScope/resources/base/element/string.json similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/element/string.json rename to multimedia/medialibrary/mediaLibrary_base/AppScope/resources/base/element/string.json diff --git a/multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_base/AppScope/resources/base/media/app_icon.png similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/AppScope/resources/base/media/app_icon.png rename to multimedia/medialibrary/mediaLibrary_base/AppScope/resources/base/media/app_icon.png diff --git a/multimedia/medialibrary/mediaLibrary_js/BUILD.gn b/multimedia/medialibrary/mediaLibrary_base/BUILD.gn similarity index 93% rename from multimedia/medialibrary/mediaLibrary_js/BUILD.gn rename to multimedia/medialibrary/mediaLibrary_base/BUILD.gn index 7dc770916b0338190261b5070315d0328504b2b3..4bf9e8f54f25ebb1f5e80b09fcfd08918fad5dfd 100755 --- a/multimedia/medialibrary/mediaLibrary_js/BUILD.gn +++ b/multimedia/medialibrary/mediaLibrary_base/BUILD.gn @@ -13,7 +13,7 @@ import("//test/xts/tools/build/suite.gni") -ohos_js_hap_suite("mediaLibrary_js_hap") { +ohos_js_hap_suite("mediaLibrary_base_hap") { hap_profile = "entry/src/main/module.json" deps = [ ":mediaLibrary_js_assets", @@ -21,7 +21,7 @@ ohos_js_hap_suite("mediaLibrary_js_hap") { ] ets2abc = true certificate_profile = "signature/openharmony_sx.p7b" - hap_name = "ActsMediaLibraryJs" + hap_name = "ActsMediaLibraryBase" } ohos_app_scope("medialibrary_app_profile") { diff --git a/multimedia/medialibrary/mediaLibrary_js/Test.json b/multimedia/medialibrary/mediaLibrary_base/Test.json similarity index 98% rename from multimedia/medialibrary/mediaLibrary_js/Test.json rename to multimedia/medialibrary/mediaLibrary_base/Test.json index 8b026bf4f617a81ec948da0efa6a35fb741e1ad5..27260adebb0ff1b4cfdf66e64a4a870e458ecb84 100755 --- a/multimedia/medialibrary/mediaLibrary_js/Test.json +++ b/multimedia/medialibrary/mediaLibrary_base/Test.json @@ -54,7 +54,7 @@ }, { "test-file-name": [ - "ActsMediaLibraryJs.hap" + "ActsMediaLibraryBase.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/Application/AbilityStage.ts similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/Application/AbilityStage.ts rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/Application/AbilityStage.ts diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/MainAbility/MainAbility.ts similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/MainAbility/MainAbility.ts rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/MainAbility/MainAbility.ts diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/pages/index/index.ets similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/index/index.ets rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/pages/index/index.ets diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/pages/second/second.ets similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/pages/second/second.ets rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/pages/second/second.ets diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/List.test.ets similarity index 88% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/List.test.ets index b6d8ffb46998974b3e2f02b4b3cc899ef4f4c227..0e78d5fc4f068f548893a5172adfda1f7fd4b4ec 100755 --- a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/List.test.ets @@ -13,10 +13,12 @@ * limitations under the License. */ +import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets' import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets' import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' export default function testsuite(abilityContext) { + mediaLibraryTestCallback(abilityContext) mediaLibraryTestPromise(abilityContext) mediaLibraryTestPromiseOnOffTest(abilityContext) } diff --git a/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..10dfe909e971fb3d78c8327ac61d84622f78239d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestCallback.test.ets @@ -0,0 +1,734 @@ +/* + * 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 mediaLibraryTestCallback(abilityContext) { + describe('mediaLibraryTestCallback', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryBase'); + }); + 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; + fetchFileResult.getFirstObject(async (err, asset) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + 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 { + media.getPublicDirectory(dir, async (err, res) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + expect(res).assertEqual(val); + done(); + }); + + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + const getFileAssetsAbnormal = async (done, testNum, fetchOps) => { + try { + media.getFileAssets(fetchOps, async (err) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect(true).assertTrue(); + done(); + return; + } + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(true).assertTrue(); + done(); + } + } + const getFileAssetsZero = async (done, testNum, fetchOps) => { + try { + media.getFileAssets(fetchOps, async (err, fetchFileResult) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + 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(); + media.createAsset(type, name, path, async (err, creatAsset) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + 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 { + media.createAsset(type, name, path, async (err, creatAsset) => { + if (err || creatAsset == undefined) { + expect(true).assertTrue(); + done(); + return; + } else { + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_002 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_003 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_004 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_005 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_006 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_006', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_007 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_007', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_GETFILEASSETS_008 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_008', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + '= ?', + selectionArgs: [], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_008'; + await getFileAssetsZero(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + 'abc= ?', + selectionArgs: [AUDIO_TYPE.toString()], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009'; + await getFileAssetsAbnormal(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_010 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_010', 0, async function (done) { + let currentFetchOps = { + selections: FILEKEY.MEDIA_TYPE + '= ?', + selectionArgs: [111], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_010'; + await getFileAssetsZero(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011', 0, async function (done) { + let currentFetchOps = { + selections: 'abc' + '= ?', + selectionArgs: [AUDIO_TYPE.toString()], + }; + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011'; + await getFileAssetsAbnormal(done, testNum, currentFetchOps) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_CAMERA + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001'; + let dir = mediaLibrary.DirectoryType.DIR_CAMERA; + let val = 'Camera/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002'; + let dir = mediaLibrary.DirectoryType.DIR_VIDEO; + let val = 'Videos/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003'; + let dir = mediaLibrary.DirectoryType.DIR_IMAGE; + let val = 'Pictures/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004'; + let dir = mediaLibrary.DirectoryType.DIR_AUDIO; + let val = 'Audios/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004'; + let dir = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + let val = 'Documents/'; + await checkGetPublicDirectory(done, testNum, dir, val) + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_006 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory 110 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_001', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_002', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_003', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_004', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_005', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_006', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_007', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_008', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_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_CALLBACK_CREATEASSET_009', 0, async function (done) { + let testNum = 'SUB__MEDIA_MIDIALIBRARY_CALLBACK_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/mediaLibraryTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets similarity index 97% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets index 263b91dcbd460146c8fa197bda646d8f6545b026..725191df40fa7a503135ce93559caca5bc8ae4ed 100755 --- a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets @@ -36,7 +36,7 @@ export default function mediaLibraryTestPromiseTest(abilityContext) { beforeAll(async function () { console.info('beforeAll case'); await getPermission(); - await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + await checkPresetsAssets(media, 'ActsMediaLibraryBase'); }); beforeEach(function () { console.info('beforeEach case'); diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets similarity index 89% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets index 834e008af429a52dfc2824812105299b27c9a174..fc9f9b4eba3a194cb24864606c4487425ce05867 100755 --- a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets +++ b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets @@ -35,7 +35,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { beforeAll(async function () { console.info('beforeAll case'); await getPermission(); - await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + await checkPresetsAssets(media, 'ActsMediaLibraryBase'); }); beforeEach(function () { console.info('beforeEach case'); @@ -321,6 +321,43 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { await offTest(done, testNum, type, currentFetchOps) }); + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005 + * @tc.name : off + * @tc.desc : off album + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005' + try { + let conut = 0; + media.on('albumChange', () => { + conut++; + }); + await sleep(300) + media.off('albumChange'); + let currentFetchOps = albumFetchOps('Pictures/', 'OffAlbum', 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 sleep(1000) + await album.commitModify(); + await sleep(300) + album.albumName = oldName; + await album.commitModify(); + expect(conut).assertEqual(0); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + }); /** * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 * @tc.name : off diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/module.json similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/module.json rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/module.json diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/element/string.json similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/element/string.json rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/element/string.json diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/media/icon.png similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/media/icon.png rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/media/icon.png diff --git a/multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/profile/main_pages.json similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/entry/src/main/resources/base/profile/main_pages.json rename to multimedia/medialibrary/mediaLibrary_base/entry/src/main/resources/base/profile/main_pages.json diff --git a/multimedia/medialibrary/mediaLibrary_js/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_base/signature/openharmony_sx.p7b similarity index 100% rename from multimedia/medialibrary/mediaLibrary_js/signature/openharmony_sx.p7b rename to multimedia/medialibrary/mediaLibrary_base/signature/openharmony_sx.p7b diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets index b4c43a249e63bf4649afa2f1233d8f83319f6d92..3779151842ce3376e137b16e17f1252efc89973b 100755 --- a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets @@ -13,7 +13,9 @@ * limitations under the License. */ +import fileTestCallback from './fileTestCallback.test.ets' import fileTestPromise from './fileTestPromise.test.ets' export default function testsuite(abilityContext) { + fileTestCallback(abilityContext) fileTestPromise(abilityContext) } diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..203aaa880038f920bb9935f2e97d5ba1285780d7 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestCallback.test.ets @@ -0,0 +1,561 @@ +/* + * 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, + checkPresetsAssets, + nameFetchOps, + checkAssetsCount, + getPermission, + fetchOps, + FILEKEY, + isNum, +} from '../../../../../../common'; + + +export default function fileTestCallbackTest(abilityContext) { + describe('fileTestCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFile') + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + 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 creatAssetTest = async (done, testNum, fetchOp, path, type, name) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) + + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + let displayName1 = `${new Date().getTime()}.${name}`; + + media.createAsset(type, displayName1, path, async (err, creatAsset1) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + const fd = await asset.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + + let displayName2 = `${new Date().getTime()}.${name}`; + const creatAsset2 = await media.createAsset(type, displayName2, path); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset.close(fd); + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + }); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const checkCreatAssetProps = async (done, testNum, fetchOp, path, type, name, key, val) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) + + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + let displayName = `${new Date().getTime()}.${name}`; + + media.createAsset(type, displayName, path, async (err, creatAsset) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + const fd = await asset.open('rw'); + const creatAssetFd = await creatAsset.open('rw'); + await copyFile(fd, creatAssetFd); + await creatAsset.close(creatAssetFd); + + if (val == 'displayName') { + val = displayName + } + expect(creatAsset[key]).assertEqual(val); + done(); + }); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const checkdateModified = async (done, testNum, fetchOp) => { + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) + + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(async (err) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + const id = asset.id; + const idOP = { selections: FILEKEY.ID + '= ?', selectionArgs: ['' + id] }; + fetchFileResult = await media.getFileAssets(idOP); + let newAsset = await fetchFileResult.getFirstObject(); + expect(isNum(newAsset.dateModified)).assertTrue(); + expect(newAsset.dateModified != asset.dateModified).assertTrue() + done(); + }); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + // ------------------------------- image type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01'; + let currentFetchOp = nameFetchOps('Pictures/Static/', '01', IMAGE_TYPE) + let name = 'jpg' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE) + '/create/' + let type = IMAGE_TYPE; + await creatAssetTest(done, testNum, currentFetchOp, path, type, name) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file displayName and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02'; + let currentFetchOp = nameFetchOps('Pictures/Static/', '02', IMAGE_TYPE) + let name = 'jpg' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE) + '/create/'; + let type = IMAGE_TYPE; + let key = 'displayName'; + let val = 'displayName'; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03'; + let currentFetchOp = nameFetchOps('Pictures/Static/', '03', IMAGE_TYPE) + let name = 'jpg' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE) + '/create/'; + let type = IMAGE_TYPE; + let key = 'relativePath'; + let val = path; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07'; + let currentFetchOp = fetchOps('Pictures/Dynamic/', IMAGE_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08'; + let currentFetchOp = nameFetchOps('Pictures/Static/', '04', IMAGE_TYPE) + let name = 'jpg' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE) + '/create/'; + let type = IMAGE_TYPE; + let key = 'mediaType'; + let val = IMAGE_TYPE; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11'; + let currentFetchOp = nameFetchOps('Pictures/Static/', '05', IMAGE_TYPE) + let name = 'jpg' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE) + '/create/'; + let type = IMAGE_TYPE; + let key = 'orientation'; + let val = 0; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + // ------------------------------- image type end ----------------------------- + + // ------------------------------- video type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01'; + let currentFetchOp = nameFetchOps('Videos/Static/', '01', VIDEO_TYPE) + let name = 'mp4' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO) + '/create/' + let type = VIDEO_TYPE; + await creatAssetTest(done, testNum, currentFetchOp, path, type, name) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file displayName and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02'; + let currentFetchOp = nameFetchOps('Videos/Static/', '02', VIDEO_TYPE) + let name = 'mp4' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO) + '/create/'; + let type = VIDEO_TYPE; + let key = 'displayName'; + let val = 'displayName'; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03'; + let currentFetchOp = nameFetchOps('Videos/Static/', '03', VIDEO_TYPE) + let name = 'mp4' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO) + '/create/'; + let type = VIDEO_TYPE; + let key = 'relativePath'; + let val = path; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07'; + let currentFetchOp = fetchOps('Videos/Dynamic/', VIDEO_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08'; + let currentFetchOp = nameFetchOps('Videos/Static/', '04', VIDEO_TYPE) + let name = 'mp4' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO) + '/create/'; + let type = VIDEO_TYPE; + let key = 'mediaType'; + let val = VIDEO_TYPE; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11'; + let currentFetchOp = nameFetchOps('Videos/Static/', '05', VIDEO_TYPE) + let name = 'mp4' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO) + '/create/'; + let type = VIDEO_TYPE; + let key = 'orientation'; + let val = 0; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + // ------------------------------- video type end ----------------------------- + + // ------------------------------- audio type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01'; + let currentFetchOp = nameFetchOps('Audios/Static/', '01', AUDIO_TYPE) + let name = 'mp3' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO) + '/create/' + let type = AUDIO_TYPE; + await creatAssetTest(done, testNum, currentFetchOp, path, type, name) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02'; + let currentFetchOp = nameFetchOps('Audios/Static/', '02', AUDIO_TYPE) + let name = 'mp3' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO) + '/create/'; + let type = AUDIO_TYPE; + let key = 'displayName'; + let val = 'displayName'; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03'; + let currentFetchOp = nameFetchOps('Audios/Static/', '03', AUDIO_TYPE) + let name = 'mp3' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO) + '/create/'; + let type = AUDIO_TYPE; + let key = 'relativePath'; + let val = path; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07'; + let currentFetchOp = fetchOps('Audios/Dynamic/', AUDIO_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08'; + let currentFetchOp = nameFetchOps('Audios/Static/', '05', AUDIO_TYPE) + let name = 'mp3' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO) + '/create/'; + let type = AUDIO_TYPE; + let key = 'mediaType'; + let val = AUDIO_TYPE; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + // ------------------------------- audio type end ----------------------------- + + // ------------------------------ file type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01'; + let currentFetchOp = nameFetchOps('Documents/Static/', '01', FILE_TYPE) + let name = 'dat' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS) + '/create/' + let type = FILE_TYPE; + await creatAssetTest(done, testNum, currentFetchOp, path, type, name) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02'; + let currentFetchOp = nameFetchOps('Documents/Static/', '02', FILE_TYPE) + let name = 'dat' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS) + '/create/'; + let type = FILE_TYPE; + let key = 'displayName'; + let val = 'displayName'; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03'; + let currentFetchOp = nameFetchOps('Documents/Static/', '03', FILE_TYPE) + let name = 'dat' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS) + '/create/'; + let type = FILE_TYPE; + let key = 'relativePath'; + let val = path; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07'; + let currentFetchOp = fetchOps('Documents/Dynamic/', FILE_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08'; + let currentFetchOp = nameFetchOps('Documents/Static/', '04', FILE_TYPE) + let name = 'dat' + let path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS) + '/create/'; + let type = FILE_TYPE; + let key = 'mediaType'; + let val = FILE_TYPE; + await checkCreatAssetProps(done, testNum, currentFetchOp, path, type, name, key, val) + }); + + // ------------------------------- file type end ----------------------------- + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestPromise.test.ets index d785d03012adf8ef20edbac2b22364bcca72d2e2..5b4b439f4129250a431a214df1ad484621f4b8dc 100755 --- a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestPromise.test.ets @@ -26,7 +26,6 @@ import { checkPresetsAssets, nameFetchOps, checkAssetsCount, - getPermission, fetchOps, FILEKEY, isNum, @@ -37,7 +36,6 @@ export default function fileTestPromiseTest(abilityContext) { describe('fileTestPromiseTest', function () { const media = mediaLibrary.getMediaLibrary(abilityContext); beforeAll(async function () { - await getPermission(); await checkPresetsAssets(media, 'ActsMediaLibraryFile') }); beforeEach(function () { }); diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json b/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json index 52a26a285cfe41920510be508064f1057a337f23..a2de3f19db69ad44a1b8c4821e081c506879b5e1 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json @@ -32,20 +32,20 @@ { "type": "ShellKit", "run-command": [ - "mkdir -pv /storage/media/100/local/files/Pictures/{Static,RW,R,W,openClose}", - "mkdir -pv /storage/media/100/local/files/Videos/{Static,RW,R,W,openClose}", - "mkdir -pv /storage/media/100/local/files/Audios/{Static,RW,R,W,openClose}", - "mkdir -pv /storage/media/100/local/files/Documents/{Static,RW,R,W,openClose}", + "mkdir -pv /storage/media/100/local/files/Pictures/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}", + "mkdir -pv /storage/media/100/local/files/Videos/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}", + "mkdir -pv /storage/media/100/local/files/Audios/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}", + "mkdir -pv /storage/media/100/local/files/Documents/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}", - "for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", - "for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", - "for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", - "for d in RW R W openClose; do for i in $$(seq 2); 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;", + "for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", + "for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", + "for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", + "for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); 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;", - "for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", - "for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", - "for d in Static; do for i in $$(seq 5); 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; do for i in $$(seq 5); 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;", + "for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", + "for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", + "for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", + "for d in ModifyCb ModifyPro; do for i in $$(seq 5); 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/*", diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets index 48836999f225b5d1fbae1184c9d82bec76a75701..5bc1f5a63430742345656edb5fb5b714070d3919 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets @@ -13,9 +13,13 @@ * limitations under the License. */ +import fileAssetCallback2 from './fileAssetCallback2.test.ets' import fileAssetPromise2 from './fileAssetPromise2.test.ets' +import fileAssetTestCallback from './fileAssetTestCallback.test.ets' import fileAssetTestPromise from './fileAssetTestPromise.test.ets' export default function testsuite(abilityContext) { + fileAssetCallback2(abilityContext) fileAssetPromise2(abilityContext) + fileAssetTestCallback(abilityContext) fileAssetTestPromise(abilityContext) } diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetCallback2.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetCallback2.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..2a5eda4700bf4c80ea773daffca2471c191e9509 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetCallback2.test.ets @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + getPermission, + nameFetchOps, +} from '../../../../../../common'; + +export default function fileAssetCallback2Test(abilityContext) { + describe('fileAssetCallback2Test', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset') + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + const checkCommitModify = async function (done, testNum, fetchOp, prop, val) { + try { + console.info(`${testNum} fetchOp : ${JSON.stringify(fetchOp)}`) + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + const oldVal = asset[prop] + asset[prop] = val; + const id = asset.id; + await asset.commitModify(async (err) => { + if (err) { + console.info(`${testNum} err : ${err}`) + expect.assertFail(); + done(); + return; + } + let currentfetchOp = { + selections: FILEKEY.ID + '= ?', + selectionArgs: [id + ''], + }; + const fetchFileResult2 = await media.getFileAssets(currentfetchOp); + const currentAsset = await fetchFileResult2.getFirstObject(); + expect(currentAsset[prop]).assertEqual(val); + + asset[prop] = oldVal; + await asset.commitModify(); + await fetchFileResult.close(); + done(); + }); + + } catch (error) { + console.info(`${testNum} error : ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_001 + * @tc.name : commitModify + * @tc.desc : Modify displayName + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_001', 0, async function (done) { + let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_001' + let fetchOp = nameFetchOps('Pictures/ModifyCb/', '01', IMAGE_TYPE); + let prop = 'displayName' + let val = new Date().getTime() + '.jpg' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_002 + * @tc.name : commitModify + * @tc.desc : Modify title + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_002' + let fetchOp = nameFetchOps('Pictures/ModifyCb/', '02', IMAGE_TYPE); + let prop = 'title' + let val = new Date().getTime() + 'newTitle' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_003 + * @tc.name : commitModify + * @tc.desc : Modify relativePath + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_003' + let fetchOp = nameFetchOps('Pictures/ModifyCb/', '03', IMAGE_TYPE); + let prop = 'relativePath' + let val = 'Pictures/Temp/' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_004 + * @tc.name : commitModify + * @tc.desc : Modify orientation + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_004', 0, async function (done) { + + let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_004' + let fetchOp = nameFetchOps('Pictures/ModifyCb/', '04', IMAGE_TYPE); + let prop = 'orientation' + let val = 1 + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_callback_001 + * @tc.name : isDirectory + * @tc.desc : isDirectory asset + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_isDirectory_callback_001', 0, async function (done) { + try { + let fetchOp = nameFetchOps('Pictures/ModifyCb/', '05', IMAGE_TYPE); + const fetchFileResult = await media.getFileAssets(fetchOp); + const asset = await fetchFileResult.getFirstObject(); + const isDir = await asset.isDirectory(); + expect(!isDir).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset isDirectory 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetPromise2.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetPromise2.test.ets index 573df12a850806c8298884a3cbff7d43cca93ba8..aaeef1b478af3850fe94b2e3f915818412cbe946 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetPromise2.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetPromise2.test.ets @@ -20,12 +20,9 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from import { sleep, IMAGE_TYPE, - AUDIO_TYPE, FILEKEY, checkPresetsAssets, checkAssetsCount, - getPermission, - fetchOps, nameFetchOps, } from '../../../../../../common'; @@ -33,8 +30,7 @@ export default function fileAssetPromise2Test(abilityContext) { describe('fileAssetPromise2Test', function () { const media = mediaLibrary.getMediaLibrary(abilityContext); beforeAll(async function () { - await getPermission(); - await checkPresetsAssets(media, 'ActsMediaLibraryFileKey') + await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset') }); beforeEach(function () { }); afterEach(async function () { @@ -82,7 +78,7 @@ export default function fileAssetPromise2Test(abilityContext) { */ it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) { let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_001' - let fetchOp = nameFetchOps('Pictures/Static/', '01', IMAGE_TYPE); + let fetchOp = nameFetchOps('Pictures/ModifyPro/', '01', IMAGE_TYPE); let prop = 'displayName' let val = new Date().getTime() + '.jpg' await checkCommitModify(done, testNum, fetchOp, prop, val) @@ -98,7 +94,7 @@ export default function fileAssetPromise2Test(abilityContext) { */ it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) { let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_002' - let fetchOp = nameFetchOps('Pictures/Static/', '02', IMAGE_TYPE); + let fetchOp = nameFetchOps('Pictures/ModifyPro/', '02', IMAGE_TYPE); let prop = 'title' let val = new Date().getTime() + 'newTitle' await checkCommitModify(done, testNum, fetchOp, prop, val) @@ -114,7 +110,7 @@ export default function fileAssetPromise2Test(abilityContext) { */ it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) { let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_003' - let fetchOp = nameFetchOps('Pictures/Static/', '03', IMAGE_TYPE); + let fetchOp = nameFetchOps('Pictures/ModifyPro/', '03', IMAGE_TYPE); let prop = 'relativePath' let val = 'Pictures/Temp/' await checkCommitModify(done, testNum, fetchOp, prop, val) @@ -131,7 +127,7 @@ export default function fileAssetPromise2Test(abilityContext) { it('SUB_MEDIA_FILEASSET_commitModify_promise_004', 0, async function (done) { let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_004' - let fetchOp = nameFetchOps('Pictures/Static/', '04', IMAGE_TYPE); + let fetchOp = nameFetchOps('Pictures/ModifyPro/', '04', IMAGE_TYPE); let prop = 'orientation' let val = 1 await checkCommitModify(done, testNum, fetchOp, prop, val) @@ -147,7 +143,7 @@ export default function fileAssetPromise2Test(abilityContext) { */ it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { try { - let fetchOp = nameFetchOps('Pictures/Static/', '05', IMAGE_TYPE); + let fetchOp = nameFetchOps('Pictures/ModifyPro/', '05', IMAGE_TYPE); const fetchFileResult = await media.getFileAssets(fetchOp); const asset = await fetchFileResult.getFirstObject(); const isDir = await asset.isDirectory(); diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0f2c956dd86bf5a3c23342899ad222ae5a958226 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets @@ -0,0 +1,506 @@ +/* + * 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 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, + checkPresetsAssets, + checkAssetsCount, + fetchOps, +} from '../../../../../../common'; +export default function fileAssetTestCallbackTest(abilityContext) { + describe('fileAssetTestCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset') + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + function isNum(value) { + return typeof value === 'number' && !isNaN(value); + } + + const rwOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount) { + let asset, asset1; + let fd, fd1; + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset.open('rw', async (err, fd) => { + if (err) { + console.info(`${testNum} :: err: ${err}`); + expect.assertFail(); + done(); + return; + } + expect(isNum(fd)).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead).assertEqual(assetProps.bytesRead); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + expect(isNum(fd1)).assertTrue(); + let buf1 = new ArrayBuffer(4096); + await fileio.read(fd1, buf1); + let write = await fileio.write(fd, buf1); + expect(write).assertEqual(assetProps.write); + console.info(`res.bytesRead:${res.bytesRead},write:${write}`) + console.info(`fd1:${fd1},fd:${fd}`) + await asset.close(fd); + await asset1.close(fd1); + done(); + }); + + } catch (error) { + console.info(`${testNum} :: error: ${error}`); + await asset.close(fd); + await asset1.close(fd1); + expect.assertFail(); + done(); + } + } + const rOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount) { + let asset; + let fd; + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset.open('r', async (err, fd) => { + if (err) { + console.info(`${testNum} :: err: ${err}`); + expect.assertFail(); + done(); + return; + } + expect(isNum(fd)).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + console.log(' bytesRead: ' + res.bytesRead) + expect(res.bytesRead).assertEqual(assetProps.bytesRead); + try { + await fileio.write(fd, buf); + expect.assertFail(); + } catch (error) { + expect(true).assertTrue(); + await asset.close(fd); + done(); + } + }); + + } catch (error) { + console.info(`${testNum} :: error: ${error}`); + expect.assertFail(); + await asset.close(fd); + done(); + } + } + + const wOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount) { + let asset, asset1; + let fd, fd1; + try { + + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset1 = dataList[1]; + + asset.open('w', async (err, fd) => { + if (err) { + console.info(`${testNum} :: err: ${err}`); + expect.assertFail(); + done(); + return; + } + expect(isNum(fd)).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + console.info(`${testNum} :: write: ${write}`); + expect(write).assertEqual(assetProps.write); + let buf1 = new ArrayBuffer(4096); + try { + await fileio.read(fd, buf1); + expect.assertFail(); + + } catch (error) { + expect(true).assertTrue(); + + } + done(); + }); + + } catch (error) { + console.info(`${testNum} :: error: ${error}`); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + } + + const closeTest = async function (done, testNum, fetchOp) { + let asset; + let fd; + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 2); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + fd = await asset.open('r'); + expect(isNum(fd)).assertTrue(); + asset.close(fd, async (err) => { + if (err) { + console.info(`${testNum} :: err: ${err}`); + expect.assertFail(); + done(); + return; + } + let count = 0 + let buf = new ArrayBuffer(4096); + try { + await fileio.read(fd, buf); + } catch (error) { + count++ + } + try { + await fileio.write(fd, buf); + } catch (error) { + count++ + } + await sleep(1000) + expect(count).assertEqual(2); + done(); + }); + + } catch (error) { + console.info(`${testNum} error:${error}`) + await asset.close(fd); + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01', 0, async function (done) { + let assetProps = { + bytesRead: 10, + write: 4096, + } + let fetchOp = fetchOps('Documents/RW_cb/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 + * @tc.name : open('r') + * @tc.desc : open -r the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02', 0, async function (done) { + let assetProps = { + bytesRead: 10, + write: 4096, + } + let fetchOp = fetchOps('Documents/R_cb/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 + * @tc.name : open('w') + * @tc.desc : open -w the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Documents/W_cb/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + // //======================== FILE END ================================== + + //======================== IMAGE BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Pictures/RW_cb/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 + * @tc.name : open('r') + * @tc.desc : open -r the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Pictures/R_cb/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 + * @tc.name : open('w') + * @tc.desc : open -w the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Pictures/W_cb/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== IMAGE END ================================== + + //======================== AUDIO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Audios/RW_cb/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 + * @tc.name : open('r') + * @tc.desc : open -r the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Audios/R_cb/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 + * @tc.name : open('w') + * @tc.desc : open -w the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Audios/W_cb/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== AUDIO END ================================== + + //======================== VIDEO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Videos/RW_cb/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 + * @tc.name : open('r') + * @tc.desc : open -r the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Videos/R_cb/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 + * @tc.name : open('w') + * @tc.desc : open -w the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Videos/W_cb/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== VIDEO END ================================== + + //======================== CLOSE BEGIN ================================ + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 + * @tc.name : close + * @tc.desc : asset close the type of file + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31' + let fetchOp = fetchOps('Documents/openClose/', FILE_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 + * @tc.name : close + * @tc.desc : asset close the type of image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33' + let fetchOp = fetchOps('Pictures/openClose/', IMAGE_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 + * @tc.name : close + * @tc.desc : asset close the type of audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34' + let fetchOp = fetchOps('Audios/openClose/', AUDIO_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35' + let fetchOp = fetchOps('Videos/openClose/', VIDEO_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + //======================== CLOSE BEGIN ================================ + }); +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets index c56246c6fb9cfc5104bdd64fe5fb18f27655571d..b862fc78a46895ce48e00e7d0fbcd8781677f342 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets @@ -22,19 +22,15 @@ import { VIDEO_TYPE, AUDIO_TYPE, FILE_TYPE, - - FILEKEY, checkPresetsAssets, checkAssetsCount, - getPermission, fetchOps, - nameFetchOps, } from '../../../../../../common'; export default function fileAssetTestPromiseTest(abilityContext) { describe('fileAssetTestPromiseTest', function () { const media = mediaLibrary.getMediaLibrary(abilityContext); beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryFileKey') + await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset') }); beforeEach(function () { }); afterEach(async function () { diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultCallback.test.ets b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultCallback.test.ets index 2c26b3656af483673d49a11c18515ef540e013a8..d033a0e241714774d729b8443e008453e13e7bf9 100755 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultCallback.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultCallback.test.ets @@ -32,7 +32,7 @@ export default function fetchFileResultCallbackTest(abilityContext) { const media = mediaLibrary.getMediaLibrary(abilityContext); beforeAll(async function () { await getPermission(); - await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultCb'); + await checkPresetsAssets(media, 'ActsMediaLibraryFileResult'); }); beforeEach(function () { }); afterEach(async function () { diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultPromise.test.ets index d285e47f9f4d0e9512bfbe997a66f820c277c771..d04f484dea455188d1c6e438d55e8b02dd9fad35 100755 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/fetchFileResultPromise.test.ets @@ -33,7 +33,7 @@ export default function fetchFileResultPromiseTest(abilityContext) { describe('fetchFileResultPromiseTest', function () { const media = mediaLibrary.getMediaLibrary(abilityContext); beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultPro'); + await checkPresetsAssets(media, 'ActsMediaLibraryFileResult'); }); beforeEach(function () { }); afterEach(async function () { 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 efca2799fbe7de97e65c8c414b938819252f80c2..eba0e5a516c9183276b04ac764a0500de4a09df0 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 @@ -13,15 +13,7 @@ * limitations under the License. */ import getPermissionTest from './getPermission.test.ets' -import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets' -import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets' -import fileTestCallBackTest from './fileTestCallBack.test.ets' -import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets' export default function testsuite(abilityContext) { getPermissionTest() - fileAssetCallBack2Test(abilityContext) - fileAssetTestCallbackTest(abilityContext) - fileTestCallBackTest(abilityContext) - mediaLibraryTestCallBackTest(abilityContext) } diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetCallBack2.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetCallBack2.test.ets deleted file mode 100755 index 6f33f642f93c6f5b11c597953db3627b2cfb71e2..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetCallBack2.test.ets +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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 mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import { - sleep, -} from '../../../../../../common'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -function printAttr(asset) { - for (const key in asset) { - console.info(`${key}: asset[key]`); - } -} -function checkAttrs(done, asset, tNum) { - let passed = true; - for (const key in asset) { - if (asset[key] == undefined) { - passed = false; - break; - } - } - if (passed) { - console.info(`FileAsset checkAttrs ${tNum} passed`); - expect(true).assertTrue(); - done(); - } else { - console.info(`FileAsset checkAttrs ${tNum} failed`); - expect(false).assertTrue(); - done(); - } -} -export default function fileAssetCallBack2Test(abilityContext){ - describe('fileAssetCallBack2Test', function () { - let fileKeyObj = mediaLibrary.FileKey; - - let imageType = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - let imagesfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic/', imageType.toString()], - }; - - let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], - }; - let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], - }; - - let allTypefetchOp = { - selections: '', - selectionArgs: [], - }; - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_001 - * @tc.name : commitModify - * @tc.desc : Modify displayName - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_callback_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const newName = 'newName' + new Date().getTime() + '.jpg'; - asset.displayName = newName; - const id = asset.id; - asset.commitModify(async () => { - let currentfetchOp = { - selections: fileKeyObj.ID + '= ?', - selectionArgs: [id + ''], - }; - const fetchFileResult2 = await media.getFileAssets(currentfetchOp); - const currentAsset = await fetchFileResult2.getFirstObject(); - expect(currentAsset.displayName == newName).assertTrue(); - done(); - }); - } catch (error) { - console.info('FileAsset commitModify 001 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_002 - * @tc.name : commitModify - * @tc.desc : Modify title - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_callback_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const newTitle = 'newTitle' + new Date().getTime(); - asset.title = newTitle; - const id = asset.id; - asset.commitModify(async () => { - let currentfetchOp = { - selections: fileKeyObj.ID + '= ?', - selectionArgs: [id + ''], - }; - const fetchFileResult2 = await media.getFileAssets(currentfetchOp); - const currentAsset = await fetchFileResult2.getFirstObject(); - expect(currentAsset.title == newTitle).assertTrue(); - done(); - }); - } catch (error) { - console.info('FileAsset commitModify 002 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_003 - * @tc.name : commitModify - * @tc.desc : Modify relativePath - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_callback_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - let newrelativePath = 'Pictures/Temp/'; - - asset.relativePath = newrelativePath; - const id = asset.id; - asset.commitModify(async () => { - let currentfetchOp = { - selections: fileKeyObj.ID + '= ?', - selectionArgs: [id + ''], - }; - const fetchFileResult2 = await media.getFileAssets(currentfetchOp); - const currentAsset = await fetchFileResult2.getFirstObject(); - expect(currentAsset.relativePath == newrelativePath).assertTrue(); - done(); - }); - } catch (error) { - console.info('FileAsset commitModify 003 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_004 - * @tc.name : commitModify - * @tc.desc : Modify orientation - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_callback_004', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - let neworientation = 1; - if (asset.orientation == 1) { - neworientation = 0; - } - asset.orientation = neworientation; - const id = asset.id; - asset.commitModify(async () => { - let currentfetchOp = { - selections: fileKeyObj.ID + '= ?', - selectionArgs: [id + ''], - }; - const fetchFileResult2 = await media.getFileAssets(currentfetchOp); - const currentAsset = await fetchFileResult2.getFirstObject(); - expect(currentAsset.orientation == neworientation).assertTrue(); - done(); - }); - } catch (error) { - console.info('FileAsset commitModify 004 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_callback_001 - * @tc.name : isDirectory - * @tc.desc : isDirectory asset - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_isDirectory_callback_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.isDirectory((err, isDir) => { - if (isDir == undefined) { - expect(false).assertTrue(); - done(); - } else { - expect(!isDir).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('FileAsset isDirectory 001 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_001 - * @tc.name : attrs - * @tc.desc : imagesfetchOp attrs print and check - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_checkAttr_callback_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - fetchFileResult.getFirstObject((err, asset) => { - if (asset == undefined) { - expect(false).assertTrue(); - done(); - } else { - printAttr(asset); - checkAttrs(done, asset, '001'); - } - }); - } catch (error) { - console.info('FileAsset checkAttr 001 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_002 - * @tc.name : attrs - * @tc.desc : videosfetchOp attrs print and check - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_checkAttr_callback_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videosfetchOp); - fetchFileResult.getFirstObject((err, asset) => { - if (asset == undefined) { - expect(false).assertTrue(); - done(); - } else { - printAttr(asset); - checkAttrs(done, asset, '002'); - } - }); - } catch (error) { - console.info('FileAsset checkAttr 002 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_003 - * @tc.name : attrs - * @tc.desc : audiosfetchOp attrs print and check - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_checkAttr_callback_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - fetchFileResult.getFirstObject((err, asset) => { - if (asset == undefined) { - expect(false).assertTrue(); - done(); - } else { - printAttr(asset); - checkAttrs(done, asset, '003'); - } - }); - } catch (error) { - console.info('FileAsset checkAttr 003 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_004 - * @tc.name : attrs - * @tc.desc : album attrs print and check - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_checkAttr_callback_004', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(allTypefetchOp); - fetchFileResult.getFirstObject((err, asset) => { - if (asset == undefined) { - expect(false).assertTrue(); - done(); - } else { - printAttr(asset); - checkAttrs(done, asset, '004'); - } - }); - - } catch (error) { - console.info('FileAsset checkAttr 003 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetTestCallback.test.ets deleted file mode 100755 index 2dec1d4fce3f0648e1a5cfc0d1d6d37a57a141d1..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetTestCallback.test.ets +++ /dev/null @@ -1,1086 +0,0 @@ -/* - * 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 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'; -export default function fileAssetTestCallbackTest(abilityContext){ - describe('fileAssetTestCallbackTest', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - const fileKeyObj = mediaLibrary.FileKey; - function isNum(value) { - return typeof value === 'number' && !isNaN(value); - } - //======================== FILE BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - bytesRead: 10, - write: 4096, - } - try { - let fileType = mediaLibrary.MediaType.FILE; - let fileFetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic01/', fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset.open('rw', async (error, fd) => { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 fd:' - + fd); - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 res.bytesRead:' - + res.bytesRead); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write == assetProps.write).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 write:' - + write); - await asset.close(fd); - await asset1.close(fd1); - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 success'); - done(); - } else { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 failed'); - done(); - } - } - }); - - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 - * @tc.name : open('r') - * @tc.desc : open -r the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - } - try { - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset.open('r', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 fd:' - + fd); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 res.bytesRead:' - + res.bytesRead); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 error:' - + error); - expect(true).assertTrue(); - if (isNum(fd)) { - await asset.close(fd); - } - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 error:' - + error); - expect(false).assertTrue(); - if (isNum(fd)) { - await asset.close(fd); - } - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 - * @tc.name : open('w') - * @tc.desc : open -w the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - write: 4096, - } - try { - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - asset.open('w', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 fd:' - + fd); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 read fd1 success'); - let write = await fileio.write(fd, buf); - expect(write == assetProps.write).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 write:' - + write); - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 read fd'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 error:' - + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 error:' - + error); - expect(false).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== FILE END ================================== - - //======================== IMAGE BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - - asset.open('rw', async (error, fd) => { - if (fd == undefined) { - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write == assetProps.write).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 success'); - done(); - } else { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 failed'); - done(); - } - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 - * @tc.name : open('r') - * @tc.desc : open -r the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset.open('r', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 res.bytesRead:' - + res.bytesRead); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 error:' - + error); - if (isNum(fd)) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 error:' - + error); - expect(false).assertTrue(); - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 - * @tc.name : open('w') - * @tc.desc : open -w the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset1 = dataList[1]; - - asset.open('w', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 fd:' - + fd); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - expect(write == assetProps.write).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 write:' - + write); - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 read'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 error:' - + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 error:' - + error); - expect(false).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== IMAGE END ================================== - - //======================== AUDIO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.AUDIO; - let fileFetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset.open('rw', async (error, fd) => { - if (fd == undefined) { - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write == assetProps.write).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 success'); - done(); - } else { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 failed'); - done(); - } - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 - * @tc.name : open('r') - * @tc.desc : open -r the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset.open('r', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 fd:' - + fd); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 res.bytesRead:' - + res.bytesRead); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - let write = await fileio.write(fd, buf); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 write'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 error:' - + error); - expect(true).assertTrue(); - if (isNum(fd)) { - await asset.close(fd); - } - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 error:' - + error); - expect(false).assertTrue(); - if (isNum(fd)) { - await asset.close(fd); - } - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 - * @tc.name : open('w') - * @tc.desc : open -w the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - write: 4096, - } - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset1 = dataList[1]; - - asset.open('w', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 fd:' - + fd); - expect(isNum(fd)).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - expect(write == assetProps.write).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 write:' - + write); - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 read'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 error:' - + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 error:' - + error); - expect(false).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== AUDIO END ================================== - - //======================== VIDEO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset.open('rw', async (error, fd) => { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 fd:' - + fd); - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 res.bytesRead :' - + res.bytesRead); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write == assetProps.write).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 write :' - + write); - - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 success'); - done(); - } else { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 failed'); - done(); - } - } - }); - - await asset.close(fd); - await asset1.close(fd1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 - * @tc.name : open('r') - * @tc.desc : open -r the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - write: 4096, - } - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - - asset.open('r', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 fd:' - + fd); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 res.bytesRead:' - + res.bytesRead); - let write = await fileio.write(fd, buf); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 write:' - + write); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 error:' - + error); - expect(true).assertTrue(); - await asset.close(fd); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 error:' - + error); - expect(false).assertTrue(); - if (isNum(fd)) { - await asset.close(fd); - } - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 - * @tc.name : open('w') - * @tc.desc : open -w the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - let assetProps = { - write: 4096, - } - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic01/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset1 = dataList[1]; - asset.open('w', async (error, fd) => { - try { - if (fd == undefined) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 fd == undefined'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 fd :' - + fd); - expect(isNum(fd)).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - expect(write == assetProps.write).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 wreite:' - + write); - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 read'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 error:' - + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 error:' - + error); - expect(false).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== VIDEO END ================================== - - //======================== CLOSE BEGIN ================================ - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 - * @tc.name : close - * @tc.desc : asset close the type of file - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - - asset.close(fd, async (error) => { - fd1 = await asset.open('r'); - await asset.close(fd1); - if (isNum(fd) && isNum(fd1)) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 false'); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 - * @tc.name : close - * @tc.desc : asset close the type of image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - - console.info('MediaLibraryTest : ==1 fd:' + fd); - asset.close(fd, async (error) => { - fd1 = await asset.open('r'); - console.info('MediaLibraryTest : ==2 fd2:' + fd1); - await asset.close(fd1); - if (isNum(fd) && isNum(fd1)) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 false'); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 - * @tc.name : close - * @tc.desc : asset close the type of audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - - asset.close(fd, async (error) => { - fd1 = await asset.open('r'); - await asset.close(fd1); - if (isNum(fd) && isNum(fd1)) { - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 false'); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 - * @tc.name : close - * @tc.desc : asset close the type of video - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('r'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 fd' + fd); - expect(isNum(fd)).assertTrue(); - asset.close(fd, async (error) => { - try { - fd1 = await asset.open('r'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 fd1' - + fd1); - expect(isNum(fd1)).assertTrue(); - expect(error == undefined).assertTrue(); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error == undefined'); - await asset.close(fd1); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 close fd1:' - + fd1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error' - + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - //======================== CLOSE BEGIN ================================ - }); -} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileTestCallBack.test.ets deleted file mode 100755 index 8993383e736956c674918b9de2e48f94d220fd72..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileTestCallBack.test.ets +++ /dev/null @@ -1,744 +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 fileType = mediaLibrary.MediaType.FILE; -let imageType = mediaLibrary.MediaType.IMAGE; -let videoType = mediaLibrary.MediaType.VIDEO; -let audioType = mediaLibrary.MediaType.AUDIO; - -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()], -}; - -function checkAssetAttr(done, attr, testNum, asset, checkType) { - if (checkType && asset[attr] != checkType) { - console.info(`ASSET_CALLBACK getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } else if (asset[attr] == undefined) { - console.info(`ASSET_CALLBACK getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } -} - -let path; -let presetAsset; -let displayName; -let id; -let mediaType; -let orientation = 0; -export default function fileTestCallBackTest(abilityContext){ - describe('fileTestCallBackTest', function () { - var context = featureAbility.getContext(); - console.info('getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('getMediaLibrary OUT'); - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { }); - - 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); - } - - // ------------------------------- image type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(imagesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - presetAsset = asset1; - media.createAsset( - imageType, - `${new Date().getTime()}.jpg`, - path, - async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.jpg`; - const asset2 = dataList[1]; - const creatAsset2 = await media.createAsset(imageType, displayName, path); - const fd2 = await asset2.open('r'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = imageType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } - } - ); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 001_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file displayName and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 001_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 001_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07 - * @tc.name : commitModify - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(imagesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - asset.commitModify(async () => { - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_CALLBACK getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_CALLBACK getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 001_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 001_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11 - * @tc.name : createAsset - * @tc.desc : Get the orientaion attribute - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.orientation == orientation).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 001_11 failed, message = ' + error); - } - }); - - // ------------------------------- image type end ----------------------------- - - // ------------------------------- video type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - media.createAsset( - videoType, - `${new Date().getTime()}.mp4`, - path, - async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp4`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(videoType, displayName, path); - const fd2 = await asset2.open('r'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = videoType; - - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } - } - ); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 002_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file displayName and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 002_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 002_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - asset.commitModify(async () => { - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_CALLBACK getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_CALLBACK getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 002_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 002_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11 - * @tc.name : createAsset - * @tc.desc : Get the orientaion attribute - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.orientation == orientation).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 002_11 failed, message = ' + error); - } - }); - // ------------------------------- video type end ----------------------------- - - // ------------------------------- audio type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - media.createAsset( - audioType, - `${new Date().getTime()}.mp3`, - path, - async (err, creatAsset1) => { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp3`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(audioType, displayName, path); - const fd2 = await asset2.open('r'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = audioType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } - ); - - } catch (error) { - console.info('ASSET_CALLBACK createAsset 003_01 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file name and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.displayName == displayName).assertTrue(); - - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 003_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 003_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - asset.commitModify(async () => { - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - expect(newAsset.dateModified != asset.dateModified).assertTrue() - done(); - } else { - expect(newAsset.dateModified != undefined).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 003_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 003_08 failed, message = ' + error); - } - }); - - // ------------------------------- audio type end ----------------------------- - - // ------------------------------ file type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - media.createAsset( - fileType, - `${new Date().getTime()}.bat`, - path, - async (err, creatAsset1) => { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.bat`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(fileType, displayName, path); - const fd2 = await asset2.open('r'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = fileType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } - ); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 004_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file name and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 004_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 004_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - asset.commitModify(async () => { - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_CALLBACK getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_CALLBACK getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_CALLBACK getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info('ASSET_CALLBACK getFileAssets 004_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK createAsset 004_08 failed, message = ' + error); - } - }); - - // ------------------------------- file type end ----------------------------- - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestCallBack.test.ets deleted file mode 100755 index b89eaafcfd102cccf825d3e23013b5593bd58ecf..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestCallBack.test.ets +++ /dev/null @@ -1,1003 +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', - dateTaken: '0', - 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 mediaLibraryTestCallBackTest(abilityContext){ - describe('mediaLibraryTestCallBackTest', 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 fileName = new Date().getTime() + '.bat'; - - - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001', 0, async function (done) { - try { - media.getFileAssets(imageRelativefetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_002 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_002', 0, async function (done) { - try { - media.getFileAssets(videoRelativefetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_003 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_003', 0, async function (done) { - try { - media.getFileAssets(audioRelativefetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_004 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_004', 0, async function (done) { - try { - media.getFileAssets(fileRelativefetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_005 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_005', 0, async function (done) { - try { - media.getFileAssets(imageAndVideofetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_006 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_006', 0, async function (done) { - try { - media.getFileAssets(imageAndVideoAndfilefetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_007 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_007', 0, async function (done) { - try { - media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp, async (err, fetchFileResult) => { - 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_CALLBACK_GETFILEASSETS_008 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_008', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', - selectionArgs: ['abc'], - }; - try { - media.getFileAssets(fetchOp, (err, fetchFileResult) => { - expect(fetchFileResult == undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 008 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['abc', audioType.toString()], - }; - try { - media.getFileAssets(fetchOp, (err, fetchFileResult) => { - expect(fetchFileResult == undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 009 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_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 { - media.getFileAssets(fetchOp, (err, fetchFileResult) => { - expect(fetchFileResult == undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 010 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_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 { - media.getFileAssets(fetchOp, (err, fetchFileResult) => { - expect(fetchFileResult == undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 011 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_CAMERA - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001', 0, async function (done) { - try { - - let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; - - media.getPublicDirectory(DIR_CAMERA, async (err, dicResult) => { - expect(dicResult == 'Camera/').assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002', 0, async function (done) { - try { - let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; - - media.getPublicDirectory(DIR_VIDEO, async (err, 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_CALLBACK_GETPUBLICDIRECTORY_003 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003', 0, async function (done) { - try { - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - - media.getPublicDirectory(DIR_IMAGE, async (err, dicResult) => { - expect(dicResult == 'Pictures/').assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004', 0, async function (done) { - try { - let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; - - media.getPublicDirectory(DIR_AUDIO, async (err, dicResult) => { - expect(dicResult == 'Audios/').assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005', 0, async function (done) { - try { - let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - - media.getPublicDirectory(DIR_DOCUMENTS, async (err, dicResult) => { - expect(dicResult == 'Documents/').assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_006 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory 110 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_006', 0, async function (done) { - try { - media.getPublicDirectory(110, async (err, dicResult) => { - expect(dicResult == undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 006 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_009 - * @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_CALLBACK_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(imagesfetchOp); - const asset1 = await fileAssets.getFirstObject(); - const jpgName = new Date().getTime() + '.jpg'; - media.createAsset(imageType, jpgName, filePath, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - 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(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_CREATEASSET_001', 0, async function (done) { - try { - const jpgName = new Date().getTime() + '.jpg'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - - const fileAssets = await media.getFileAssets(imagesfetchOp); - - const asset1 = await fileAssets.getFirstObject(); - - media.createAsset(imageType, jpgName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - 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_CALLBACK_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_CALLBACK_CREATEASSET_002', 0, async function (done) { - try { - const jpgName = new Date().getTime() + '.jpg'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(imagesfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(imageType, jpgName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - media.createAsset(imageType, jpgName, path, async (err, creatAsset2) => { - expect(creatAsset2 == undefined).assertTrue(); - done(); - }); - } - }); - - } catch (error) { - console.info(`MediaLibraryTest : createAsset 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_CREATEASSET_003', 0, async function (done) { - try { - const videoName = new Date().getTime() + '.mp4'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(videoType, videoName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - 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_CALLBACK_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_CALLBACK_CREATEASSET_004', 0, async function (done) { - try { - const videoName = new Date().getTime() + '.mp4'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(videoType, videoName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - media.createAsset(videoType, videoName, path, async (err, creatAsset2) => { - expect(creatAsset2 == undefined).assertTrue(); - done(); - }); - } - }); - - } catch (error) { - console.info(`MediaLibraryTest : createAsset 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_CREATEASSET_005', 0, async function (done) { - try { - const audioName = new Date().getTime() + '.mp3'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(audioType, audioName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - 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_CALLBACK_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_CALLBACK_CREATEASSET_006', 0, async function (done) { - try { - const audioName = new Date().getTime() + '.mp3'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(audioType, audioName, path, async (err, creatAsset1) => { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - media.createAsset(audioType, audioName, path, async (err, creatAsset2) => { - expect(creatAsset2 == undefined).assertTrue(); - done(); - }); - } - }); - - } catch (error) { - console.info(`MediaLibraryTest : createAsset 006 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_CREATEASSET_007', 0, async function (done) { - try { - const fileName = new Date().getTime() + '.bat'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); - const fileAssets = await media.getFileAssets(filesfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(fileType, fileName, path, async (err, creatAsset1) => { - try { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - 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(); - } - }); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_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_CALLBACK_CREATEASSET_008', 0, async function (done) { - try { - const fileName = new Date().getTime() + '.bat'; - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); - const fileAssets = await media.getFileAssets(filesfetchOp); - const asset1 = await fileAssets.getFirstObject(); - media.createAsset(fileType, fileName, path, async (err, creatAsset1) => { - try { - if (creatAsset1 == undefined) { - expect(false).assertTrue(); - done(); - } else { - const fd1 = await asset1.open('r'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - media.createAsset(fileType, fileName, path, async (err, creatAsset2) => { - expect(creatAsset2 == undefined).assertTrue(); - done(); - }); - } - } catch (error) { - console.info(`MediaLibraryTest : createAsset 008 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 008 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_RELEASE_001 - * @tc.name : release - * @tc.desc : Release MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_RELEASE_001', 0, async function (done) { - try { - console.info('MediaLibraryTest : release 001 begin'); - media.release((err, data) => { - if (err == undefined) { - expect(true).assertTrue(); - done(); - } else { - expect(false).assertTrue(); - done(); - }}); - } catch (error) { - console.info('MediaLibraryTest : release 001 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - }); -} -