diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn old mode 100755 new mode 100644 index a3d87a54190c6228d830978f4ad8d1486e40a673..3c4fc742493c9edfef7a5b2f1885f1e6fbaff011 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//test/xts/tools/build/suite.gni") @@ -37,7 +37,12 @@ group("multimedia") { "media/media_js_standard/videoPlayer:video_player_js_hap", "medialibrary/mediaLibrary_album:mediaLibrary_album_hap", "medialibrary/mediaLibrary_favorite:mediaLibrary_favorite_hap", + "medialibrary/mediaLibrary_file:mediaLibrary_file_hap", + "medialibrary/mediaLibrary_fileAsset:mediaLibrary_fileAsset_hap", + "medialibrary/mediaLibrary_fileAssetUri:mediaLibrary_fileAssetUri_hap", + "medialibrary/mediaLibrary_fileKey:mediaLibrary_fileKey_hap", "medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap", + "medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap", "medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap", ] } else { diff --git a/multimedia/medialibrary/common.js b/multimedia/medialibrary/common.js old mode 100644 new mode 100755 index 9a5b3b5387ffb3e00aa9ca4fa4ae9e4993830b18..34e9a1e621d75cf13f938154e33cf633c245872f --- a/multimedia/medialibrary/common.js +++ b/multimedia/medialibrary/common.js @@ -1,200 +1,209 @@ -/* - * 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 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 }, -} - -const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE; -const VIDEO_TYPE = mediaLibrary.MediaType.VIDEO; -const AUDIO_TYPE = mediaLibrary.MediaType.AUDIO; -const FILE_TYPE = mediaLibrary.MediaType.FILE; - -const FILEKEY = mediaLibrary.FileKey; -const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY -const sleep = async function sleep(times = 10) { - await new Promise(res => setTimeout(res, times)); -} - -const allFetchOp = function (others = {}) { - return { - selections: '', - selectionArgs: [], - ...others - }; -} - -const fetchOps = function (path, type, others = {}) { - return { - selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', - selectionArgs: [path, type.toString()], - ...others - }; -} -const nameFetchOps = function (path, title, type) { - return { - selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.TITLE + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', - selectionArgs: [path, title, type.toString()], - }; -} - -const idFetchOps = function (albumId) { - return { - selections: FILEKEY.ALBUM_ID + '= ?', - selectionArgs: [albumId + ''], - }; -} - -const albumFetchOps = function (path, albumName, type, others = { order: FILEKEY.DATE_ADDED + " DESC", }) { - return { - selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?', - selectionArgs: [path, albumName, type.toString()], - ...others - }; -} - -// albums of two resource types -const albumTwoTypesFetchOps = function (paths, albumName, types, others = { order: FILEKEY.DATE_ADDED + " DESC", }) { - try { - let ops = { - selections: '(' + RELATIVE_PATH + '= ? or ' + - RELATIVE_PATH + '= ? ) AND ' + - ALBUM_NAME + '= ? AND (' + - MEDIA_TYPE + '= ? or ' + - MEDIA_TYPE + '= ?)', - selectionArgs: [paths[0], paths[1], albumName, types[0].toString(), types[1].toString()], - ...others - }; - return ops - } catch (error) { - console.info(`albumTwoTypesFetchOps :: error: ${error}`); - } -} - -// albums of three resource types -const albumThreeTypesFetchOps = function (paths, albumName, types, others = { order: FILEKEY.DATE_ADDED, }) { - try { - let ops = { - selections: '(' + RELATIVE_PATH + '= ? or ' + - RELATIVE_PATH + '= ? or ' + - RELATIVE_PATH + '= ? ) AND ' + - ALBUM_NAME + '= ? AND (' + - MEDIA_TYPE + '= ? or ' + - MEDIA_TYPE + '= ? or ' + - MEDIA_TYPE + '= ?)', - selectionArgs: [paths[0], paths[1], paths[2], albumName, - types[0].toString(), types[1].toString(), types[2].toString()], - ...others - }; - return ops - } catch (error) { - console.info(`albumThreeTypesFetchOps :: error: ${error}`); - } -} - -const checkPresetsAssets = async function (media, hapName) { - console.info('checkPresetsAssets start') - let albumList = await media.getAlbums(allFetchOp()); - 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('checkPresetsAssets end') -} - -const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) { - if (!fetchFileResult) { - console.info(`${testNum}:: fetchFileResult error:`); - return false - } - let count = await fetchFileResult.getCount(); - if (count != expectCount) { - console.info(`${testNum}:: count: ${count}`); - console.info(`${testNum}:: expectCount: ${expectCount}`); - expect(count).assertEqual(expectCount); - done(); - } - return count == expectCount; -} - -const checkAlbumsCount = function (done, testNum, albumList, expectCount) { - if (!Array.isArray(albumList)) { - console.info(`${testNum}:: albumList error:`); - return false - } - let albumsCount = albumList.length; - if (albumsCount != expectCount) { - console.info(`${testNum}:: albumsCount: ${albumsCount}`); - console.info(`${testNum}:: expectCount: ${expectCount}`); - console.info(`${testNum} failed:: albums length error`); - expect(albumsCount).assertEqual(expectCount); - done(); - } - return albumsCount == expectCount; -} - -const getPermission = async function (name = 'ohos.acts.multimedia.mediaLibrary') { - console.info('getPermission start', name) - let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); - let tokenID = appInfo.accessTokenId; - let atManager = abilityAccessCtrl.createAtManager(); - let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); - let result2 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1); - let result3 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1); - let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); - let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); - let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); - if (!(result1 == 0 && result2 == 0 && result3 == 0) || !(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0)) { - console.info('getPermission failed') - } - console.info('getPermission end') -} - -const MODIFY_ERROR_CODE_01 = '-1000'; -export { - getPermission, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILE_TYPE, - - FILEKEY, - - sleep, - - allFetchOp, - fetchOps, - nameFetchOps, - idFetchOps, - albumFetchOps, - albumTwoTypesFetchOps, - albumThreeTypesFetchOps, - - checkPresetsAssets, - checkAssetsCount, - checkAlbumsCount, - MODIFY_ERROR_CODE_01, -} +/* + * 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 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 }, +} + +const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE; +const VIDEO_TYPE = mediaLibrary.MediaType.VIDEO; +const AUDIO_TYPE = mediaLibrary.MediaType.AUDIO; +const FILE_TYPE = mediaLibrary.MediaType.FILE; + +const FILEKEY = mediaLibrary.FileKey; +const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY +const sleep = async function sleep(times = 10) { + await new Promise(res => setTimeout(res, times)); +} + +const allFetchOp = function (others = {}) { + return { + selections: '', + selectionArgs: [], + ...others + }; +} + +const fetchOps = function (path, type, others = {}) { + return { + selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', + selectionArgs: [path, type.toString()], + ...others + }; +} +const nameFetchOps = function (path, title, type) { + return { + selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.TITLE + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', + selectionArgs: [path, title, type.toString()], + }; +} + +const idFetchOps = function (albumId) { + return { + selections: FILEKEY.ALBUM_ID + '= ?', + selectionArgs: [albumId + ''], + }; +} + +const albumFetchOps = function (path, albumName, type, others = { order: FILEKEY.DATE_ADDED + " DESC", }) { + return { + selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?', + selectionArgs: [path, albumName, type.toString()], + ...others + }; +} + +// albums of two resource types +const albumTwoTypesFetchOps = function (paths, albumName, types, others = { order: FILEKEY.DATE_ADDED + " DESC", }) { + try { + let ops = { + selections: '(' + RELATIVE_PATH + '= ? or ' + + RELATIVE_PATH + '= ? ) AND ' + + ALBUM_NAME + '= ? AND (' + + MEDIA_TYPE + '= ? or ' + + MEDIA_TYPE + '= ?)', + selectionArgs: [paths[0], paths[1], albumName, types[0].toString(), types[1].toString()], + ...others + }; + return ops + } catch (error) { + console.info(`albumTwoTypesFetchOps :: error: ${error}`); + } +} + +// albums of three resource types +const albumThreeTypesFetchOps = function (paths, albumName, types, others = { order: FILEKEY.DATE_ADDED, }) { + try { + let ops = { + selections: '(' + RELATIVE_PATH + '= ? or ' + + RELATIVE_PATH + '= ? or ' + + RELATIVE_PATH + '= ? ) AND ' + + ALBUM_NAME + '= ? AND (' + + MEDIA_TYPE + '= ? or ' + + MEDIA_TYPE + '= ? or ' + + MEDIA_TYPE + '= ?)', + selectionArgs: [paths[0], paths[1], paths[2], albumName, + types[0].toString(), types[1].toString(), types[2].toString()], + ...others + }; + return ops + } catch (error) { + console.info(`albumThreeTypesFetchOps :: error: ${error}`); + } +} + +const checkPresetsAssets = async function (media, hapName) { + console.info('checkPresetsAssets start') + let albumList = await media.getAlbums(allFetchOp()); + 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('checkPresetsAssets end') +} + +const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) { + if (!fetchFileResult) { + console.info(`${testNum}:: fetchFileResult error:`); + expect(false).assertTrue(); + done(); + return false + } + let count = await fetchFileResult.getCount(); + if (count != expectCount) { + console.info(`${testNum}:: count: ${count}`); + console.info(`${testNum}:: expectCount: ${expectCount}`); + expect(count).assertEqual(expectCount); + done(); + } + return count == expectCount; +} + +const checkAlbumsCount = function (done, testNum, albumList, expectCount) { + if (!Array.isArray(albumList)) { + console.info(`${testNum}:: albumList error:`); + expect(false).assertTrue(); + done(); + return false + } + let albumsCount = albumList.length; + if (albumsCount != expectCount) { + console.info(`${testNum}:: albumsCount: ${albumsCount}`); + console.info(`${testNum}:: expectCount: ${expectCount}`); + console.info(`${testNum} failed:: albums length error`); + expect(albumsCount).assertEqual(expectCount); + done(); + } + return albumsCount == expectCount; +} + +const getPermission = async function (name = 'ohos.acts.multimedia.mediaLibrary') { + console.info('getPermission start', name) + let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); + let tokenID = appInfo.accessTokenId; + let atManager = abilityAccessCtrl.createAtManager(); + let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); + let result2 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1); + let result3 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1); + let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); + let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); + let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); + if (!(result1 == 0 && result2 == 0 && result3 == 0) || !(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0)) { + console.info('getPermission failed') + } + console.info('getPermission end') +} + +const MODIFY_ERROR_CODE_01 = '-1000'; + +const isNum = function (value) { + return typeof value === 'number' && !isNaN(value); +} +export { + getPermission, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + FILEKEY, + sleep, + allFetchOp, + fetchOps, + nameFetchOps, + idFetchOps, + albumFetchOps, + albumTwoTypesFetchOps, + albumThreeTypesFetchOps, + checkPresetsAssets, + checkAssetsCount, + checkAlbumsCount, + MODIFY_ERROR_CODE_01, + isNum, +} diff --git a/multimedia/medialibrary/mediaLibrary_album/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_album/AppScope/app.json old mode 100644 new mode 100755 index 5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba..841282ae47b98590bdbc8aea744fbbcd178e9195 --- a/multimedia/medialibrary/mediaLibrary_album/AppScope/app.json +++ b/multimedia/medialibrary/mediaLibrary_album/AppScope/app.json @@ -1,21 +1,21 @@ -{ - "app":{ - "bundleName":"ohos.acts.multimedia.mediaLibrary", - "vendor":"huawei", - "versionCode":1000000, - "versionName":"1.0.0", - "debug":false, - "icon":"$media:icon", - "label":"$string:entry_MainAbility", - "description":"$string:mainability_description", - "distributedNotificationEnabled":true, - "keepAlive":true, - "singleUser":true, - "minAPIVersion":8, - "targetAPIVersion":8, - "car":{ - "apiCompatibleVersion":8, - "singleUser":false - } - } -} +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/element/string.json old mode 100644 new mode 100755 index c1dee63527ae5e3c37f3736f6b68189e8df6f201..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- a/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_album/AppScope/resources/base/media/app_icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_album/BUILD.gn b/multimedia/medialibrary/mediaLibrary_album/BUILD.gn old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_album/Test.json b/multimedia/medialibrary/mediaLibrary_album/Test.json old mode 100644 new mode 100755 index 4647834d596371514ce954e3534cd25fd91e3db1..b907d3d2d9b281e17207f071496ca105ffc0206b --- a/multimedia/medialibrary/mediaLibrary_album/Test.json +++ b/multimedia/medialibrary/mediaLibrary_album/Test.json @@ -1,66 +1,64 @@ -{ - "description": "Configuration for mediaLibrary Tests", - "driver": { - "type": "JSUnitTest", - "test-timeout": "300000", - "package": "ohos.acts.multimedia.mediaLibrary", - "shell-timeout": "600000" - }, - "kits": [ - { - "type": "ShellKit", - "pre-push": [ - ], - "run-command": [ - "rm -rf /storage/media/100/local/files/*", - "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", - "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}", - "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "PushKit", - "pre-push": [ - ], - "push": [ - "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "ShellKit", - "run-command": [ - "mkdir -pv /storage/media/100/local/files/Pictures/{Static,DynamicPro1,DynamicPro2,DynamicCb1,DynamicCb2}", - "mkdir -pv /storage/media/100/local/files/Videos/Static", - "mkdir -pv /storage/media/100/local/files/Audios/Static", - - "for d in Static; do for i in $$(seq 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 DynamicPro1 DynamicPro2 DynamicCb1 DynamicCb2; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;", - - "chmod -R 777 /storage/media/100/local/files/*", - "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", - "hilog -Q pidoff", - "hilog -p off", - "hilog -b D -D 0xD002B70", - "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "sleep 10", - "cem publish -e usual.event.SCREEN_OFF", - "sleep 10" - ], - "teardown-command":[ - - ] - }, - { - "test-file-name": [ - "ActsMediaLibraryAlbum.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,DynamicPro1,DynamicPro2,DynamicCb1,DynamicCb2}", + "mkdir -pv /storage/media/100/local/files/Videos/Static", + "mkdir -pv /storage/media/100/local/files/Audios/Static", + + "for d in Static; do for i in $$(seq 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 DynamicPro1 DynamicPro2 DynamicCb1 DynamicCb2; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ], + "teardown-command":[ + + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryAlbum.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/Application/AbilityStage.ts old mode 100644 new mode 100755 index 51cb02ba3f5c7011c1cd433d07deebd47a195704..14f230e140160dc5f94ecc462304621178f4cf64 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/Application/AbilityStage.ts +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/Application/AbilityStage.ts @@ -1,9 +1,9 @@ -import AbilityStage from "@ohos.application.AbilityStage" - -export default class MyAbilityStage extends AbilityStage { - onCreate() { - console.log("[Demo] MyAbilityStage onCreate") - globalThis.stageOnCreateRun = 1; - globalThis.stageContext = this.context; - } -} +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/MainAbility/MainAbility.ts old mode 100644 new mode 100755 index 2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,36 +1,36 @@ -import Ability from '@ohos.application.Ability' - -export default class MainAbility extends Ability { - onCreate(want,launchParam){ - // Ability is creating, initialize resources for this ability - console.log("[Demo] MainAbility onCreate") - globalThis.abilityWant = want; - } - - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("[Demo] MainAbility onDestroy") - } - - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("[Demo] MainAbility onWindowStageCreate") - globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) - } - - onWindowStageDestroy() { - //Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") - } - - onForeground() { - // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") - } - - onBackground() { - // Ability has back to background - console.log("[Demo] MainAbility onBackground") - } +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } }; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/index/index.ets old mode 100644 new mode 100755 index 0586aed695fae579cfd58539ab4839737986bbb6..ac301f98781abd45f4d9d98fd7ffecfde9053ed9 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/index/index.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/index/index.ets @@ -1,69 +1,67 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import file from '@system.file'; - -import { Core, ExpectExtend, InstrumentLog, ReportExtend } from "deccjsunit/index" -import testsuite from "../../test/List.test.ets" -import { getPermission } from "../../../../../../../common" - -@Entry -@Component -struct Index { - - aboutToAppear(){ - getPermission() - console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - const reportExtend = new ReportExtend(file) - - core.addService('report', reportExtend) - core.init() - core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - console.info('testsuite()---->') - testsuite(globalThis.abilityContext) - core.execute() - console.info('core.execute()---->') - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(25) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import { Core, ExpectExtend, InstrumentLog, ReportExtend } from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/second/second.ets old mode 100644 new mode 100755 index 1c1c727ff11ecc97909f482c35268db87ae23bb4..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/second/second.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/pages/second/second.ets @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import router from '@system.router'; - -@Entry -@Component -struct Second { - private content: string = "Second Page" - - build() { - Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(`${this.content}`) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('back to index') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/List.test.ets old mode 100644 new mode 100755 index 3836260d62a420e4dc82c98f0a051dae3f3e557e..a1815e3af63565a6051a434bc1351dbed77650b4 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/List.test.ets @@ -1,24 +1,24 @@ -/* - * 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 albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.ets' -import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets' -import albumTestCallBackTest from './albumTestCallBack.test.ets' -import albumTestPromiseTest from './albumTestPromise.test.ets' -export default function testsuite(abilityContext) { - albumGetFileAssetsCallbackTest(abilityContext) - albumGetFileAssetsPromiseTest(abilityContext) - albumTestPromiseTest(abilityContext) - albumTestCallBackTest(abilityContext) -} +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.ets' +import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets' +import albumTestCallBackTest from './albumTestCallBack.test.ets' +import albumTestPromiseTest from './albumTestPromise.test.ets' +export default function testsuite(abilityContext) { + albumGetFileAssetsCallbackTest(abilityContext) + albumGetFileAssetsPromiseTest(abilityContext) + albumTestPromiseTest(abilityContext) + albumTestCallBackTest(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets old mode 100644 new mode 100755 index 0aad61b59fa8bafe1a58cf871c3bd48fb47d3a99..831055fdd5d3b16490c7be720efa9286df23ec9e --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsCallback.test.ets @@ -1,393 +1,395 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILEKEY, - allFetchOp, - albumFetchOps, - albumTwoTypesFetchOps, - albumThreeTypesFetchOps, - checkPresetsAssets, - checkAlbumsCount, -} from '../../../../../../common'; - -export default function albumGetFileAssetsCallbackTest(abilityContext) { - describe('albumGetFileAssetsCallbackTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); - }); - beforeEach(function () { }); - afterEach(async function () { - await sleep() - }); - afterAll(function () { }); - - const abnormalFetchOp = { - selections: 'date_added < 0', - selectionArgs: [], - order: 'date_added DESC LIMIT 0,1', - } - - const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - - const albumList = await media.getAlbums(fetchOp); - // check album length - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - // one asset type - if (expectAlbumCount == 1) { - const album = albumList[0]; - album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => { - if (fetchFileResult == undefined || error) { - console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) - expect(false).assertTrue(); - done(); - return; - } - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - done(); - }); - } else { - // more asset type - let count = 0; - for (const album of albumList) { - album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => { - if (fetchFileResult == undefined || error) { - console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) - expect(false).assertTrue(); - done(); - return; - } - count++; - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - }); - await sleep(500) - } - await sleep(500) - expect(count).assertEqual(expectAlbumCount); - done(); - } - } catch (error) { - console.info(`${testNum}, error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - const albumList = await media.getAlbums(fetchOp); - // check album length - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - album.getFileAssets(abnormalFetchOp, (error, fetchFileResult) => { - if (fetchFileResult == undefined || error) { - console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) - expect(false).assertTrue(); - done(); - return; - } - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - done(); - }); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01 - * @tc.name : getFileAssets - * @tc.desc : Image type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02 - * @tc.name : getFileAssets - * @tc.desc : Audios type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03 - * @tc.name : getFileAssets - * @tc.desc : Videos type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05 - * @tc.name : getFileAssets - * @tc.desc : Pictures Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06 - * @tc.name : getFileAssets - * @tc.desc : Videos Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07'; - let assetsCount = 3; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 3; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01 - * @tc.name : getFileAssets - * @tc.desc : Image type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02 - * @tc.name : getFileAssets - * @tc.desc : Audios type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03 - * @tc.name : getFileAssets - * @tc.desc : Videos type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05 - * @tc.name : getFileAssets - * @tc.desc : Pictures Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE],) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06 - * @tc.name : getFileAssets - * @tc.desc : Videos Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07'; - let assetsCount = 1; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', - [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 3; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01'; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02'; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03'; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - }); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + allFetchOp, + albumFetchOps, + albumTwoTypesFetchOps, + albumThreeTypesFetchOps, + checkPresetsAssets, + checkAlbumsCount, + getPermission, +} from '../../../../../../common'; + +export default function albumGetFileAssetsCallbackTest(abilityContext) { + describe('albumGetFileAssetsCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + const abnormalFetchOp = { + selections: 'date_added < 0', + selectionArgs: [], + order: 'date_added DESC LIMIT 0,1', + } + + const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + + const albumList = await media.getAlbums(fetchOp); + // check album length + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + // one asset type + if (expectAlbumCount == 1) { + const album = albumList[0]; + album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => { + if (fetchFileResult == undefined || error) { + console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) + expect(false).assertTrue(); + done(); + return; + } + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + done(); + }); + } else { + // more asset type + let count = 0; + for (const album of albumList) { + album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => { + if (fetchFileResult == undefined || error) { + console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) + expect(false).assertTrue(); + done(); + return; + } + count++; + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + }); + await sleep(500) + } + await sleep(500) + expect(count).assertEqual(expectAlbumCount); + done(); + } + } catch (error) { + console.info(`${testNum}, error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + const albumList = await media.getAlbums(fetchOp); + // check album length + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + album.getFileAssets(abnormalFetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined || error) { + console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`) + expect(false).assertTrue(); + done(); + return; + } + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + done(); + }); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01 + * @tc.name : getFileAssets + * @tc.desc : Image type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02 + * @tc.name : getFileAssets + * @tc.desc : Audios type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03 + * @tc.name : getFileAssets + * @tc.desc : Videos type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05 + * @tc.name : getFileAssets + * @tc.desc : Pictures Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06 + * @tc.name : getFileAssets + * @tc.desc : Videos Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07'; + let assetsCount = 3; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 3; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01 + * @tc.name : getFileAssets + * @tc.desc : Image type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_01'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02 + * @tc.name : getFileAssets + * @tc.desc : Audios type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_02'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03 + * @tc.name : getFileAssets + * @tc.desc : Videos type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_03'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_04'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05 + * @tc.name : getFileAssets + * @tc.desc : Pictures Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_05'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE],) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06 + * @tc.name : getFileAssets + * @tc.desc : Videos Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_06'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_002_07'; + let assetsCount = 1; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', + [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 3; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_01'; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_02'; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_003_03'; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + }); } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets old mode 100644 new mode 100755 index 66cb9e93c359e890cb088ce8415e77e566d68cdd..a1a9c2dbd1a800ebc4e36a6cc2a601112b37e1d3 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumGetFileAssetsPromise.test.ets @@ -1,392 +1,392 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILEKEY, - allFetchOp, - albumFetchOps, - albumTwoTypesFetchOps, - albumThreeTypesFetchOps, - checkPresetsAssets, - checkAlbumsCount, -} from '../../../../../../common'; - -export default function albumGetFileAssetsPromiseTest(abilityContext) { - describe('albumGetFileAssetsPromiseTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); - }); - beforeEach(function () { }); - afterEach(async function () { - await sleep() - }); - afterAll(function () { }); - - // Exception request - const abnormalFetchOp = { - selections: 'date_added < 0', - selectionArgs: [], - order: 'date_added DESC LIMIT 0,1', - } - - const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - - const albumList = await media.getAlbums(fetchOp); - // check album length - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - // one asset type - let op:mediaLibrary.MediaFetchOptions = - allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }) - if (expectAlbumCount == 1) { - const album = albumList[0]; - - let fetchFileResult = await album.getFileAssets(op); - if (fetchFileResult == undefined) { - console.info(`${testNum} fetchFileResult undefined`) - expect(false).assertTrue(); - done(); - return; - } - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - done(); - } else { - // more asset type - let count = 0; - for (const album of albumList) { - let fetchFileResult = await album.getFileAssets(op); - if (fetchFileResult == undefined) { - console.info(`${testNum} fetchFileResult undefined`) - expect(false).assertTrue(); - done(); - return; - } - count++; - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - } - expect(count).assertEqual(expectAlbumCount); - done(); - } - } catch (error) { - console.info(`${testNum}, error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - const albumList = await media.getAlbums(fetchOp); - // check album length - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(abnormalFetchOp); - if (fetchFileResult == undefined) { - console.info(`${testNum} fetchFileResult undefined`) - expect(false).assertTrue(); - done(); - return; - } - console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) - console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) - expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01 - * @tc.name : getFileAssets - * @tc.desc : Image type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 - * @tc.name : getFileAssets - * @tc.desc : Audios type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 - * @tc.name : getFileAssets - * @tc.desc : Videos type album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03'; - let assetsCount = 3; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 - * @tc.name : getFileAssets - * @tc.desc : Pictures Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 - * @tc.name : getFileAssets - * @tc.desc : Videos Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06'; - let assetsCount = 3; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos Audios types album get 3 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07'; - let assetsCount = 3; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 3; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01 - * @tc.name : getFileAssets - * @tc.desc : Image type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02 - * @tc.name : getFileAssets - * @tc.desc : Audios type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03 - * @tc.name : getFileAssets - * @tc.desc : Videos type album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03'; - let assetsCount = 1; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05 - * @tc.name : getFileAssets - * @tc.desc : Pictures Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE],) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06 - * @tc.name : getFileAssets - * @tc.desc : Videos Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06'; - let assetsCount = 1; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 2; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07 - * @tc.name : getFileAssets - * @tc.desc : Pictures Videos Audios types album get 1 resources - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07'; - let assetsCount = 1; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', - [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let albumCount = 3; - await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) - }); - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01'; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02'; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03'; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) - let assetsCount = 0; - await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) - }); - }); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + allFetchOp, + albumFetchOps, + albumTwoTypesFetchOps, + albumThreeTypesFetchOps, + checkPresetsAssets, + checkAlbumsCount, +} from '../../../../../../common'; + +export default function albumGetFileAssetsPromiseTest(abilityContext) { + describe('albumGetFileAssetsPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + // Exception request + const abnormalFetchOp = { + selections: 'date_added < 0', + selectionArgs: [], + order: 'date_added DESC LIMIT 0,1', + } + + const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + + const albumList = await media.getAlbums(fetchOp); + // check album length + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + // one asset type + let op:mediaLibrary.MediaFetchOptions = + allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }) + if (expectAlbumCount == 1) { + const album = albumList[0]; + + let fetchFileResult = await album.getFileAssets(op); + if (fetchFileResult == undefined) { + console.info(`${testNum} fetchFileResult undefined`) + expect(false).assertTrue(); + done(); + return; + } + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + done(); + } else { + // more asset type + let count = 0; + for (const album of albumList) { + let fetchFileResult = await album.getFileAssets(op); + if (fetchFileResult == undefined) { + console.info(`${testNum} fetchFileResult undefined`) + expect(false).assertTrue(); + done(); + return; + } + count++; + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + } + expect(count).assertEqual(expectAlbumCount); + done(); + } + } catch (error) { + console.info(`${testNum}, error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumAssetsCount = async function (done, testNum, fetchOp, expectAssetsCount, expectAlbumCount = 1) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + const albumList = await media.getAlbums(fetchOp); + // check album length + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(abnormalFetchOp); + if (fetchFileResult == undefined) { + console.info(`${testNum} fetchFileResult undefined`) + expect(false).assertTrue(); + done(); + return; + } + console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) + console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) + expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01 + * @tc.name : getFileAssets + * @tc.desc : Image type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 + * @tc.name : getFileAssets + * @tc.desc : Audios type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 + * @tc.name : getFileAssets + * @tc.desc : Videos type album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03'; + let assetsCount = 3; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 + * @tc.name : getFileAssets + * @tc.desc : Pictures Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 + * @tc.name : getFileAssets + * @tc.desc : Videos Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06'; + let assetsCount = 3; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos Audios types album get 3 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07'; + let assetsCount = 3; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 3; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01 + * @tc.name : getFileAssets + * @tc.desc : Image type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_01'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02 + * @tc.name : getFileAssets + * @tc.desc : Audios type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_02'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03 + * @tc.name : getFileAssets + * @tc.desc : Videos type album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_03'; + let assetsCount = 1; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_04'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05 + * @tc.name : getFileAssets + * @tc.desc : Pictures Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_05'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE],) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06 + * @tc.name : getFileAssets + * @tc.desc : Videos Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_06'; + let assetsCount = 1; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 2; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07 + * @tc.name : getFileAssets + * @tc.desc : Pictures Videos Audios types album get 1 resources + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_002_07'; + let assetsCount = 1; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', + [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let albumCount = 3; + await checkAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount, albumCount) + }); + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_01'; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_02'; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_003_03'; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE) + let assetsCount = 0; + await abnormalAlbumAssetsCount(done, testNum, currentFetchOp, assetsCount) + }); + }); } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestCallBack.test.ets old mode 100644 new mode 100755 index 5a0617653c0ad02f3d5669308b2fbca3289c5827..ba91991b75be9511d7060f26587e53f18ae72645 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestCallBack.test.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestCallBack.test.ets @@ -1,418 +1,418 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILEKEY, - allFetchOp, - idFetchOps, - albumFetchOps, - albumTwoTypesFetchOps, - albumThreeTypesFetchOps, - checkPresetsAssets, - checkAlbumsCount, -} from '../../../../../../common'; - - -export default function albumTestCallbackTest(abilityContext) { - describe('albumTestCallbackTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); - }); - beforeEach(function () { }); - afterEach(async function () { - await sleep() - }); - afterAll(function () { }); - - function printAlbumMessage(testNum, album) { - console.info(`${testNum} album.albumId: ${album.albumId}`); - console.info(`${testNum} album.albumName: ${album.albumName}`); - console.info(`${testNum} album.albumUri: ${album.albumUri}`); - console.info(`${testNum} album.dateModified: ${album.dateModified}`); - console.info(`${testNum} album.count: ${album.count}`); - console.info(`${testNum} album.relativePath: ${album.relativePath}`); - console.info(`${testNum} album.coverUri: ${album.coverUri}`); - } - - const props = { - albumName: 'Static', - albumUri: 'datashare:///media/album/', - count: 5 - } - const checkProps = async function (done, testNum, album, relativePaths) { - printAlbumMessage(testNum, album); - if (album.albumId == undefined || album.coverUri == undefined) { - console.info(`${testNum}, album.albumId or album.coverUri is undefined`) - expect(false).assertTrue(); - done(); - return; - } - expect(album.albumName).assertEqual(props.albumName); - expect(album.albumUri).assertEqual(props.albumUri + album.albumId); - expect(album.count).assertEqual(props.count); - if (Array.isArray(relativePaths)) { - let i = relativePaths.indexOf(album.relativePath) - if (i > -1) { - relativePaths.splice(i, 1) - } else { - expect(false).assertTrue(); - done(); - } - } else { - expect(album.relativePath).assertEqual(relativePaths); - } - } - const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths, expectAlbumCount) { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - try { - media.getAlbums(fetchOp, async (err, albumList) => { - if(err) { - console.info(`${testNum}, err: ${err}`) - expect(false).assertTrue(); - done(); - return; - } - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - if (expectAlbumCount == 1) { - const album = albumList[0]; - checkProps(done, testNum, album, relativePaths); - done(); - } else { - let count = 0 - for (const album of albumList) { - checkProps(done, testNum, album, relativePaths); - count++; - } - expect(count).assertEqual(expectAlbumCount); - expect(relativePaths.length).assertEqual(0); - done(); - } - }); - } catch (error) { - console.info(`${testNum}, failed: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumCount = async function (done, testNum, fetchOp) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - media.getAlbums(fetchOp, async (err, albumList) => { - if(err) { - expect(true).assertTrue(); - done(); - return; - } - console.info(`${testNum}, albumList.length: ${albumList.length}`) - expect(albumList.length).assertEqual(0); - done(); - }); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumCommitModify = async function (done, testNum, fetchOp, newName, expectAlbumCount) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - const albumList = await media.getAlbums(fetchOp); - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - album.albumName = newName; - album.commitModify(async (error) => { - console.info(`${testNum}, error.message: ${error.message}`) - console.info(`${testNum}, error.code: ${error.code}`) - expect(error.code != undefined).assertTrue(); - done(); - }); - } catch (error) { - console.info(`${testNum}, error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - // ------------------------------ 001 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01 - * @tc.name : getAlbums - * @tc.desc : Get Album by allTypeInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01'; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); - let relativePaths = 'Pictures/'; - let expectAlbumCount = 1; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02'; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE); - let relativePaths = 'Videos/'; - let expectAlbumCount = 1; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03'; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE); - let relativePaths = 'Audios/'; - let expectAlbumCount = 1; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04 - * @tc.name : getAlbums - * @tc.desc : Get Album by image 、Video types, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, videoType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04'; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let relativePaths = ['Pictures/', 'Videos/']; - let expectAlbumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05'; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) - let relativePaths = ['Pictures/', 'Audios/']; - let expectAlbumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndAudioAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06'; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let relativePaths = ['Videos/', 'Audios/']; - let expectAlbumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAndAudioAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07'; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let relativePaths = ['Pictures/', 'Videos/', 'Audios/']; - let expectAlbumCount = 3; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); - }); - // ------------------------------ 001 test end ------------------------- - - // ------------------------------ 002 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: FILEKEY.MEDIA_TYPE + ' = ?', - selectionArgs: ['666'], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06' - - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: '666' + '= ?', - selectionArgs: [VIDEO_TYPE.toString()], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07' - - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: '666' + '= ?', - selectionArgs: ['666'], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08' - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - // ------------------------------ 002 test end ------------------------- - - // ------------------------------ 003 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01 - * @tc.name : commitModify - * @tc.desc : Modify Album name to 'hello' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01'; - try { - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb1', IMAGE_TYPE); - console.info(`${testNum}, currentFetchOp: ${JSON.stringify(currentFetchOp)}`) - - const albumList = await media.getAlbums(currentFetchOp); - const expectAlbumCount = 1; - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - const albumId = album.albumId; - console.info(`${testNum}, album.albumName(old): ${album.albumName}`) - const newName = 'albumName' + new Date().getTime(); - album.albumName = newName; - album.commitModify(async () => { - let currentfetchOp = idFetchOps(albumId) - const newAlbumList = await media.getAlbums(currentfetchOp); - console.info(`${testNum}, album.albumName(new): ${newAlbumList[0].albumName}`) - expect(newAlbumList[0].albumName).assertEqual(newName); - album.albumName = 'DynamicCb1'; - await album.commitModify(); - done(); - }); - - } catch (error) { - console.info(`${testNum}, failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02 - * @tc.name : commitModify - * @tc.desc : Modify Album name '' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02'; - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb2', IMAGE_TYPE); - let newName = ''; - let expectAlbumCount = 1; - await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04 - * @tc.name : commitModify - * @tc.desc : Modify Album name 'i123456...119' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04'; - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb2', IMAGE_TYPE); - let newName = ""; - for (var i = 0; i < 1200; i++) { - newName += i.toString(); - } - let expectAlbumCount = 1; - await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) - }); - // // ------------------------------ 003 test end ------------------------- - }); -} - - +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + allFetchOp, + idFetchOps, + albumFetchOps, + albumTwoTypesFetchOps, + albumThreeTypesFetchOps, + checkPresetsAssets, + checkAlbumsCount, +} from '../../../../../../common'; + + +export default function albumTestCallbackTest(abilityContext) { + describe('albumTestCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + function printAlbumMessage(testNum, album) { + console.info(`${testNum} album.albumId: ${album.albumId}`); + console.info(`${testNum} album.albumName: ${album.albumName}`); + console.info(`${testNum} album.albumUri: ${album.albumUri}`); + console.info(`${testNum} album.dateModified: ${album.dateModified}`); + console.info(`${testNum} album.count: ${album.count}`); + console.info(`${testNum} album.relativePath: ${album.relativePath}`); + console.info(`${testNum} album.coverUri: ${album.coverUri}`); + } + + const props = { + albumName: 'Static', + albumUri: 'datashare:///media/album/', + count: 5 + } + const checkProps = async function (done, testNum, album, relativePaths) { + printAlbumMessage(testNum, album); + if (album.albumId == undefined || album.coverUri == undefined) { + console.info(`${testNum}, album.albumId or album.coverUri is undefined`) + expect(false).assertTrue(); + done(); + return; + } + expect(album.albumName).assertEqual(props.albumName); + expect(album.albumUri).assertEqual(props.albumUri + album.albumId); + expect(album.count).assertEqual(props.count); + if (Array.isArray(relativePaths)) { + let i = relativePaths.indexOf(album.relativePath) + if (i > -1) { + relativePaths.splice(i, 1) + } else { + expect(false).assertTrue(); + done(); + } + } else { + expect(album.relativePath).assertEqual(relativePaths); + } + } + const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths, expectAlbumCount) { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + try { + media.getAlbums(fetchOp, async (err, albumList) => { + if(err) { + console.info(`${testNum}, err: ${err}`) + expect(false).assertTrue(); + done(); + return; + } + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + if (expectAlbumCount == 1) { + const album = albumList[0]; + checkProps(done, testNum, album, relativePaths); + done(); + } else { + let count = 0 + for (const album of albumList) { + checkProps(done, testNum, album, relativePaths); + count++; + } + expect(count).assertEqual(expectAlbumCount); + expect(relativePaths.length).assertEqual(0); + done(); + } + }); + } catch (error) { + console.info(`${testNum}, failed: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumCount = async function (done, testNum, fetchOp) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + media.getAlbums(fetchOp, async (err, albumList) => { + if(err) { + expect(true).assertTrue(); + done(); + return; + } + console.info(`${testNum}, albumList.length: ${albumList.length}`) + expect(albumList.length).assertEqual(0); + done(); + }); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumCommitModify = async function (done, testNum, fetchOp, newName, expectAlbumCount) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + const albumList = await media.getAlbums(fetchOp); + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + album.albumName = newName; + album.commitModify(async (error) => { + console.info(`${testNum}, error.message: ${error.message}`) + console.info(`${testNum}, error.code: ${error.code}`) + expect(error.code != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`${testNum}, error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01 + * @tc.name : getAlbums + * @tc.desc : Get Album by allTypeInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01'; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); + let relativePaths = 'Pictures/'; + let expectAlbumCount = 1; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02'; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE); + let relativePaths = 'Videos/'; + let expectAlbumCount = 1; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03'; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE); + let relativePaths = 'Audios/'; + let expectAlbumCount = 1; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04 + * @tc.name : getAlbums + * @tc.desc : Get Album by image 、Video types, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, videoType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04'; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let relativePaths = ['Pictures/', 'Videos/']; + let expectAlbumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05'; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) + let relativePaths = ['Pictures/', 'Audios/']; + let expectAlbumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndAudioAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06'; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let relativePaths = ['Videos/', 'Audios/']; + let expectAlbumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAndAudioAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07'; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let relativePaths = ['Pictures/', 'Videos/', 'Audios/']; + let expectAlbumCount = 3; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, expectAlbumCount); + }); + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: FILEKEY.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06' + + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: '666' + '= ?', + selectionArgs: [VIDEO_TYPE.toString()], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07' + + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: '666' + '= ?', + selectionArgs: ['666'], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08' + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + // ------------------------------ 002 test end ------------------------- + + // ------------------------------ 003 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01 + * @tc.name : commitModify + * @tc.desc : Modify Album name to 'hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01'; + try { + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb1', IMAGE_TYPE); + console.info(`${testNum}, currentFetchOp: ${JSON.stringify(currentFetchOp)}`) + + const albumList = await media.getAlbums(currentFetchOp); + const expectAlbumCount = 1; + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + const albumId = album.albumId; + console.info(`${testNum}, album.albumName(old): ${album.albumName}`) + const newName = 'albumName' + new Date().getTime(); + album.albumName = newName; + album.commitModify(async () => { + let currentfetchOp = idFetchOps(albumId) + const newAlbumList = await media.getAlbums(currentfetchOp); + console.info(`${testNum}, album.albumName(new): ${newAlbumList[0].albumName}`) + expect(newAlbumList[0].albumName).assertEqual(newName); + album.albumName = 'DynamicCb1'; + await album.commitModify(); + done(); + }); + + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name '' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02'; + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb2', IMAGE_TYPE); + let newName = ''; + let expectAlbumCount = 1; + await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04 + * @tc.name : commitModify + * @tc.desc : Modify Album name 'i123456...119' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04'; + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicCb2', IMAGE_TYPE); + let newName = ""; + for (var i = 0; i < 1200; i++) { + newName += i.toString(); + } + let expectAlbumCount = 1; + await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) + }); + // // ------------------------------ 003 test end ------------------------- + }); +} + + diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestPromise.test.ets old mode 100644 new mode 100755 index d8658030f570fa4382ec8fd5f66392e27ef707d5..b45abe7bddfabeb69dd8a57d9416dd9aea6136cf --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/ets/test/albumTestPromise.test.ets @@ -1,441 +1,441 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILEKEY, - allFetchOp, - idFetchOps, - albumFetchOps, - albumTwoTypesFetchOps, - albumThreeTypesFetchOps, - checkPresetsAssets, - checkAlbumsCount, -} from '../../../../../../common'; - -export default function albumTestPromiseTest(abilityContext) { - describe('albumTestPromiseTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); - }); - beforeEach(function () { }); - afterEach(async function () { - await sleep() - }); - afterAll(function () { }); - - function printAlbumMessage(testNum, album) { - console.info(`${testNum} album.albumId: ${album.albumId}`); - console.info(`${testNum} album.albumName: ${album.albumName}`); - console.info(`${testNum} album.albumUri: ${album.albumUri}`); - console.info(`${testNum} album.dateModified: ${album.dateModified}`); - console.info(`${testNum} album.count: ${album.count}`); - console.info(`${testNum} album.relativePath: ${album.relativePath}`); - console.info(`${testNum} album.coverUri: ${album.coverUri}`); - } - - const props = { - albumName: 'Static', - albumUri: 'datashare:///media/album/', - count: 5 - } - const checkProps = async function (done, testNum, album, relativePaths) { - printAlbumMessage(testNum, album); - if (album.albumId == undefined || album.coverUri == undefined) { - console.info(`${testNum}, album.albumId or album.coverUri is undefined`) - expect(false).assertTrue(); - done(); - return; - } - expect(album.albumName).assertEqual(props.albumName); - expect(album.albumUri).assertEqual(props.albumUri + album.albumId); - expect(album.count).assertEqual(props.count); - if (Array.isArray(relativePaths)) { - let i = relativePaths.indexOf(album.relativePath) - if (i > -1) { - relativePaths.splice(i, 1) - } else { - expect(false).assertTrue(); - done(); - } - } else { - expect(album.relativePath).assertEqual(relativePaths); - } - } - const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths, expectAlbumCount = 1) { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - try { - const albumList = await media.getAlbums(fetchOp); - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - if (expectAlbumCount == 1) { - const album = albumList[0]; - checkProps(done, testNum, album, relativePaths); - done(); - } else { - let count = 0 - for (const album of albumList) { - checkProps(done, testNum, album, relativePaths); - count++; - } - expect(count).assertEqual(expectAlbumCount); - expect(relativePaths.length).assertEqual(0); - done(); - } - } catch (error) { - console.info(`${testNum}, failed: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumCount = async function (done, testNum, fetchOp) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - const albumList = await media.getAlbums(fetchOp); - console.info(`${testNum}, albumList.length: ${albumList.length}`) - expect(albumList.length).assertEqual(0); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const abnormalAlbumCommitModify = async function (done, testNum, fetchOp, newName, expectAlbumCount) { - try { - console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) - const albumList = await media.getAlbums(fetchOp); - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - album.albumName = newName; - await album.commitModify(); - console.info(`${testNum}, failed`) - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`${testNum}, error.message: ${error.message}`) - console.info(`${testNum}, error.code: ${error.code}`) - expect(error.code!=undefined).assertTrue(); - done(); - } - } - // ------------------------------ 001 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01 - * @tc.name : getAlbums - * @tc.desc : Get Album by allTypeInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01'; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); - let relativePaths = 'Pictures/'; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02'; - let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE); - let relativePaths = 'Videos/'; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03'; - let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE); - let relativePaths = 'Audios/'; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, videoType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04'; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) - let relativePaths = ['Pictures/', 'Videos/']; - let albumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05'; - let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) - let relativePaths = ['Pictures/', 'Audios/']; - let albumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndAudioAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06'; - let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) - let relativePaths = ['Videos/', 'Audios/']; - let albumCount = 2; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAndAudioAlbumInfofetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07'; - let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) - let relativePaths = ['Pictures/', 'Videos/', 'Audios/']; - let albumCount = 3; - await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); - }); - // ------------------------------ 001 test end ------------------------- - - // ------------------------------ 002 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: FILEKEY.MEDIA_TYPE + ' = ?', - selectionArgs: ['666'], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06' - - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: '666' + '= ?', - selectionArgs: [VIDEO_TYPE.toString()], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07' - - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) { - let fileHasArgsfetchOp = { - selections: '666' + '= ?', - selectionArgs: ['666'], - }; - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08' - await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) - }); - // ------------------------------ 002 test end ------------------------- - - // ------------------------------ 003 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01 - * @tc.name : commitModify - * @tc.desc : Modify Album name to 'hello' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) { - const testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01'; - try { - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro1', IMAGE_TYPE); - console.info(`${testNum}, currentFetchOp: ${JSON.stringify(currentFetchOp)}`) - - const albumList = await media.getAlbums(currentFetchOp); - const expectAlbumCount = 1; - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - const albumId = album.albumId; - console.info(`${testNum}, album.albumName(old): ${album.albumName}`) - const newName = 'albumName' + new Date().getTime(); - album.albumName = newName; - await album.commitModify(); - let currentfetchOp = idFetchOps(albumId) - const newAlbumList = await media.getAlbums(currentfetchOp); - console.info(`${testNum}, album.albumName(new): ${newAlbumList[0].albumName}`) - expect(newAlbumList[0].albumName).assertEqual(newName); - - album.albumName = 'DynamicPro1'; - await album.commitModify(); - done(); - } catch (error) { - console.info(`${testNum}, failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02 - * @tc.name : commitModify - * @tc.desc : Modify Album name '' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02'; - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro2', IMAGE_TYPE); - let newName = ''; - let expectAlbumCount = 1; - await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04 - * @tc.name : commitModify - * @tc.desc : Modify Album name 'i123456...119' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04'; - let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro2', IMAGE_TYPE); - let newName = ""; - for (var i = 0; i < 1200; i++) { - newName += i.toString(); - } - let expectAlbumCount = 1; - await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) - }); - // // ------------------------------ 003 test end ------------------------- - - // ------------------------------ 004 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01 - * @tc.name : album.coverUri - * @tc.desc : check album.coverUri - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01'; - try { - let coverUrifetchOp = { - selections: '', - selectionArgs: [], - order: 'date_added DESC LIMIT 0,1', - }; - let expectAlbumCount = 1; - let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); - const albumList = await media.getAlbums(currentFetchOp); - const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); - if (!albumCountPass) return; - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(coverUrifetchOp); - const asset = await fetchFileResult.getFirstObject(); - if (asset == undefined) { - console.info(`${testNum} failed asset undefined`) - - expect(false).assertTrue(); - done(); - return - } - expect(asset.uri).assertEqual(album.coverUri); - done(); - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 004 test end ------------------------- - }); -} - - +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + allFetchOp, + idFetchOps, + albumFetchOps, + albumTwoTypesFetchOps, + albumThreeTypesFetchOps, + checkPresetsAssets, + checkAlbumsCount, +} from '../../../../../../common'; + +export default function albumTestPromiseTest(abilityContext) { + describe('albumTestPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryAlbum'); + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + function printAlbumMessage(testNum, album) { + console.info(`${testNum} album.albumId: ${album.albumId}`); + console.info(`${testNum} album.albumName: ${album.albumName}`); + console.info(`${testNum} album.albumUri: ${album.albumUri}`); + console.info(`${testNum} album.dateModified: ${album.dateModified}`); + console.info(`${testNum} album.count: ${album.count}`); + console.info(`${testNum} album.relativePath: ${album.relativePath}`); + console.info(`${testNum} album.coverUri: ${album.coverUri}`); + } + + const props = { + albumName: 'Static', + albumUri: 'datashare:///media/album/', + count: 5 + } + const checkProps = async function (done, testNum, album, relativePaths) { + printAlbumMessage(testNum, album); + if (album.albumId == undefined || album.coverUri == undefined) { + console.info(`${testNum}, album.albumId or album.coverUri is undefined`) + expect(false).assertTrue(); + done(); + return; + } + expect(album.albumName).assertEqual(props.albumName); + expect(album.albumUri).assertEqual(props.albumUri + album.albumId); + expect(album.count).assertEqual(props.count); + if (Array.isArray(relativePaths)) { + let i = relativePaths.indexOf(album.relativePath) + if (i > -1) { + relativePaths.splice(i, 1) + } else { + expect(false).assertTrue(); + done(); + } + } else { + expect(album.relativePath).assertEqual(relativePaths); + } + } + const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths, expectAlbumCount = 1) { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + try { + const albumList = await media.getAlbums(fetchOp); + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + if (expectAlbumCount == 1) { + const album = albumList[0]; + checkProps(done, testNum, album, relativePaths); + done(); + } else { + let count = 0 + for (const album of albumList) { + checkProps(done, testNum, album, relativePaths); + count++; + } + expect(count).assertEqual(expectAlbumCount); + expect(relativePaths.length).assertEqual(0); + done(); + } + } catch (error) { + console.info(`${testNum}, failed: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumCount = async function (done, testNum, fetchOp) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + const albumList = await media.getAlbums(fetchOp); + console.info(`${testNum}, albumList.length: ${albumList.length}`) + expect(albumList.length).assertEqual(0); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const abnormalAlbumCommitModify = async function (done, testNum, fetchOp, newName, expectAlbumCount) { + try { + console.info(`${testNum}, fetchOp: ${JSON.stringify(fetchOp)}`) + const albumList = await media.getAlbums(fetchOp); + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + album.albumName = newName; + await album.commitModify(); + console.info(`${testNum}, failed`) + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}, error.message: ${error.message}`) + console.info(`${testNum}, error.code: ${error.code}`) + expect(error.code!=undefined).assertTrue(); + done(); + } + } + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01 + * @tc.name : getAlbums + * @tc.desc : Get Album by allTypeInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01'; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); + let relativePaths = 'Pictures/'; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02'; + let currentFetchOp = albumFetchOps('Videos/', 'Static', VIDEO_TYPE); + let relativePaths = 'Videos/'; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03'; + let currentFetchOp = albumFetchOps('Audios/', 'Static', AUDIO_TYPE); + let relativePaths = 'Audios/'; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, videoType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04'; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Videos/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE]) + let relativePaths = ['Pictures/', 'Videos/']; + let albumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndVideoAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05'; + let currentFetchOp = albumTwoTypesFetchOps(['Pictures/', 'Audios/'], 'Static', [IMAGE_TYPE, AUDIO_TYPE]) + let relativePaths = ['Pictures/', 'Audios/']; + let albumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndAudioAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06'; + let currentFetchOp = albumTwoTypesFetchOps(['Videos/', 'Audios/'], 'Static', [VIDEO_TYPE, AUDIO_TYPE]) + let relativePaths = ['Videos/', 'Audios/']; + let albumCount = 2; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAndAudioAlbumInfofetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07'; + let currentFetchOp = albumThreeTypesFetchOps(['Pictures/', 'Videos/', 'Audios/'], 'Static', [IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE]) + let relativePaths = ['Pictures/', 'Videos/', 'Audios/']; + let albumCount = 3; + await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths, albumCount); + }); + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: FILEKEY.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06' + + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: '666' + '= ?', + selectionArgs: [VIDEO_TYPE.toString()], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07' + + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) { + let fileHasArgsfetchOp = { + selections: '666' + '= ?', + selectionArgs: ['666'], + }; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08' + await abnormalAlbumCount(done, testNum, fileHasArgsfetchOp) + }); + // ------------------------------ 002 test end ------------------------- + + // ------------------------------ 003 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01 + * @tc.name : commitModify + * @tc.desc : Modify Album name to 'hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) { + const testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01'; + try { + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro1', IMAGE_TYPE); + console.info(`${testNum}, currentFetchOp: ${JSON.stringify(currentFetchOp)}`) + + const albumList = await media.getAlbums(currentFetchOp); + const expectAlbumCount = 1; + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + const albumId = album.albumId; + console.info(`${testNum}, album.albumName(old): ${album.albumName}`) + const newName = 'albumName' + new Date().getTime(); + album.albumName = newName; + await album.commitModify(); + let currentfetchOp = idFetchOps(albumId) + const newAlbumList = await media.getAlbums(currentfetchOp); + console.info(`${testNum}, album.albumName(new): ${newAlbumList[0].albumName}`) + expect(newAlbumList[0].albumName).assertEqual(newName); + + album.albumName = 'DynamicPro1'; + await album.commitModify(); + done(); + } catch (error) { + console.info(`${testNum}, failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name '' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02'; + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro2', IMAGE_TYPE); + let newName = ''; + let expectAlbumCount = 1; + await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04 + * @tc.name : commitModify + * @tc.desc : Modify Album name 'i123456...119' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04'; + let currentFetchOp = albumFetchOps('Pictures/', 'DynamicPro2', IMAGE_TYPE); + let newName = ""; + for (var i = 0; i < 1200; i++) { + newName += i.toString(); + } + let expectAlbumCount = 1; + await abnormalAlbumCommitModify(done, testNum, currentFetchOp, newName, expectAlbumCount) + }); + // // ------------------------------ 003 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01 + * @tc.name : album.coverUri + * @tc.desc : check album.coverUri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01'; + try { + let coverUrifetchOp = { + selections: '', + selectionArgs: [], + order: 'date_added DESC LIMIT 0,1', + }; + let expectAlbumCount = 1; + let currentFetchOp = albumFetchOps('Pictures/', 'Static', IMAGE_TYPE); + const albumList = await media.getAlbums(currentFetchOp); + const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); + if (!albumCountPass) return; + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(coverUrifetchOp); + const asset = await fetchFileResult.getFirstObject(); + if (asset == undefined) { + console.info(`${testNum} failed asset undefined`) + + expect(false).assertTrue(); + done(); + return + } + expect(asset.uri).assertEqual(album.coverUri); + done(); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 004 test end ------------------------- + }); +} + + diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/module.json old mode 100644 new mode 100755 index 82fb1970953e8e320b149a3885c079feaf97b750..8e0400fc761d17bbb4800f146c44da034a4bb89e --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/module.json +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/module.json @@ -1,67 +1,67 @@ -{ - "module": { - "name": "phone", - "type": "entry", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:mainability_description", - "mainElement": "MainAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "uiSyntax": "ets", - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", - "description": "$string:mainability_description", - "icon": "$media:icon", - "label": "$string:entry_MainAbility", - "visible": true, - "orientation": "portrait", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_BUNDLE_INFO", - "reason": "use ohos.permission.GET_BUNDLE_INFO" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - }, - { - "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, - { - "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.MEDIA_LOCATION", - "reason":"use ohos.permission.MEDIA_LOCATION" - }, - { - "name": "ohos.permission.READ_MEDIA", - "reason":"use ohos.permission.READ_MEDIA" - }, - { - "name": "ohos.permission.WRITE_MEDIA", - "reason":"use ohos.permission.WRITE_MEDIA" - } - ] - } -} +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/element/string.json old mode 100644 new mode 100755 index d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b..32237ee203edf64926964fb238fa44e396ddf577 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/media/icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/profile/main_pages.json old mode 100644 new mode 100755 index 6898b31d2085f478ee1ed9d933a5910cbf901d92..96b478210df9884592229ae2db6f6bb7f86c14f4 --- a/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/profile/main_pages.json +++ b/multimedia/medialibrary/mediaLibrary_album/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ -{ - "src": [ - "pages/index/index", - "pages/second/second" - ] +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_album/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_album/signature/openharmony_sx.p7b old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_favorite/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_favorite/AppScope/app.json old mode 100644 new mode 100755 index 5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba..841282ae47b98590bdbc8aea744fbbcd178e9195 --- a/multimedia/medialibrary/mediaLibrary_favorite/AppScope/app.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/AppScope/app.json @@ -1,21 +1,21 @@ -{ - "app":{ - "bundleName":"ohos.acts.multimedia.mediaLibrary", - "vendor":"huawei", - "versionCode":1000000, - "versionName":"1.0.0", - "debug":false, - "icon":"$media:icon", - "label":"$string:entry_MainAbility", - "description":"$string:mainability_description", - "distributedNotificationEnabled":true, - "keepAlive":true, - "singleUser":true, - "minAPIVersion":8, - "targetAPIVersion":8, - "car":{ - "apiCompatibleVersion":8, - "singleUser":false - } - } -} +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/element/string.json old mode 100644 new mode 100755 index c1dee63527ae5e3c37f3736f6b68189e8df6f201..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- a/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_favorite/AppScope/resources/base/media/app_icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_favorite/BUILD.gn b/multimedia/medialibrary/mediaLibrary_favorite/BUILD.gn old mode 100644 new mode 100755 index 3f2892f47d40881386cc8fd4eb35727f4ee712bd..2944426bdd63a6481360e5afa8a0884980da59ff --- a/multimedia/medialibrary/mediaLibrary_favorite/BUILD.gn +++ b/multimedia/medialibrary/mediaLibrary_favorite/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//test/xts/tools/build/suite.gni") diff --git a/multimedia/medialibrary/mediaLibrary_favorite/Test.json b/multimedia/medialibrary/mediaLibrary_favorite/Test.json old mode 100644 new mode 100755 index 22c3a2724130b976a81bac00c859132345f2ff5f..a8abf3311b02c895ab40fe0845a553eac874c7c7 --- a/multimedia/medialibrary/mediaLibrary_favorite/Test.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/Test.json @@ -1,64 +1,62 @@ -{ - "description": "Configuration for mediaLibrary Tests", - "driver": { - "type": "JSUnitTest", - "test-timeout": "300000", - "package": "ohos.acts.multimedia.mediaLibrary", - "shell-timeout": "600000" - }, - "kits": [ - { - "type": "ShellKit", - "pre-push": [ - ], - "run-command": [ - "rm -rf /storage/media/100/local/files/*", - "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", - "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", - "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "PushKit", - "pre-push": [ - ], - "push": [ - "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "ShellKit", - "run-command": [ - "mkdir -pv /storage/media/100/local/files/Pictures/{StaticPro,StaticCb}", - "mkdir -pv /storage/media/100/local/files/Videos/{StaticPro,StaticCb}", - "mkdir -pv /storage/media/100/local/files/Audios/{StaticPro,StaticCb}", - "mkdir -pv /storage/media/100/local/files/Documents/{StaticPro,StaticCb}", - - "for d in {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;", - - "chmod -R 777 /storage/media/100/local/files/*", - "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", - "hilog -Q pidoff", - "hilog -p off", - "hilog -b D -D 0xD002B70", - "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "sleep 10", - "cem publish -e usual.event.SCREEN_OFF", - "sleep 10" - ] - }, - { - "test-file-name": [ - "ActsMediaLibraryFavorite.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{StaticPro,StaticCb}", + "mkdir -pv /storage/media/100/local/files/Videos/{StaticPro,StaticCb}", + "mkdir -pv /storage/media/100/local/files/Audios/{StaticPro,StaticCb}", + "mkdir -pv /storage/media/100/local/files/Documents/{StaticPro,StaticCb}", + + "for d in {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); 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 {StaticPro,StaticCb}; do for i in $$(seq 4); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFavorite.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/Application/AbilityStage.ts old mode 100644 new mode 100755 index 51cb02ba3f5c7011c1cd433d07deebd47a195704..14f230e140160dc5f94ecc462304621178f4cf64 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/Application/AbilityStage.ts +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/Application/AbilityStage.ts @@ -1,9 +1,9 @@ -import AbilityStage from "@ohos.application.AbilityStage" - -export default class MyAbilityStage extends AbilityStage { - onCreate() { - console.log("[Demo] MyAbilityStage onCreate") - globalThis.stageOnCreateRun = 1; - globalThis.stageContext = this.context; - } -} +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/MainAbility/MainAbility.ts old mode 100644 new mode 100755 index 2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,36 +1,36 @@ -import Ability from '@ohos.application.Ability' - -export default class MainAbility extends Ability { - onCreate(want,launchParam){ - // Ability is creating, initialize resources for this ability - console.log("[Demo] MainAbility onCreate") - globalThis.abilityWant = want; - } - - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("[Demo] MainAbility onDestroy") - } - - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("[Demo] MainAbility onWindowStageCreate") - globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) - } - - onWindowStageDestroy() { - //Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") - } - - onForeground() { - // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") - } - - onBackground() { - // Ability has back to background - console.log("[Demo] MainAbility onBackground") - } +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } }; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/index/index.ets old mode 100644 new mode 100755 index 553566f889603f823fe24557052baf1f26675a15..71bcb74b8a045a4e05dd64ed8209d3964c72a730 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/index/index.ets +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/index/index.ets @@ -1,69 +1,67 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import file from '@system.file'; - -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" -import testsuite from "../../test/List.test.ets" -import { getPermission } from "../../../../../../../common" - -@Entry -@Component -struct Index { - - aboutToAppear(){ - getPermission() - console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - const reportExtend = new ReportExtend(file) - - core.addService('report', reportExtend) - core.init() - core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - console.info('testsuite()---->') - testsuite(globalThis.abilityContext) - core.execute() - console.info('core.execute()---->') - } - - build() { - Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(25) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/second/second.ets old mode 100644 new mode 100755 index 1c1c727ff11ecc97909f482c35268db87ae23bb4..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/second/second.ets +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/pages/second/second.ets @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import router from '@system.router'; - -@Entry -@Component -struct Second { - private content: string = "Second Page" - - build() { - Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(`${this.content}`) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('back to index') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/List.test.ets old mode 100644 new mode 100755 index 17fea57c7a546fc45f3505c19abbe1db5d888d99..41be7d631bedb420b99c5fb4f393dd283dc03c51 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/List.test.ets @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import favoriteTestPromise from './favoriteTestPromise.test.ets' -import favoriteTestCallback from './favoriteTestCallback.test.ets' -export default function testsuite(abilityContext) { - favoriteTestPromise(abilityContext) - favoriteTestCallback(abilityContext) -} +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import favoriteTestPromise from './favoriteTestPromise.test.ets' +import favoriteTestCallback from './favoriteTestCallback.test.ets' +export default function testsuite(abilityContext) { + favoriteTestCallback(abilityContext) + favoriteTestPromise(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestCallback.test.ets old mode 100644 new mode 100755 index d6df05261cd25d671ccfad9d1a2ce43c0bb0b87a..5facd448f166aa6368d102be49ca3d0fc4661911 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestCallback.test.ets +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestCallback.test.ets @@ -1,286 +1,288 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILE_TYPE, - checkPresetsAssets, - nameFetchOps, - checkAssetsCount, -} from '../../../../../../common'; - -export default function favoriteTestCallbackTest(abilityContext) { - describe('favoriteTestCallbackTest', function () { - var media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryFavorite'); - }); - beforeEach(function () { }); - afterEach(async function () { - sleep() - }); - afterAll(function () { }); - - const favoriteDefaultState = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - let fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - let asset = await fetchFileResult.getFirstObject(); - asset.isFavorite(async (err, isFavorite) => { - if (err) { - expect(false).assertTrue(); - await fetchFileResult.close(); - done(); - return; - } - expect(isFavorite).assertEqual(false); - await fetchFileResult.close(); - done() - }); - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - const favoriteByTrue = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - const fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - const asset = await fetchFileResult.getFirstObject(); - asset.favorite(true, async (err) => { - if(err) { - console.info(`${testNum} failed err: ${err}`) - expect(false).assertTrue(); - done(); - return; - } - let isFavorite = await asset.isFavorite(); - expect(isFavorite).assertEqual(true); - await fetchFileResult.close(); - done(); - }); - - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - const favoriteByFalse = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - const fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - const asset = await fetchFileResult.getFirstObject(); - await asset.favorite(true); - asset.favorite(false, async (err) => { - if(err) { - console.info(`${testNum} failed err: ${err}`) - expect(false).assertTrue(); - done(); - return; - } - let isFavorite = await asset.isFavorite(); - expect(isFavorite).assertEqual(false); - await fetchFileResult.close(); - done(); - }); - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(image) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01' - let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '01', IMAGE_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02 - * @tc.name : favorite - * @tc.desc : favorite(image) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02' - let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '02', IMAGE_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03 - * @tc.name : favorite - * @tc.desc : favorite(image) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03' - let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '03', IMAGE_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(video) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01' - let currentFetchOp = nameFetchOps('Videos/StaticCb/', '01', VIDEO_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02 - * @tc.name : favorite - * @tc.desc : favorite(video) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02' - let currentFetchOp = nameFetchOps('Videos/StaticCb/', '02', VIDEO_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03 - * @tc.name : favorite - * @tc.desc : favorite(video) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03' - let currentFetchOp = nameFetchOps('Videos/StaticCb/', '03', VIDEO_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(audio) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01' - let currentFetchOp = nameFetchOps('Audios/StaticCb/', '01', AUDIO_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02 - * @tc.name : favorite - * @tc.desc : favorite(audio) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02' - let currentFetchOp = nameFetchOps('Audios/StaticCb/', '02', AUDIO_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03 - * @tc.name : favorite - * @tc.desc : favorite(audio) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03' - let currentFetchOp = nameFetchOps('Audios/StaticCb/', '03', AUDIO_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(file) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01' - let currentFetchOp = nameFetchOps('Documents/StaticCb/', '01', FILE_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02 - * @tc.name : favorite - * @tc.desc : favorite(file) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02' - let currentFetchOp = nameFetchOps('Documents/StaticCb/', '02', FILE_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03 - * @tc.name : favorite - * @tc.desc : favorite(file) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03' - let currentFetchOp = nameFetchOps('Documents/StaticCb/', '03', FILE_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - }); -} +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + checkPresetsAssets, + nameFetchOps, + checkAssetsCount, + getPermission, +} from '../../../../../../common'; + +export default function favoriteTestCallbackTest(abilityContext) { + describe('favoriteTestCallbackTest', function () { + var media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFavorite'); + }); + beforeEach(function () { }); + afterEach(async function () { + sleep() + }); + afterAll(function () { }); + + const favoriteDefaultState = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + asset.isFavorite(async (err, isFavorite) => { + if (err) { + expect(false).assertTrue(); + await fetchFileResult.close(); + done(); + return; + } + expect(isFavorite).assertEqual(false); + await fetchFileResult.close(); + done() + }); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + const favoriteByTrue = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + asset.favorite(true, async (err) => { + if(err) { + console.info(`${testNum} failed err: ${err}`) + expect(false).assertTrue(); + done(); + return; + } + let isFavorite = await asset.isFavorite(); + expect(isFavorite).assertEqual(true); + await fetchFileResult.close(); + done(); + }); + + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + const favoriteByFalse = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + await asset.favorite(true); + asset.favorite(false, async (err) => { + if(err) { + console.info(`${testNum} failed err: ${err}`) + expect(false).assertTrue(); + done(); + return; + } + let isFavorite = await asset.isFavorite(); + expect(isFavorite).assertEqual(false); + await fetchFileResult.close(); + done(); + }); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(image) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01' + let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '01', IMAGE_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02 + * @tc.name : favorite + * @tc.desc : favorite(image) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02' + let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '02', IMAGE_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03 + * @tc.name : favorite + * @tc.desc : favorite(image) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03' + let currentFetchOp = nameFetchOps('Pictures/StaticCb/', '03', IMAGE_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(video) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01' + let currentFetchOp = nameFetchOps('Videos/StaticCb/', '01', VIDEO_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02 + * @tc.name : favorite + * @tc.desc : favorite(video) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02' + let currentFetchOp = nameFetchOps('Videos/StaticCb/', '02', VIDEO_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03 + * @tc.name : favorite + * @tc.desc : favorite(video) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03' + let currentFetchOp = nameFetchOps('Videos/StaticCb/', '03', VIDEO_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(audio) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01' + let currentFetchOp = nameFetchOps('Audios/StaticCb/', '01', AUDIO_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02 + * @tc.name : favorite + * @tc.desc : favorite(audio) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02' + let currentFetchOp = nameFetchOps('Audios/StaticCb/', '02', AUDIO_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03 + * @tc.name : favorite + * @tc.desc : favorite(audio) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03' + let currentFetchOp = nameFetchOps('Audios/StaticCb/', '03', AUDIO_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(file) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01' + let currentFetchOp = nameFetchOps('Documents/StaticCb/', '01', FILE_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02 + * @tc.name : favorite + * @tc.desc : favorite(file) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02' + let currentFetchOp = nameFetchOps('Documents/StaticCb/', '02', FILE_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03 + * @tc.name : favorite + * @tc.desc : favorite(file) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03' + let currentFetchOp = nameFetchOps('Documents/StaticCb/', '03', FILE_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + }); +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestPromise.test.ets old mode 100644 new mode 100755 index 5c251ecb1117ed674dd92e4ec6d3ce45c81a1ba6..8046631553e8d02cdc79010bd83d4227fbbce87b --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/ets/test/favoriteTestPromise.test.ets @@ -1,264 +1,264 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILE_TYPE, - checkPresetsAssets, - nameFetchOps, - checkAssetsCount, -} from '../../../../../../common'; - -export default function favoriteTestPromiseTest(abilityContext) { - describe('favoriteTestPromiseTest', function () { - var media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryFavorite'); - }); - beforeEach(function () { }); - afterEach(async function () { - sleep() - }); - afterAll(function () { }); - - const favoriteDefaultState = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - let fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - let asset = await fetchFileResult.getFirstObject(); - let isFavorite = await asset.isFavorite(); - expect(isFavorite).assertEqual(false); - await fetchFileResult.close(); - done() - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - const favoriteByTrue = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - const fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - const asset = await fetchFileResult.getFirstObject(); - await asset.favorite(true); - let isFavorite = await asset.isFavorite(); - expect(isFavorite).assertEqual(true); - await fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - const favoriteByFalse = async function (done, testNum, fetchOp) { - console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) - try { - const fetchFileResult = await media.getFileAssets(fetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); - if (!checkAssetCountPass) return; - const asset = await fetchFileResult.getFirstObject(); - await asset.favorite(true); - await asset.favorite(false); - let isFavorite = await asset.isFavorite(); - expect(isFavorite).assertEqual(false); - await fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} failed error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(image) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01' - let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '01', IMAGE_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02 - * @tc.name : favorite - * @tc.desc : favorite(image) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02' - let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '02', IMAGE_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03 - * @tc.name : favorite - * @tc.desc : favorite(image) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03' - let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '03', IMAGE_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(video) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01' - let currentFetchOp = nameFetchOps('Videos/StaticPro/', '01', VIDEO_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02 - * @tc.name : favorite - * @tc.desc : favorite(video) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02' - let currentFetchOp = nameFetchOps('Videos/StaticPro/', '02', VIDEO_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03 - * @tc.name : favorite - * @tc.desc : favorite(video) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03' - let currentFetchOp = nameFetchOps('Videos/StaticPro/', '03', VIDEO_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(audio) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01' - let currentFetchOp = nameFetchOps('Audios/StaticPro/', '01', AUDIO_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02 - * @tc.name : favorite - * @tc.desc : favorite(audio) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02' - let currentFetchOp = nameFetchOps('Audios/StaticPro/', '02', AUDIO_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03 - * @tc.name : favorite - * @tc.desc : favorite(audio) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03' - let currentFetchOp = nameFetchOps('Audios/StaticPro/', '03', AUDIO_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01 - * @tc.name : isFavorite - * @tc.desc : isFavorite(file) result false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01' - let currentFetchOp = nameFetchOps('Documents/StaticPro/', '01', FILE_TYPE) - await favoriteDefaultState(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02 - * @tc.name : favorite - * @tc.desc : favorite(file) by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02' - let currentFetchOp = nameFetchOps('Documents/StaticPro/', '02', FILE_TYPE) - await favoriteByTrue(done, testNum, currentFetchOp) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03 - * @tc.name : favorite - * @tc.desc : favorite(file) by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03' - let currentFetchOp = nameFetchOps('Documents/StaticPro/', '03', FILE_TYPE) - await favoriteByFalse(done, testNum, currentFetchOp) - }); - }); -} +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + checkPresetsAssets, + nameFetchOps, + checkAssetsCount, +} from '../../../../../../common'; + +export default function favoriteTestPromiseTest(abilityContext) { + describe('favoriteTestPromiseTest', function () { + var media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryFavorite'); + }); + beforeEach(function () { }); + afterEach(async function () { + sleep() + }); + afterAll(function () { }); + + const favoriteDefaultState = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + let isFavorite = await asset.isFavorite(); + expect(isFavorite).assertEqual(false); + await fetchFileResult.close(); + done() + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + const favoriteByTrue = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + expect(isFavorite).assertEqual(true); + await fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + const favoriteByFalse = async function (done, testNum, fetchOp) { + console.info(`${testNum} fetchOp ${JSON.stringify(fetchOp)}`) + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + await asset.favorite(true); + await asset.favorite(false); + let isFavorite = await asset.isFavorite(); + expect(isFavorite).assertEqual(false); + await fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(image) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01' + let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '01', IMAGE_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02 + * @tc.name : favorite + * @tc.desc : favorite(image) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02' + let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '02', IMAGE_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03 + * @tc.name : favorite + * @tc.desc : favorite(image) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03' + let currentFetchOp = nameFetchOps('Pictures/StaticPro/', '03', IMAGE_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(video) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01' + let currentFetchOp = nameFetchOps('Videos/StaticPro/', '01', VIDEO_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02 + * @tc.name : favorite + * @tc.desc : favorite(video) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02' + let currentFetchOp = nameFetchOps('Videos/StaticPro/', '02', VIDEO_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03 + * @tc.name : favorite + * @tc.desc : favorite(video) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03' + let currentFetchOp = nameFetchOps('Videos/StaticPro/', '03', VIDEO_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(audio) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01' + let currentFetchOp = nameFetchOps('Audios/StaticPro/', '01', AUDIO_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02 + * @tc.name : favorite + * @tc.desc : favorite(audio) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02' + let currentFetchOp = nameFetchOps('Audios/StaticPro/', '02', AUDIO_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03 + * @tc.name : favorite + * @tc.desc : favorite(audio) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03' + let currentFetchOp = nameFetchOps('Audios/StaticPro/', '03', AUDIO_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01 + * @tc.name : isFavorite + * @tc.desc : isFavorite(file) result false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01' + let currentFetchOp = nameFetchOps('Documents/StaticPro/', '01', FILE_TYPE) + await favoriteDefaultState(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02 + * @tc.name : favorite + * @tc.desc : favorite(file) by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02' + let currentFetchOp = nameFetchOps('Documents/StaticPro/', '02', FILE_TYPE) + await favoriteByTrue(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03 + * @tc.name : favorite + * @tc.desc : favorite(file) by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03' + let currentFetchOp = nameFetchOps('Documents/StaticPro/', '03', FILE_TYPE) + await favoriteByFalse(done, testNum, currentFetchOp) + }); + }); +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/module.json old mode 100644 new mode 100755 index 82fb1970953e8e320b149a3885c079feaf97b750..8e0400fc761d17bbb4800f146c44da034a4bb89e --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/module.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/module.json @@ -1,67 +1,67 @@ -{ - "module": { - "name": "phone", - "type": "entry", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:mainability_description", - "mainElement": "MainAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "uiSyntax": "ets", - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", - "description": "$string:mainability_description", - "icon": "$media:icon", - "label": "$string:entry_MainAbility", - "visible": true, - "orientation": "portrait", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_BUNDLE_INFO", - "reason": "use ohos.permission.GET_BUNDLE_INFO" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - }, - { - "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, - { - "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.MEDIA_LOCATION", - "reason":"use ohos.permission.MEDIA_LOCATION" - }, - { - "name": "ohos.permission.READ_MEDIA", - "reason":"use ohos.permission.READ_MEDIA" - }, - { - "name": "ohos.permission.WRITE_MEDIA", - "reason":"use ohos.permission.WRITE_MEDIA" - } - ] - } -} +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/element/string.json old mode 100644 new mode 100755 index d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b..32237ee203edf64926964fb238fa44e396ddf577 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/media/icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/profile/main_pages.json old mode 100644 new mode 100755 index 6898b31d2085f478ee1ed9d933a5910cbf901d92..96b478210df9884592229ae2db6f6bb7f86c14f4 --- a/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/profile/main_pages.json +++ b/multimedia/medialibrary/mediaLibrary_favorite/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ -{ - "src": [ - "pages/index/index", - "pages/second/second" - ] +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_favorite/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_favorite/signature/openharmony_sx.p7b old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_file/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_file/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..841282ae47b98590bdbc8aea744fbbcd178e9195 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_file/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_file/BUILD.gn b/multimedia/medialibrary/mediaLibrary_file/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..673c4d86cc4dc2f3106184703c6975f4ece7f45f --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("mediaLibrary_file_hap") { + hap_profile = "entry/src/main/module.json" + deps = [ + ":mediaLibrary_js_assets", + ":mediaLibrary_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsMediaLibraryFile" +} + +ohos_app_scope("medialibrary_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("mediaLibrary_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("mediaLibrary_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":medialibrary_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/medialibrary/mediaLibrary_file/Test.json b/multimedia/medialibrary/mediaLibrary_file/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..a7a92e54869dcee112dbd17f155567eaab859553 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/Test.json @@ -0,0 +1,67 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,Dynamic}", + "mkdir -pv /storage/media/100/local/files/Videos/{Static,Dynamic}", + "mkdir -pv /storage/media/100/local/files/Audios/{Static,Dynamic}", + "mkdir -pv /storage/media/100/local/files/Documents/{Static,Dynamic}", + + "for d in Static; do for i in $$(seq 6); 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 6); 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 6); 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 6); 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;", + + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/Dynamic/01.jpg", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/Dynamic/01.mp4", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/Dynamic/01.mp3", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/Dynamic/01.dat", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFile.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..14f230e140160dc5f94ecc462304621178f4cf64 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..71bcb74b8a045a4e05dd64ed8209d3964c72a730 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b4c43a249e63bf4649afa2f1233d8f83319f6d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 fileTestPromise from './fileTestPromise.test.ets' +export default function testsuite(abilityContext) { + fileTestPromise(abilityContext) +} 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 new file mode 100755 index 0000000000000000000000000000000000000000..d785d03012adf8ef20edbac2b22364bcca72d2e2 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/ets/test/fileTestPromise.test.ets @@ -0,0 +1,547 @@ +/* + * 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 fileTestPromiseTest(abilityContext) { + describe('fileTestPromiseTest', 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}`; + + const creatAsset1 = await media.createAsset(type, displayName1, path); + + 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}`; + + const creatAsset = await media.createAsset(type, displayName, path); + + 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()}`; + await asset.commitModify(); + + 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_PROMISE_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_PROMISE_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_07'; + let currentFetchOp = fetchOps('Pictures/Dynamic/', IMAGE_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_001_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_001_11', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_002_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_07'; + let currentFetchOp = fetchOps('Videos/Dynamic/', VIDEO_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_002_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_002_11', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_003_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_07'; + let currentFetchOp = fetchOps('Audios/Dynamic/', AUDIO_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_003_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_004_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_004_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_004_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE_004_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_07'; + let currentFetchOp = fetchOps('Documents/Dynamic/', FILE_TYPE) + await checkdateModified(done, testNum, currentFetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_004_08', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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/module.json b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..8e0400fc761d17bbb4800f146c44da034a4bb89e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..32237ee203edf64926964fb238fa44e396ddf577 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..96b478210df9884592229ae2db6f6bb7f86c14f4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_file/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_file/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_file/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_file/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAsset/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/BUILD.gn b/multimedia/medialibrary/mediaLibrary_fileAsset/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..f6dc879da57ce5a546bfc34968e07614c353f0a7 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("mediaLibrary_fileAsset_hap") { + hap_profile = "entry/src/main/module.json" + deps = [ + ":mediaLibrary_js_assets", + ":mediaLibrary_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsMediaLibraryFileAsset" +} + +ohos_app_scope("medialibrary_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("mediaLibrary_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("mediaLibrary_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":medialibrary_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json b/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..d9a4cbcacaaf8356689b33c75fbd185786545c6b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/Test.json @@ -0,0 +1,67 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,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}", + + "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 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;", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFileAsset.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..624cad290665fcd29dcd579d9582a300479e8ad7 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..48836999f225b5d1fbae1184c9d82bec76a75701 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fileAssetPromise2 from './fileAssetPromise2.test.ets' +import fileAssetTestPromise from './fileAssetTestPromise.test.ets' +export default function testsuite(abilityContext) { + fileAssetPromise2(abilityContext) + fileAssetTestPromise(abilityContext) +} 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 new file mode 100755 index 0000000000000000000000000000000000000000..573df12a850806c8298884a3cbff7d43cca93ba8 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetPromise2.test.ets @@ -0,0 +1,164 @@ +/* + * 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, + AUDIO_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + getPermission, + fetchOps, + nameFetchOps, +} from '../../../../../../common'; + +export default function fileAssetPromise2Test(abilityContext) { + describe('fileAssetPromise2Test', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFileKey') + }); + 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(); + 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_promise_001 + * @tc.name : commitModify + * @tc.desc : Modify displayName + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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 prop = 'displayName' + let val = new Date().getTime() + '.jpg' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002 + * @tc.name : commitModify + * @tc.desc : Modify title + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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 prop = 'title' + let val = new Date().getTime() + 'newTitle' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003 + * @tc.name : commitModify + * @tc.desc : Modify relativePath + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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 prop = 'relativePath' + let val = 'Pictures/Temp/' + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004 + * @tc.name : commitModify + * @tc.desc : Modify orientation + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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 prop = 'orientation' + let val = 1 + await checkCommitModify(done, testNum, fetchOp, prop, val) + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001 + * @tc.name : isDirectory + * @tc.desc : isDirectory asset + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { + try { + let fetchOp = nameFetchOps('Pictures/Static/', '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/fileAssetTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..c56246c6fb9cfc5104bdd64fe5fb18f27655571d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets @@ -0,0 +1,478 @@ +/* + * 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, + + 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') + }); + 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]; + fd = await asset.open('rw'); + expect(isNum(fd)).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead).assertEqual(assetProps.bytesRead); + asset1 = 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]; + fd = await asset.open('r'); + expect(isNum(fd)).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + console.log(' bytesRead: ' + res.bytesRead) + expect(res.bytesRead).assertEqual(assetProps.bytesRead); + try { + await fileio.write(fd, buf); + expect.assertFail(); + } catch (error) { + expect(true).assertTrue(); + await asset.close(fd); + done(); + } + } catch (error) { + console.info(`${testNum} :: error: ${error}`); + expect.assertFail(); + await asset.close(fd); + done(); + } + } + + const wOpenTest = async function (done, testNum, 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]; + + fd = await asset.open('w'); + expect(isNum(fd)).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + console.info(`${testNum} :: write: ${write}`); + expect(write).assertEqual(assetProps.write); + let buf1 = new ArrayBuffer(4096); + try { + await fileio.read(fd, buf1); + expect.assertFail(); + + } catch (error) { + expect(true).assertTrue(); + + } + done(); + } catch (error) { + console.info(`${testNum} :: error: ${error}`); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + } + + const 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(); + await asset.close(fd); + let count = 0 + let buf = new ArrayBuffer(4096); + try { + await fileio.read(fd, buf); + } catch (error) { + count++ + } + try { + await fileio.write(fd, buf); + } catch (error) { + count++ + } + await sleep(1000) + expect(count).assertEqual(2); + done(); + } catch (error) { + console.info(`${testNum} error:${error}`) + await asset.close(fd); + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_01', 0, async function (done) { + let assetProps = { + bytesRead: 10, + write: 4096, + } + let fetchOp = fetchOps('Documents/RW/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_02', 0, async function (done) { + let assetProps = { + bytesRead: 10, + write: 4096, + } + let fetchOp = fetchOps('Documents/R/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_03', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Documents/W/', FILE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + // //======================== FILE END ================================== + + //======================== IMAGE BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_07', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Pictures/RW/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_08', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Pictures/R/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_09', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Pictures/W/', IMAGE_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== IMAGE END ================================== + + //======================== AUDIO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_10', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Audios/RW/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_11', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Audios/R/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_12', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Audios/W/', AUDIO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== AUDIO END ================================== + + //======================== VIDEO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_13', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + write: 4096, + } + let fetchOp = fetchOps('Videos/RW/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13'; + await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_14', 0, async function (done) { + let assetProps = { + bytesRead: 4096, + } + let fetchOp = fetchOps('Videos/R/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14'; + await rOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_15', 0, async function (done) { + let assetProps = { + write: 4096, + } + let fetchOp = fetchOps('Videos/W/', VIDEO_TYPE); + let expectCount = 2; + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15'; + await wOpenTest(done, testNum, fetchOp, assetProps, expectCount) + }); + + //======================== VIDEO END ================================== + + //======================== CLOSE BEGIN ================================ + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_31', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31' + let fetchOp = fetchOps('Documents/openClose/', FILE_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_33', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33' + let fetchOp = fetchOps('Pictures/openClose/', IMAGE_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_34', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34' + let fetchOp = fetchOps('Audios/openClose/', AUDIO_TYPE); + await closeTest(done, testNum, fetchOp) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_35', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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/module.json b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..82fb1970953e8e320b149a3885c079feaf97b750 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_fileAsset/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAsset/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAssetUri/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/BUILD.gn b/multimedia/medialibrary/mediaLibrary_fileAssetUri/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e017a925cbab364a6d97aca5b7d2dc1e84a64b26 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("mediaLibrary_fileAssetUri_hap") { + hap_profile = "entry/src/main/module.json" + deps = [ + ":mediaLibrary_js_assets", + ":mediaLibrary_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsMediaLibraryFileAssetUri" +} + +ohos_app_scope("medialibrary_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("mediaLibrary_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("mediaLibrary_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":medialibrary_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/Test.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..c08ed7fe1d8f9644e7bae44c5e033545cdac5351 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/Test.json @@ -0,0 +1,62 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/Static", + "mkdir -pv /storage/media/100/local/files/Videos/Static", + "mkdir -pv /storage/media/100/local/files/Audios/Static", + "mkdir -pv /storage/media/100/local/files/Documents/Static", + + "for d in Static; 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 Static; 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 Static; 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 Static; 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;", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFileAssetUri.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..e45e49a3b7b1f7478c19dfae76022aff91a6896e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f19284ea62d20aa6024e9528cf189f12f2e02550 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fileAssetUriTestPromise from './fileAssetUriTestPromise.test.ets' +import fileAssetUriTestCallback from './fileAssetUriTestCallback.test.ets' +export default function testsuite(abilityContext) { + fileAssetUriTestCallback(abilityContext) + fileAssetUriTestPromise(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..9c2bbcd2f6bef200659179a7cfdd2f9bbf99b7eb --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestCallback.test.ets @@ -0,0 +1,150 @@ +/* + * 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, + AUDIO_TYPE, + VIDEO_TYPE, + FILE_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; + +export default function filekeyTestCallbackTest(abilityContext) { + describe('filekeyTestCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFileAssetUri'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + const serachUri = async (done, testNum, fetchOp, type) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 2); + if (!checkAssetCountPass) return; + let firstObject = await fetchFileResult.getFirstObject(); + const id = firstObject.id; + const uri = firstObject.uri; + const serachUri = `datashare:///media/${type}/${id}`; + console.info(`${testNum} :uri ${uri};serachUri${serachUri})`) + + let serchfetchOp = { + uri: serachUri.toString(), + selections: '', + selectionArgs: [], + }; + + media.getFileAssets(serchfetchOp, async (err, result) => { + if (err) { + console.info(`${testNum}, err: ${err}`) + expect(false).assertTrue(); + done(); + return; + } + checkAssetCountPass = await checkAssetsCount(done, testNum, result, 1); + if (!checkAssetCountPass) return; + let asset = await result.getFirstObject(); + expect(asset.uri).assertEqual(serachUri); + expect(asset.id).assertEqual(id); + done(); + }); + + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001 + * @tc.name : uri + * @tc.desc : serach image asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001'; + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = 'image'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002 + * @tc.name : uri + * @tc.desc : serach audio asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002'; + let currentFetchOp = fetchOps('Audios/Static/', AUDIO_TYPE); + let type = 'audio'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003 + * @tc.name : uri + * @tc.desc : serach video asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003'; + let currentFetchOp = fetchOps('Videos/Static/', VIDEO_TYPE); + let type = 'video'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004 + * @tc.name : uri + * @tc.desc : serach file asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004'; + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE); + let type = 'file'; + await serachUri(done, testNum, currentFetchOp, type); + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..c8d6b1fe35b0da21823a930ea9be8799e78941ee --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets @@ -0,0 +1,143 @@ +/* + * 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, + AUDIO_TYPE, + VIDEO_TYPE, + FILE_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; + +export default function filekeyTestPromiseTest(abilityContext) { + describe('filekeyTestPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await checkPresetsAssets(media, 'ActsMediaLibraryFileAssetUri'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + + const serachUri = async (done, testNum, fetchOp, type) => { + try { + const fetchFileResult = await media.getFileAssets(fetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 2); + if (!checkAssetCountPass) return; + let firstObject = await fetchFileResult.getFirstObject(); + const id = firstObject.id; + const uri = firstObject.uri; + const serachUri = `datashare:///media/${type}/${id}`; + console.info(`${testNum} :uri ${uri};serachUri${serachUri})`) + + let serchfetchOp = { + uri: serachUri.toString(), + selections: '', + selectionArgs: [], + }; + + const result = await media.getFileAssets(serchfetchOp); + checkAssetCountPass = await checkAssetsCount(done, testNum, result, 1); + if (!checkAssetCountPass) return; + + let asset = await result.getFirstObject(); + expect(asset.uri).assertEqual(serachUri); + expect(asset.id).assertEqual(id); + done(); + } catch (error) { + console.info(`${testNum} failed error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001 + * @tc.name : uri + * @tc.desc : serach image asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001'; + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE); + let type = 'image'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002 + * @tc.name : uri + * @tc.desc : serach audio asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002'; + let currentFetchOp = fetchOps('Audios/Static/', AUDIO_TYPE); + let type = 'audio'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003 + * @tc.name : uri + * @tc.desc : serach video asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003'; + let currentFetchOp = fetchOps('Videos/Static/', VIDEO_TYPE); + let type = 'video'; + await serachUri(done, testNum, currentFetchOp, type); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004 + * @tc.name : uri + * @tc.desc : serach file asset by uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004'; + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE); + let type = 'file'; + await serachUri(done, testNum, currentFetchOp, type); + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..82fb1970953e8e320b149a3885c079feaf97b750 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileAssetUri/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileAssetUri/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_fileAssetUri/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileAssetUri/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileKey/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/BUILD.gn b/multimedia/medialibrary/mediaLibrary_fileKey/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..56278642724fb5bde61d615addec6b49ad996ec2 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("mediaLibrary_fileKey_hap") { + hap_profile = "entry/src/main/module.json" + deps = [ + ":mediaLibrary_js_assets", + ":mediaLibrary_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsMediaLibraryFileKey" +} + +ohos_app_scope("medialibrary_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("mediaLibrary_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("mediaLibrary_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":medialibrary_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/Test.json b/multimedia/medialibrary/mediaLibrary_fileKey/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..2587f380983c8901a14cf4940339dcbb86feeb90 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/Test.json @@ -0,0 +1,58 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/ImageInfo", + "mkdir -pv /storage/media/100/local/files/Audios/Static", + + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/ImageInfo/01.jpg", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/Static/01.mp3", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFileKey.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..e45e49a3b7b1f7478c19dfae76022aff91a6896e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..289252e25631403992c31901df7a0211be99381f --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import filekeyTestCallback from './filekeyTestCallback.test.ets' +import filekeyTestPromise from './filekeyTestPromise.test.ets' +export default function testsuite(abilityContext) { + filekeyTestCallback(abilityContext) + filekeyTestPromise(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..50271bf065d3ebdde3bcc0ccb89e688a8da1953a --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestCallback.test.ets @@ -0,0 +1,310 @@ +/* + * 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, + AUDIO_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; + +const filekeys = { + parent: 'PARENT', + mimeType: 'MIME_TYPE', + size: 'SIZE', + dateAdded: 'DATE_ADDED', + title: 'TITLE', + duration: 'DURATION', + width: 'WIDTH', + height: 'HEIGHT', + orientation: 'ORIENTATION', + albumId: 'ALBUM_ID', + artist: 'ARTIST', + audioAlbum: 'AUDIOALBUM', + dateModified: 'DATE_MODIFIED', + dateTaken: 'DATE_TAKEN', + relativePath: 'RELATIVE_PATH', + displayName: 'DISPLAY_NAME', +} + +export default function filekeyTestCallbackTest(abilityContext) { + describe('filekeyTestCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryFileKey') + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + async function getFileAssetsBy(done, testNum, type, count = 1) { + try { + let assetOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE); + if (type == 'audioAlbum' || type == 'artist' || type == 'duration') { + assetOp = fetchOps('Audios/Static/', AUDIO_TYPE); + } + console.info(`${testNum} assOp : ${JSON.stringify(assetOp)}`) + let fetchFileResult = await media.getFileAssets(assetOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + let Op = { + selections: FILEKEY[filekeys[type]] + '= ?', + selectionArgs: [asset[type] + ''], + }; + media.getFileAssets(Op, async (err, fetchFileResult) => { + if(err) { + console.info(`${testNum}, err: ${err}`) + expect(false).assertTrue(); + done(); + return; + } + const fetchCount = fetchFileResult.getCount(); + const currentAsset = await fetchFileResult.getFirstObject(); + expect(currentAsset[type]).assertEqual(asset[type]); + expect(fetchCount>0).assertTrue(); + done(); + }); + } catch (error) { + console.info(`${testNum} error : ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_001 + * @tc.name : getFileAssets + * @tc.desc : filekey parentOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_001', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_001' + await getFileAssetsBy(done, testNum, 'parent'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_002 + * @tc.name : getFileAssets + * @tc.desc : filekey mimeTypeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_002' + await getFileAssetsBy(done, testNum, 'mimeType'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_003 + * @tc.name : getFileAssets + * @tc.desc : filekey sizeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_003' + await getFileAssetsBy(done, testNum, 'size'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_004 + * @tc.name : getFileAssets + * @tc.desc : filekey dateAddedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_004' + await getFileAssetsBy(done, testNum, 'dateAdded', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_005 + * @tc.name : getFileAssets + * @tc.desc : filekey dateModifiedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_005' + await getFileAssetsBy(done, testNum, 'dateModified', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_006 + * @tc.name : getFileAssets + * @tc.desc : filekey dateTakenOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_006', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_006' + await getFileAssetsBy(done, testNum, 'dateTaken', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_007 + * @tc.name : getFileAssets + * @tc.desc : filekey titleOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_007', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_007' + await getFileAssetsBy(done, testNum, 'title', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_008 + * @tc.name : getFileAssets + * @tc.desc : filekey durationOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_008', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_008' + await getFileAssetsBy(done, testNum, 'duration'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_009 + * @tc.name : getFileAssets + * @tc.desc : filekey widthOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_009', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_009' + await getFileAssetsBy(done, testNum, 'width'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_010 + * @tc.name : getFileAssets + * @tc.desc : filekey heightOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_010', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_010' + await getFileAssetsBy(done, testNum, 'height'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_011 + * @tc.name : getFileAssets + * @tc.desc : filekey orientationOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_011', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_011' + await getFileAssetsBy(done, testNum, 'orientation', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_012 + * @tc.name : getFileAssets + * @tc.desc : filekey widthOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_012', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_012' + await getFileAssetsBy(done, testNum, 'albumId'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0014 + * @tc.name : getFileAssets + * @tc.desc : filekey artistOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0014', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_014' + await getFileAssetsBy(done, testNum, 'artist'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0015 + * @tc.name : getFileAssets + * @tc.desc : filekey audioAlbumOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0015', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_015' + await getFileAssetsBy(done, testNum, 'audioAlbum'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0016 + * @tc.name : getFileAssets + * @tc.desc : filekey relative_path + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0016', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0016' + await getFileAssetsBy(done, testNum, 'relativePath'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0017 + * @tc.name : getFileAssets + * @tc.desc : filekey display_name + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0017', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_CALLBACK_0017' + await getFileAssetsBy(done, testNum, 'displayName'); + + }); + + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7a069b704e4aeca7dedb6622ea9db59a2b09051e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/ets/test/filekeyTestPromise.test.ets @@ -0,0 +1,302 @@ +/* + * 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, + AUDIO_TYPE, + + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, +} from '../../../../../../common'; + +const filekeys = { + parent: 'PARENT', + mimeType: 'MIME_TYPE', + size: 'SIZE', + dateAdded: 'DATE_ADDED', + title: 'TITLE', + duration: 'DURATION', + width: 'WIDTH', + height: 'HEIGHT', + orientation: 'ORIENTATION', + albumId: 'ALBUM_ID', + artist: 'ARTIST', + audioAlbum: 'AUDIOALBUM', + dateModified: 'DATE_MODIFIED', + dateTaken: 'DATE_TAKEN', + relativePath: 'RELATIVE_PATH', + displayName: 'DISPLAY_NAME', +} + +export default function filekeyTestPromiseTest(abilityContext) { + describe('filekeyTestPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryFileKey') + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + async function getFileAssetsBy(done, testNum, type, count = 1) { + try { + let assetOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE); + if (type == 'audioAlbum' || type == 'artist' || type == 'duration') { + assetOp = fetchOps('Audios/Static/', AUDIO_TYPE); + } + console.info(`${testNum} assOp : ${JSON.stringify(assetOp)}`) + let fetchFileResult = await media.getFileAssets(assetOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + const asset = await fetchFileResult.getFirstObject(); + let Op = { + selections: FILEKEY[filekeys[type]] + '= ?', + selectionArgs: [asset[type] + ''], + }; + fetchFileResult = await media.getFileAssets(Op); + const fetchCount = fetchFileResult.getCount(); + expect(fetchCount>0).assertTrue(); + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject[type]).assertEqual(asset[type]); + done(); + } catch (error) { + console.info(`${testNum} error : ${error}`) + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_001 + * @tc.name : getFileAssets + * @tc.desc : filekey parentOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_001', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_001' + await getFileAssetsBy(done, testNum, 'parent'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_002 + * @tc.name : getFileAssets + * @tc.desc : filekey mimeTypeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_002' + await getFileAssetsBy(done, testNum, 'mimeType'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_003 + * @tc.name : getFileAssets + * @tc.desc : filekey sizeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_003' + await getFileAssetsBy(done, testNum, 'size'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_004 + * @tc.name : getFileAssets + * @tc.desc : filekey dateAddedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_004' + await getFileAssetsBy(done, testNum, 'dateAdded', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_005 + * @tc.name : getFileAssets + * @tc.desc : filekey dateModifiedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_005' + await getFileAssetsBy(done, testNum, 'dateModified', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_006 + * @tc.name : getFileAssets + * @tc.desc : filekey dateTakenOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_006', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_006' + await getFileAssetsBy(done, testNum, 'dateTaken', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_007 + * @tc.name : getFileAssets + * @tc.desc : filekey titleOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_007', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_007' + await getFileAssetsBy(done, testNum, 'title', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_008 + * @tc.name : getFileAssets + * @tc.desc : filekey durationOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_008', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_008' + await getFileAssetsBy(done, testNum, 'duration'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_009 + * @tc.name : getFileAssets + * @tc.desc : filekey widthOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_009', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_009' + await getFileAssetsBy(done, testNum, 'width'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_010 + * @tc.name : getFileAssets + * @tc.desc : filekey heightOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_010', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_010' + await getFileAssetsBy(done, testNum, 'height'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_011 + * @tc.name : getFileAssets + * @tc.desc : filekey orientationOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_011', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_011' + await getFileAssetsBy(done, testNum, 'orientation', 2); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_012 + * @tc.name : getFileAssets + * @tc.desc : filekey widthOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_012', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_012' + await getFileAssetsBy(done, testNum, 'albumId'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0014 + * @tc.name : getFileAssets + * @tc.desc : filekey artistOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0014', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_014' + await getFileAssetsBy(done, testNum, 'artist'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0015 + * @tc.name : getFileAssets + * @tc.desc : filekey audioAlbumOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0015', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_015' + await getFileAssetsBy(done, testNum, 'audioAlbum'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0017 + * @tc.name : getFileAssets + * @tc.desc : filekey relative_path + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0016', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_015' + await getFileAssetsBy(done, testNum, 'relativePath'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0017 + * @tc.name : getFileAssets + * @tc.desc : filekey display_name + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0017', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILE_KEY_PROMISE_0017' + await getFileAssetsBy(done, testNum, 'displayName'); + + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..82fb1970953e8e320b149a3885c079feaf97b750 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_fileKey/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileKey/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_fileKey/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_fileKey/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/app.json old mode 100644 new mode 100755 index 5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba..841282ae47b98590bdbc8aea744fbbcd178e9195 --- a/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/app.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/app.json @@ -1,21 +1,21 @@ -{ - "app":{ - "bundleName":"ohos.acts.multimedia.mediaLibrary", - "vendor":"huawei", - "versionCode":1000000, - "versionName":"1.0.0", - "debug":false, - "icon":"$media:icon", - "label":"$string:entry_MainAbility", - "description":"$string:mainability_description", - "distributedNotificationEnabled":true, - "keepAlive":true, - "singleUser":true, - "minAPIVersion":8, - "targetAPIVersion":8, - "car":{ - "apiCompatibleVersion":8, - "singleUser":false - } - } -} +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/element/string.json old mode 100644 new mode 100755 index c1dee63527ae5e3c37f3736f6b68189e8df6f201..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- a/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_fileResult/AppScope/resources/base/media/app_icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/BUILD.gn b/multimedia/medialibrary/mediaLibrary_fileResult/BUILD.gn old mode 100644 new mode 100755 index 2b4711a26eb9d6250fbf04dacd8a2931a0191854..d423dfe5299f07d9d12a1989eee8888f8c745ddb --- a/multimedia/medialibrary/mediaLibrary_fileResult/BUILD.gn +++ b/multimedia/medialibrary/mediaLibrary_fileResult/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//test/xts/tools/build/suite.gni") diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/Test.json b/multimedia/medialibrary/mediaLibrary_fileResult/Test.json old mode 100644 new mode 100755 index 612ce0d1a21c3c0d75fa8ad8fa1685a0cfe80e53..aa5a3d96ca9b4ff8aa750e060151085d3174a24c --- a/multimedia/medialibrary/mediaLibrary_fileResult/Test.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/Test.json @@ -1,65 +1,63 @@ -{ - "description": "Configuration for mediaLibrary Tests", - "driver": { - "type": "JSUnitTest", - "test-timeout": "300000", - "package": "ohos.acts.multimedia.mediaLibrary", - "shell-timeout": "600000" - }, - "kits": [ - { - "type": "ShellKit", - "pre-push": [ - ], - "run-command": [ - "rm -rf /storage/media/100/local/files/*", - "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", - "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", - "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "PushKit", - "pre-push": [ - ], - "push": [ - "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "ShellKit", - "run-command": [ - "mkdir -pv /storage/media/100/local/files/Pictures/{Static,ImageInfo}", - "mkdir -pv /storage/media/100/local/files/Videos/Static", - "mkdir -pv /storage/media/100/local/files/Audios/Static", - "mkdir -pv /storage/media/100/local/files/Documents/Static", - - "for d in Static; do for i in $$(seq 4); 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 4); 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 4); 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 100); 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;", - "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/ImageInfo/01.jpg", - - "chmod -R 777 /storage/media/100/local/files/*", - "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", - "hilog -Q pidoff", - "hilog -p off", - "hilog -b D -D 0xD002B70", - "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "sleep 10", - "cem publish -e usual.event.SCREEN_OFF", - "sleep 10" - ] - }, - { - "test-file-name": [ - "ActsMediaLibraryFileResult.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,ImageInfo}", + "mkdir -pv /storage/media/100/local/files/Videos/Static", + "mkdir -pv /storage/media/100/local/files/Audios/Static", + "mkdir -pv /storage/media/100/local/files/Documents/Static", + + "for d in Static; do for i in $$(seq 4); 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 4); 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 4); 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 100); 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;", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/ImageInfo/01.jpg", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryFileResult.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/Application/AbilityStage.ts old mode 100644 new mode 100755 index 51cb02ba3f5c7011c1cd433d07deebd47a195704..14f230e140160dc5f94ecc462304621178f4cf64 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/Application/AbilityStage.ts +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/Application/AbilityStage.ts @@ -1,9 +1,9 @@ -import AbilityStage from "@ohos.application.AbilityStage" - -export default class MyAbilityStage extends AbilityStage { - onCreate() { - console.log("[Demo] MyAbilityStage onCreate") - globalThis.stageOnCreateRun = 1; - globalThis.stageContext = this.context; - } -} +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/MainAbility/MainAbility.ts old mode 100644 new mode 100755 index 2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,36 +1,36 @@ -import Ability from '@ohos.application.Ability' - -export default class MainAbility extends Ability { - onCreate(want,launchParam){ - // Ability is creating, initialize resources for this ability - console.log("[Demo] MainAbility onCreate") - globalThis.abilityWant = want; - } - - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("[Demo] MainAbility onDestroy") - } - - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("[Demo] MainAbility onWindowStageCreate") - globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) - } - - onWindowStageDestroy() { - //Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") - } - - onForeground() { - // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") - } - - onBackground() { - // Ability has back to background - console.log("[Demo] MainAbility onBackground") - } +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } }; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/index/index.ets old mode 100644 new mode 100755 index 553566f889603f823fe24557052baf1f26675a15..71bcb74b8a045a4e05dd64ed8209d3964c72a730 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/index/index.ets +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/index/index.ets @@ -1,69 +1,67 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import file from '@system.file'; - -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" -import testsuite from "../../test/List.test.ets" -import { getPermission } from "../../../../../../../common" - -@Entry -@Component -struct Index { - - aboutToAppear(){ - getPermission() - console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - const reportExtend = new ReportExtend(file) - - core.addService('report', reportExtend) - core.init() - core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - console.info('testsuite()---->') - testsuite(globalThis.abilityContext) - core.execute() - console.info('core.execute()---->') - } - - build() { - Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(25) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/second/second.ets old mode 100644 new mode 100755 index 1c1c727ff11ecc97909f482c35268db87ae23bb4..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/second/second.ets +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/pages/second/second.ets @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import router from '@system.router'; - -@Entry -@Component -struct Second { - private content: string = "Second Page" - - build() { - Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(`${this.content}`) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('back to index') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/List.test.ets old mode 100644 new mode 100755 index 1d132ef06246a38e5b1490f295d66590dc9fc96f..46cdd507131ac056b03a72e43a0f1ee6976c0a0e --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/List.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/ets/test/List.test.ets @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import fetchFileResultPromise from './fetchFileResultPromise.test.ets' -import fetchFileResultCallback from './fetchFileResultCallback.test.ets' -export default function testsuite(abilityContext) { - fetchFileResultCallback(abilityContext) - fetchFileResultPromise(abilityContext) -} +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fetchFileResultPromise from './fetchFileResultPromise.test.ets' +import fetchFileResultCallback from './fetchFileResultCallback.test.ets' +export default function testsuite(abilityContext) { + fetchFileResultCallback(abilityContext) + fetchFileResultPromise(abilityContext) +} 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 old mode 100644 new mode 100755 index d621abce3126e2b5068125207e3279e278bb9df0..2c26b3656af483673d49a11c18515ef540e013a8 --- 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 @@ -1,504 +1,506 @@ -/* - * 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, - FILE_TYPE, - FILEKEY, - checkPresetsAssets, - checkAssetsCount, - fetchOps, -} from '../../../../../../common'; - -export default function fetchFileResultCallbackTest(abilityContext) { - describe('fetchFileResultCallbackTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultCb'); - }); - beforeEach(function () { }); - afterEach(async function () { - await sleep() - }); - afterAll(function () { }); - - const checkAssetCount = async function (done, testNum, fetchOp, expectCount) { - try { - console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) - media.getFileAssets(fetchOp, async (err, fetchFileResult) => { - let checkResult = await checkAssetsCount(done, testNum, fetchFileResult, expectCount) - expect(checkResult).assertTrue(); - await fetchFileResult.close(); - done(); - }); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const checkGetPositionObject = async function (done, testNum, pos) { - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - fetchFileResult.getPositionObject(pos, async (err, targetObject) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(targetObject.displayName).assertEqual(assetList[pos].displayName); - fetchFileResult.close(); - done(); - }); - - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - } - - const checkGetAllObject = async function (done, testNum, expectCount) { - try { - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, { order: FILEKEY.DATE_ADDED + ` DESC LIMIT 0,${expectCount}` }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - fetchFileResult.getAllObject(async (err, targetObjects) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(targetObjects.length).assertEqual(expectCount); - fetchFileResult.close(); - done(); - }); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - } - - // ------------------------------ 001 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Callback) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01' - let expectCount = 1 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,1", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Callback) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02' - let expectCount = 2 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,2", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Callback) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03' - let expectCount = 100 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,100", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Callback) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03' - let expectCount = 0 - let currentFetchOp = fetchOps('Documents/zeor/', FILE_TYPE) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - // ------------------------------ 001 test end ------------------------- - - // ------------------------------ 004 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004 - * @tc.name : getFirstObject - * @tc.desc : Get FetchResult, get first object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - fetchFileResult.getFirstObject(async (err, firstObject) => { - if(err) { - console.info(`${testNum} err: ${err}`); - expect(false).assertTrue(); - done(); - return; - } - expect(firstObject.displayName).assertEqual(assetList[0].displayName); - fetchFileResult.close(); - done(); - }); - - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - // ------------------------------ 004 test end ------------------------- - - // ------------------------------ 005 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005 - * @tc.name : getNextObject - * @tc.desc : Get FetchResult, get first object, get next object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - await fetchFileResult.getFirstObject(); - fetchFileResult.getNextObject(async (err, nextObject) => { - if(err) { - console.info(`${testNum} err: ${err}`); - expect(false).assertTrue(); - done(); - return; - } - let assetList = await fetchFileResult.getAllObject(); - expect(nextObject.displayName).assertEqual(assetList[1].displayName); - fetchFileResult.close(); - done(); - }); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 005 test end ------------------------- - - // ------------------------------ 006 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006 - * @tc.name : getLastObject - * @tc.desc : Get FetchResult, get first object, get next object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - fetchFileResult.getLastObject(async (err, lastObject) => { - expect(lastObject.displayName).assertEqual(assetList[assetList.length - 1].displayName); - fetchFileResult.close(); - done(); - }); - - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 006 test end ------------------------- - - // ------------------------------ 007 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 0 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01'; - let pos = 0; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02'; - let pos = 1; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03'; - let pos = 3; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - fetchFileResult.getPositionObject(expectCount, async (err, targetObject) => { - if (targetObject == undefined || err) { - expect(true).assertTrue(); - done(); - fetchFileResult.close(); - return; - } - fetchFileResult.close(); - expect(false).assertTrue(); - done(); - }); - - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // // ------------------------------ 007 test end ------------------------- - - // ------------------------------ 008 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01'; - let expectCount = 1; - await checkGetAllObject(done, testNum, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02'; - let expectCount = 50; - await checkGetAllObject(done, testNum, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03'; - let expectCount = 100; - await checkGetAllObject(done, testNum, expectCount) - }); - // ------------------------------ 008 test end ------------------------- - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01 - * @tc.name : getFirstObject - * @tc.desc : Get FetchResult, get first object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01'; - try { - let currentFetchOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 1; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - fetchFileResult.getFirstObject(async (err, firstObject) => { - expect(firstObject.id != undefined).assertTrue(); - if (firstObject.id == undefined) { - console.info('MediaLibraryTest :firstObject.id == undefined'); - } - - expect(firstObject.uri != undefined).assertTrue(); - if (firstObject.uri == undefined) { - console.info('MediaLibraryTest :firstObject.uri === undefined'); - } - - expect(firstObject.mimeType).assertEqual('image/*'); - - expect(firstObject.mediaType).assertEqual(IMAGE_TYPE); - - expect(firstObject.displayName).assertEqual('01.jpg'); - - expect(firstObject.title).assertEqual('01'); - - expect(firstObject.relativePath).assertEqual('Pictures/ImageInfo/'); - - expect(firstObject.parent != undefined).assertTrue(); - if (firstObject.parent == undefined) { - console.info('MediaLibraryTest :firstObject.parent == undefined'); - } - - expect(firstObject.size).assertEqual(348113); - - expect(firstObject.dateTaken).assertEqual(0); - - expect(firstObject.artist).assertEqual(''); - - expect(firstObject.audioAlbum).assertEqual(''); - - expect(firstObject.width).assertEqual(1279); - - expect(firstObject.height).assertEqual(1706); - - expect(firstObject.orientation).assertEqual(0); - - expect(firstObject.duration).assertEqual(0); - - expect(firstObject.albumId != undefined).assertTrue(); - if (firstObject.albumId == undefined) { - console.info('MediaLibraryTest :firstObject.albumId == undefined'); - } - - expect(firstObject.albumUri != undefined).assertTrue(); - if (firstObject.albumUri == undefined) { - console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); - } - - expect(firstObject.albumName).assertEqual('ImageInfo'); - - expect(firstObject.dateAdded != undefined).assertTrue(); - if (firstObject.dateAdded == undefined) { - console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); - } - - expect(firstObject.albumName != undefined).assertTrue(); - if (firstObject.albumName == undefined) { - console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); - } - done(); - }); - - } catch (error) { - console.info(`${testNum} error : ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +import { + sleep, + IMAGE_TYPE, + FILE_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; + +export default function fetchFileResultCallbackTest(abilityContext) { + describe('fetchFileResultCallbackTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultCb'); + }); + beforeEach(function () { }); + afterEach(async function () { + await sleep() + }); + afterAll(function () { }); + + const checkAssetCount = async function (done, testNum, fetchOp, expectCount) { + try { + console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) + media.getFileAssets(fetchOp, async (err, fetchFileResult) => { + let checkResult = await checkAssetsCount(done, testNum, fetchFileResult, expectCount) + expect(checkResult).assertTrue(); + await fetchFileResult.close(); + done(); + }); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const checkGetPositionObject = async function (done, testNum, pos) { + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + fetchFileResult.getPositionObject(pos, async (err, targetObject) => { + if (err) { + expect(false).assertTrue(); + done(); + return; + } + expect(targetObject.displayName).assertEqual(assetList[pos].displayName); + fetchFileResult.close(); + done(); + }); + + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + const checkGetAllObject = async function (done, testNum, expectCount) { + try { + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, { order: FILEKEY.DATE_ADDED + ` DESC LIMIT 0,${expectCount}` }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + fetchFileResult.getAllObject(async (err, targetObjects) => { + if (err) { + expect(false).assertTrue(); + done(); + return; + } + expect(targetObjects.length).assertEqual(expectCount); + fetchFileResult.close(); + done(); + }); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01' + let expectCount = 1 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,1", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02' + let expectCount = 2 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,2", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03' + let expectCount = 100 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,100", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03' + let expectCount = 0 + let currentFetchOp = fetchOps('Documents/zeor/', FILE_TYPE) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + fetchFileResult.getFirstObject(async (err, firstObject) => { + if(err) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + done(); + return; + } + expect(firstObject.displayName).assertEqual(assetList[0].displayName); + fetchFileResult.close(); + done(); + }); + + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + // ------------------------------ 004 test end ------------------------- + + // ------------------------------ 005 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + await fetchFileResult.getFirstObject(); + fetchFileResult.getNextObject(async (err, nextObject) => { + if(err) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + done(); + return; + } + let assetList = await fetchFileResult.getAllObject(); + expect(nextObject.displayName).assertEqual(assetList[1].displayName); + fetchFileResult.close(); + done(); + }); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 005 test end ------------------------- + + // ------------------------------ 006 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006 + * @tc.name : getLastObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + fetchFileResult.getLastObject(async (err, lastObject) => { + expect(lastObject.displayName).assertEqual(assetList[assetList.length - 1].displayName); + fetchFileResult.close(); + done(); + }); + + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 006 test end ------------------------- + + // ------------------------------ 007 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 0 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01'; + let pos = 0; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02'; + let pos = 1; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03'; + let pos = 3; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + fetchFileResult.getPositionObject(expectCount, async (err, targetObject) => { + if (targetObject == undefined || err) { + expect(true).assertTrue(); + done(); + fetchFileResult.close(); + return; + } + fetchFileResult.close(); + expect(false).assertTrue(); + done(); + }); + + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // // ------------------------------ 007 test end ------------------------- + + // ------------------------------ 008 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01'; + let expectCount = 1; + await checkGetAllObject(done, testNum, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02'; + let expectCount = 50; + await checkGetAllObject(done, testNum, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03'; + let expectCount = 100; + await checkGetAllObject(done, testNum, expectCount) + }); + // ------------------------------ 008 test end ------------------------- + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01'; + try { + let currentFetchOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 1; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + fetchFileResult.getFirstObject(async (err, firstObject) => { + expect(firstObject.id != undefined).assertTrue(); + if (firstObject.id == undefined) { + console.info('MediaLibraryTest :firstObject.id == undefined'); + } + + expect(firstObject.uri != undefined).assertTrue(); + if (firstObject.uri == undefined) { + console.info('MediaLibraryTest :firstObject.uri === undefined'); + } + + expect(firstObject.mimeType).assertEqual('image/*'); + + expect(firstObject.mediaType).assertEqual(IMAGE_TYPE); + + expect(firstObject.displayName).assertEqual('01.jpg'); + + expect(firstObject.title).assertEqual('01'); + + expect(firstObject.relativePath).assertEqual('Pictures/ImageInfo/'); + + expect(firstObject.parent != undefined).assertTrue(); + if (firstObject.parent == undefined) { + console.info('MediaLibraryTest :firstObject.parent == undefined'); + } + + expect(firstObject.size).assertEqual(348113); + + expect(firstObject.dateTaken).assertEqual(0); + + expect(firstObject.artist).assertEqual(''); + + expect(firstObject.audioAlbum).assertEqual(''); + + expect(firstObject.width).assertEqual(1279); + + expect(firstObject.height).assertEqual(1706); + + expect(firstObject.orientation).assertEqual(0); + + expect(firstObject.duration).assertEqual(0); + + expect(firstObject.albumId != undefined).assertTrue(); + if (firstObject.albumId == undefined) { + console.info('MediaLibraryTest :firstObject.albumId == undefined'); + } + + expect(firstObject.albumUri != undefined).assertTrue(); + if (firstObject.albumUri == undefined) { + console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); + } + + expect(firstObject.albumName).assertEqual('ImageInfo'); + + expect(firstObject.dateAdded != undefined).assertTrue(); + if (firstObject.dateAdded == undefined) { + console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); + } + + expect(firstObject.albumName != undefined).assertTrue(); + if (firstObject.albumName == undefined) { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + done(); + }); + + } catch (error) { + console.info(`${testNum} error : ${error}`); + expect(false).assertTrue(); + done(); + } + }); + }); +} 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 old mode 100644 new mode 100755 index da183e5050860fc84a62fb92e6d01cfc7f36a432..d285e47f9f4d0e9512bfbe997a66f820c277c771 --- 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 @@ -1,556 +1,556 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, - IMAGE_TYPE, - VIDEO_TYPE, - AUDIO_TYPE, - FILE_TYPE, - FILEKEY, - checkPresetsAssets, - nameFetchOps, - checkAssetsCount, - fetchOps, -} from '../../../../../../common'; - -export default function fetchFileResultPromiseTest(abilityContext) { - describe('fetchFileResultPromiseTest', function () { - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(async function () { - await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultPro'); - }); - beforeEach(function () { }); - afterEach(async function () { - sleep() - }); - afterAll(function () { }); - - const checkAssetCount = async function (done, testNum, fetchOp, expectCount) { - try { - console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) - let fetchFileResult = await media.getFileAssets(fetchOp); - let checkResult = await checkAssetsCount(done, testNum, fetchFileResult, expectCount) - expect(checkResult).assertTrue(); - await fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`) - expect(false).assertTrue(); - done(); - } - } - - const checkGetPositionObject = async function (done, testNum, pos) { - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - let targetObject = await fetchFileResult.getPositionObject(pos); - expect(targetObject.displayName).assertEqual(assetList[pos].displayName); - fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - } - - const checkGetAllObject = async function (done, testNum, expectCount) { - try { - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, { order: FILEKEY.DATE_ADDED + ` DESC LIMIT 0,${expectCount}` }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - var targetObjects = await fetchFileResult.getAllObject(); - expect(targetObjects.length).assertEqual(expectCount); - fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - } - - // ------------------------------ 001 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Promise) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01' - let expectCount = 1 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,1", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Promise) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02' - let expectCount = 2 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,2", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Promise) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03' - let expectCount = 100 - let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, - { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,100", }) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Promise) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03' - let expectCount = 0 - let currentFetchOp = fetchOps('Documents/zeor/', FILE_TYPE) - await checkAssetCount(done, testNum, currentFetchOp, expectCount) - }); - - // ------------------------------ 001 test end ------------------------- - - // ------------------------------ 002 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002 - * @tc.name : getCount - * @tc.desc : Get FetchResult by getFileCountTenOp, check the return value of the interface (by Promise) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE); - console.info(`${testNum} currentFetchOp :${JSON.stringify(currentFetchOp)}`) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let asset = await fetchFileResult.getFirstObject(); - for (var i = 1; i < expectCount; i++) { - asset = await fetchFileResult.getNextObject(); - if (i == expectCount - 1) { - let result = fetchFileResult.isAfterLast(); - expect(result).assertTrue(); - fetchFileResult.close(); - done(); - } - } - } catch (error) { - console.info(`${testNum} error ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 002 test end ------------------------- - - // ------------------------------ 003 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003 - * @tc.name : getCount - * @tc.desc : Get FetchResult, close it, check if result closed - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003'; - try { - let expectCount = 4; - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - fetchFileResult.close(); - let count = 0; - try { - fetchFileResult.getCount(); - } catch { count++ } - try { - await fetchFileResult.getFirstObject(); - } catch { count++ } - try { - await fetchFileResult.getNextObject(); - } catch { count++ } - try { - await fetchFileResult.getLastObject(); - } catch { count++ } - try { - await fetchFileResult.getPositionObject(0); - } catch { count++ } - await sleep(1000) - expect(count).assertEqual(5); - done(); - } catch (error) { - console.info(`${testNum} error:${error}`) - expect(false).assertTrue(); - done(); - } - }); - - // ------------------------------ 003 test end ------------------------- - - // ------------------------------ 004 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004 - * @tc.name : getFirstObject - * @tc.desc : Get FetchResult, get first object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - let firstObject = await fetchFileResult.getFirstObject(); - expect(firstObject.displayName).assertEqual(assetList[0].displayName); - fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - // ------------------------------ 004 test end ------------------------- - - // ------------------------------ 005 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005 - * @tc.name : getNextObject - * @tc.desc : Get FetchResult, get first object, get next object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let firstObject = await fetchFileResult.getFirstObject(); - let nextObject = await fetchFileResult.getNextObject(); - let assetList = await fetchFileResult.getAllObject(); - expect(firstObject.displayName).assertEqual(assetList[0].displayName); - - expect(nextObject.displayName).assertEqual(assetList[1].displayName); - fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 005 test end ------------------------- - - // ------------------------------ 006 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006 - * @tc.name : getLastObject - * @tc.desc : Get FetchResult, get first object, get next object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let assetList = await fetchFileResult.getAllObject(); - let firstObject = await fetchFileResult.getLastObject(); - expect(firstObject.displayName).assertEqual(assetList[assetList.length - 1].displayName); - fetchFileResult.close(); - done(); - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 006 test end ------------------------- - - // ------------------------------ 007 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 0 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01'; - let pos = 0; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02'; - let pos = 1; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_03'; - let pos = 3; - await checkGetPositionObject(done, testNum, pos) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04 - * @tc.name : getPositionObject - * @tc.desc : Get FetchResult, get position 1 object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04' - try { - let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) - console.info(`${testNum} currentFetchOp ${currentFetchOp} `) - - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 4; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - try { - await fetchFileResult.getPositionObject(expectCount); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`${testNum} passed error: ${error}`); - expect(true).assertTrue(); - fetchFileResult.close() - done(); - } - } catch (error) { - console.info(`${testNum} error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - // // ------------------------------ 007 test end ------------------------- - - // ------------------------------ 008 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01'; - let expectCount = 1; - await checkGetAllObject(done, testNum, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02'; - let expectCount = 50; - await checkGetAllObject(done, testNum, expectCount) - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03 - * @tc.name : getAllObject - * @tc.desc : Get FetchResult, get all object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03'; - let expectCount = 100; - await checkGetAllObject(done, testNum, expectCount) - }); - // ------------------------------ 008 test end ------------------------- - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01 - * @tc.name : getFirstObject - * @tc.desc : Get FetchResult, get first object, check result - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01', 0, async function (done) { - let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01'; - try { - let currentFetchOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE) - let fetchFileResult = await media.getFileAssets(currentFetchOp); - let expectCount = 1; - let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); - if (!checkAssetCountPass) return; - let firstObject = await fetchFileResult.getFirstObject(); - expect(firstObject.id != undefined).assertTrue(); - if (firstObject.id == undefined) { - console.info('MediaLibraryTest :firstObject.id == undefined'); - } - - expect(firstObject.uri != undefined).assertTrue(); - if (firstObject.uri == undefined) { - console.info('MediaLibraryTest :firstObject.uri === undefined'); - } - - expect(firstObject.mimeType).assertEqual('image/*'); - - expect(firstObject.mediaType).assertEqual(IMAGE_TYPE); - - expect(firstObject.displayName).assertEqual('01.jpg'); - - expect(firstObject.title).assertEqual('01'); - - expect(firstObject.relativePath).assertEqual('Pictures/ImageInfo/'); - - expect(firstObject.parent != undefined).assertTrue(); - if (firstObject.parent == undefined) { - console.info('MediaLibraryTest :firstObject.parent == undefined'); - } - - expect(firstObject.size).assertEqual(348113); - - expect(firstObject.dateTaken).assertEqual(0); - - expect(firstObject.artist).assertEqual(''); - - expect(firstObject.audioAlbum).assertEqual(''); - - expect(firstObject.width).assertEqual(1279); - - expect(firstObject.height).assertEqual(1706); - - expect(firstObject.orientation).assertEqual(0); - - expect(firstObject.duration).assertEqual(0); - - expect(firstObject.albumId != undefined).assertTrue(); - if (firstObject.albumId == undefined) { - console.info('MediaLibraryTest :firstObject.albumId == undefined'); - } - - expect(firstObject.albumUri != undefined).assertTrue(); - if (firstObject.albumUri == undefined) { - console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); - } - - expect(firstObject.albumName).assertEqual('ImageInfo'); - - expect(firstObject.dateAdded != undefined).assertTrue(); - if (firstObject.dateAdded == undefined) { - console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); - } - - expect(firstObject.albumName != undefined).assertTrue(); - if (firstObject.albumName == undefined) { - console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); - } - done(); - } catch (error) { - console.info(`${testNum} error : ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILE_TYPE, + FILEKEY, + checkPresetsAssets, + nameFetchOps, + checkAssetsCount, + fetchOps, +} from '../../../../../../common'; + +export default function fetchFileResultPromiseTest(abilityContext) { + describe('fetchFileResultPromiseTest', function () { + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultPro'); + }); + beforeEach(function () { }); + afterEach(async function () { + sleep() + }); + afterAll(function () { }); + + const checkAssetCount = async function (done, testNum, fetchOp, expectCount) { + try { + console.info(`${testNum} fetchOp: ${JSON.stringify(fetchOp)}`) + let fetchFileResult = await media.getFileAssets(fetchOp); + let checkResult = await checkAssetsCount(done, testNum, fetchFileResult, expectCount) + expect(checkResult).assertTrue(); + await fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`) + expect(false).assertTrue(); + done(); + } + } + + const checkGetPositionObject = async function (done, testNum, pos) { + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + let targetObject = await fetchFileResult.getPositionObject(pos); + expect(targetObject.displayName).assertEqual(assetList[pos].displayName); + fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + const checkGetAllObject = async function (done, testNum, expectCount) { + try { + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, { order: FILEKEY.DATE_ADDED + ` DESC LIMIT 0,${expectCount}` }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + var targetObjects = await fetchFileResult.getAllObject(); + expect(targetObjects.length).assertEqual(expectCount); + fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01' + let expectCount = 1 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,1", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02' + let expectCount = 2 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,2", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03' + let expectCount = 100 + let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE, + { order: FILEKEY.DATE_ADDED + " DESC LIMIT 0,100", }) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03' + let expectCount = 0 + let currentFetchOp = fetchOps('Documents/zeor/', FILE_TYPE) + await checkAssetCount(done, testNum, currentFetchOp, expectCount) + }); + + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTenOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE); + console.info(`${testNum} currentFetchOp :${JSON.stringify(currentFetchOp)}`) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + for (var i = 1; i < expectCount; i++) { + asset = await fetchFileResult.getNextObject(); + if (i == expectCount - 1) { + let result = fetchFileResult.isAfterLast(); + expect(result).assertTrue(); + fetchFileResult.close(); + done(); + } + } + } catch (error) { + console.info(`${testNum} error ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 002 test end ------------------------- + + // ------------------------------ 003 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003 + * @tc.name : getCount + * @tc.desc : Get FetchResult, close it, check if result closed + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003'; + try { + let expectCount = 4; + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + fetchFileResult.close(); + let count = 0; + try { + fetchFileResult.getCount(); + } catch { count++ } + try { + await fetchFileResult.getFirstObject(); + } catch { count++ } + try { + await fetchFileResult.getNextObject(); + } catch { count++ } + try { + await fetchFileResult.getLastObject(); + } catch { count++ } + try { + await fetchFileResult.getPositionObject(0); + } catch { count++ } + await sleep(1000) + expect(count).assertEqual(5); + done(); + } catch (error) { + console.info(`${testNum} error:${error}`) + expect(false).assertTrue(); + done(); + } + }); + + // ------------------------------ 003 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject.displayName).assertEqual(assetList[0].displayName); + fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + // ------------------------------ 004 test end ------------------------- + + // ------------------------------ 005 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let firstObject = await fetchFileResult.getFirstObject(); + let nextObject = await fetchFileResult.getNextObject(); + let assetList = await fetchFileResult.getAllObject(); + expect(firstObject.displayName).assertEqual(assetList[0].displayName); + + expect(nextObject.displayName).assertEqual(assetList[1].displayName); + fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 005 test end ------------------------- + + // ------------------------------ 006 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006 + * @tc.name : getLastObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${JSON.stringify(currentFetchOp)} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let assetList = await fetchFileResult.getAllObject(); + let firstObject = await fetchFileResult.getLastObject(); + expect(firstObject.displayName).assertEqual(assetList[assetList.length - 1].displayName); + fetchFileResult.close(); + done(); + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 006 test end ------------------------- + + // ------------------------------ 007 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 0 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01'; + let pos = 0; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02'; + let pos = 1; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_03'; + let pos = 3; + await checkGetPositionObject(done, testNum, pos) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04' + try { + let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE, { order: FILEKEY.DATE_ADDED + " DESC" }) + console.info(`${testNum} currentFetchOp ${currentFetchOp} `) + + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 4; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + try { + await fetchFileResult.getPositionObject(expectCount); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum} passed error: ${error}`); + expect(true).assertTrue(); + fetchFileResult.close() + done(); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + // // ------------------------------ 007 test end ------------------------- + + // ------------------------------ 008 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01'; + let expectCount = 1; + await checkGetAllObject(done, testNum, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02'; + let expectCount = 50; + await checkGetAllObject(done, testNum, expectCount) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03'; + let expectCount = 100; + await checkGetAllObject(done, testNum, expectCount) + }); + // ------------------------------ 008 test end ------------------------- + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01'; + try { + let currentFetchOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE) + let fetchFileResult = await media.getFileAssets(currentFetchOp); + let expectCount = 1; + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount); + if (!checkAssetCountPass) return; + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject.id != undefined).assertTrue(); + if (firstObject.id == undefined) { + console.info('MediaLibraryTest :firstObject.id == undefined'); + } + + expect(firstObject.uri != undefined).assertTrue(); + if (firstObject.uri == undefined) { + console.info('MediaLibraryTest :firstObject.uri === undefined'); + } + + expect(firstObject.mimeType).assertEqual('image/*'); + + expect(firstObject.mediaType).assertEqual(IMAGE_TYPE); + + expect(firstObject.displayName).assertEqual('01.jpg'); + + expect(firstObject.title).assertEqual('01'); + + expect(firstObject.relativePath).assertEqual('Pictures/ImageInfo/'); + + expect(firstObject.parent != undefined).assertTrue(); + if (firstObject.parent == undefined) { + console.info('MediaLibraryTest :firstObject.parent == undefined'); + } + + expect(firstObject.size).assertEqual(348113); + + expect(firstObject.dateTaken).assertEqual(0); + + expect(firstObject.artist).assertEqual(''); + + expect(firstObject.audioAlbum).assertEqual(''); + + expect(firstObject.width).assertEqual(1279); + + expect(firstObject.height).assertEqual(1706); + + expect(firstObject.orientation).assertEqual(0); + + expect(firstObject.duration).assertEqual(0); + + expect(firstObject.albumId != undefined).assertTrue(); + if (firstObject.albumId == undefined) { + console.info('MediaLibraryTest :firstObject.albumId == undefined'); + } + + expect(firstObject.albumUri != undefined).assertTrue(); + if (firstObject.albumUri == undefined) { + console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); + } + + expect(firstObject.albumName).assertEqual('ImageInfo'); + + expect(firstObject.dateAdded != undefined).assertTrue(); + if (firstObject.dateAdded == undefined) { + console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); + } + + expect(firstObject.albumName != undefined).assertTrue(); + if (firstObject.albumName == undefined) { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + done(); + } catch (error) { + console.info(`${testNum} error : ${error}`); + expect(false).assertTrue(); + done(); + } + }); + }); +} diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/module.json old mode 100644 new mode 100755 index 82fb1970953e8e320b149a3885c079feaf97b750..8e0400fc761d17bbb4800f146c44da034a4bb89e --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/module.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/module.json @@ -1,67 +1,67 @@ -{ - "module": { - "name": "phone", - "type": "entry", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:mainability_description", - "mainElement": "MainAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "uiSyntax": "ets", - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", - "description": "$string:mainability_description", - "icon": "$media:icon", - "label": "$string:entry_MainAbility", - "visible": true, - "orientation": "portrait", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_BUNDLE_INFO", - "reason": "use ohos.permission.GET_BUNDLE_INFO" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - }, - { - "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, - { - "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.MEDIA_LOCATION", - "reason":"use ohos.permission.MEDIA_LOCATION" - }, - { - "name": "ohos.permission.READ_MEDIA", - "reason":"use ohos.permission.READ_MEDIA" - }, - { - "name": "ohos.permission.WRITE_MEDIA", - "reason":"use ohos.permission.WRITE_MEDIA" - } - ] - } -} +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/element/string.json old mode 100644 new mode 100755 index d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b..32237ee203edf64926964fb238fa44e396ddf577 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/media/icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/profile/main_pages.json old mode 100644 new mode 100755 index 6898b31d2085f478ee1ed9d933a5910cbf901d92..96b478210df9884592229ae2db6f6bb7f86c14f4 --- a/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/profile/main_pages.json +++ b/multimedia/medialibrary/mediaLibrary_fileResult/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ -{ - "src": [ - "pages/index/index", - "pages/second/second" - ] +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_fileResult/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_fileResult/signature/openharmony_sx.p7b old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/app.json new file mode 100755 index 0000000000000000000000000000000000000000..5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c1dee63527ae5e3c37f3736f6b68189e8df6f201 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_getThumbnail/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/BUILD.gn b/multimedia/medialibrary/mediaLibrary_getThumbnail/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..0b0e46bef447604db26d89dd042c511d6ed9623f --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("mediaLibrary_getThumbnail_hap") { + hap_profile = "entry/src/main/module.json" + deps = [ + ":mediaLibrary_js_assets", + ":mediaLibrary_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsMediaLibraryGetThumbnailTest" +} + +ohos_app_scope("medialibrary_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("mediaLibrary_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("mediaLibrary_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":medialibrary_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/Test.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..10fac8c90536ad50edbba87643189c096931327d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/Test.json @@ -0,0 +1,62 @@ +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "300000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.MediaLibraryDataA/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/Thumbnail", + "mkdir -pv /storage/media/100/local/files/Videos/Thumbnail", + "mkdir -pv /storage/media/100/local/files/Audios/Thumbnail", + + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.jpg /storage/media/100/local/files/Pictures/Thumbnail", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp3 /storage/media/100/local/files/Audios/Thumbnail", + "cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp4 /storage/media/100/local/files/Videos/Thumbnail", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -p off", + "hilog -b D -D 0xD002B70", + "scanner_demo", + "sleep 10" + ], + "teardown-command":[ + "rm -rf /storage/media/100/local/files/*" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryGetThumbnailTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/Application/AbilityStage.ts new file mode 100755 index 0000000000000000000000000000000000000000..51cb02ba3f5c7011c1cd433d07deebd47a195704 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000000000000000000000000000000000000..2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/index/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..e45e49a3b7b1f7478c19dfae76022aff91a6896e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/second/second.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c1c727ff11ecc97909f482c35268db87ae23bb4 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/List.test.ets b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..05c14818db425d804d2289ebadb0f90e55b41f77 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 getThumbnailPromise from './getThumbnailPromise.test.ets' +import getThumbnailCallback from './getThumbnailCallback.test.ets' +export default function testsuite(abilityContext) { + getThumbnailCallback(abilityContext) + getThumbnailPromise(abilityContext) +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailCallback.test.ets b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailCallback.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..593b206e7d432f9d006692682d4790a8562f2406 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailCallback.test.ets @@ -0,0 +1,442 @@ +/* + * 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 image from '@ohos.multimedia.image'; + +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; +export default function getThumbnailCallback(abilityContext) { + describe('getThumbnailCallback', function () { + image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { }); + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + + async function testGetThumbnail(done, testNum, dOp, size,) { + try { + let fetchFileResult = await media.getFileAssets(dOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + if (size == 'default') { + size = { width: 256, height: 256 }; + asset.getThumbnail(async (err, pixelmap) => { + await pixelmap.getImageInfo((err, info) => { + console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`); + console.info(`${testNum}:: param width ${size.width},param height: ${size.height}`); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }) + } else { + asset.getThumbnail(size, async (err, pixelmap) => { + await pixelmap.getImageInfo((err, info) => { + console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`); + console.info(`${testNum}:: param width ${size.width},param height: ${size.height}`); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }) + + } + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function testGetThumbnailError(done, testNum, dOp, size,) { + try { + let fetchFileResult = await media.getFileAssets(dOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + asset.getThumbnail(size, async (err, pixelmap) => { + if (err) { + console.info(`${testNum}:: err :${err}`); + expect(true).assertTrue(); + done(); + return; + } + if (pixelmap == undefined) { + expect(true).assertTrue(); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info(`${testNum} pixel width: ${info.size.width}`); + console.info(`${testNum} pixel height: ${info.size.height}`); + expect(info.size.width == size.width || info.size.height == size.height).assertFalse(); + done(); + } + }); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + // ------------------------------ image type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------image type end-------------------------- + + // ------------------------------video type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------video type end-------------------------- + + // ------------------------------audio type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------audio type end-------------------------- + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailPromise.test.ets b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailPromise.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1904a8cd6a2c75f51deb98b33a1208bb328e0689 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/ets/test/getThumbnailPromise.test.ets @@ -0,0 +1,419 @@ +/* + * 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 image from '@ohos.multimedia.image'; +import { + sleep, + IMAGE_TYPE, + VIDEO_TYPE, + AUDIO_TYPE, + FILEKEY, + checkPresetsAssets, + checkAssetsCount, + fetchOps, + getPermission, +} from '../../../../../../common'; + +export default function getThumbnailPromise(abilityContext) { + describe('getThumbnailPromise', function () { + image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { }); + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(async function () { + console.info('beforeAll case'); + await getPermission(); + await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail'); + }); + beforeEach(function () { + console.info('beforeEach case'); + }); + afterEach(async function () { + console.info('afterEach case'); + await sleep() + }); + afterAll(function () { + console.info('afterAll case'); + }); + + async function testGetThumbnail(done, testNum, dOp, size,) { + try { + let fetchFileResult = await media.getFileAssets(dOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + console.info(`${testNum}:displayName ${asset.displayName}`) + let pixelmap; + if (size == 'default') { + size = { width: 256, height: 256 }; + pixelmap = await asset.getThumbnail() + } else { + pixelmap = await asset.getThumbnail(size) + } + let info = await pixelmap.getImageInfo(); + console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`); + console.info(`${testNum}:: param width ${size.width},param height: ${size.height}`); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function testGetThumbnailError(done, testNum, dOp, size,) { + try { + let fetchFileResult = await media.getFileAssets(dOp); + let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); + if (!checkAssetCountPass) return; + let asset = await fetchFileResult.getFirstObject(); + let s: mediaLibrary.Size = size; + let pixelmap = await asset.getThumbnail(s); + let info = await pixelmap.getImageInfo(); + console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum}:: error :${error}`); + expect(true).assertTrue(); + done(); + } + } + + // ------------------------------ image type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07'; + let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------image type end-------------------------- + + // ------------------------------video type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(video) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07'; + let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------video type end-------------------------- + + // ------------------------------audio type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 128, height: 128 }; + await testGetThumbnail(done, testNum, dOp, size) + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 128, height: 256 }; + await testGetThumbnail(done, testNum, dOp, size); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = 'default'; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 1, height: 1 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 0, height: 0 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: -128, height: -128 }; + await testGetThumbnailError(done, testNum, dOp, size,); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07', 0, async function (done) { + let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07'; + let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE); + let size = { width: 1024, height: 1024 }; + await testGetThumbnail(done, testNum, dOp, size,); + }); + // ------------------------------audio type end-------------------------- + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/module.json new file mode 100755 index 0000000000000000000000000000000000000000..82fb1970953e8e320b149a3885c079feaf97b750 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/module.json @@ -0,0 +1,67 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] + } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_getThumbnail/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_getThumbnail/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_getThumbnail/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/multimedia/medialibrary/mediaLibrary_getThumbnail/signature/openharmony_sx.p7b differ diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/app.json b/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/app.json old mode 100644 new mode 100755 index 5139eaad5d5fd2e2de13b4970785d6fa8ae1a4ba..841282ae47b98590bdbc8aea744fbbcd178e9195 --- a/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/app.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/app.json @@ -1,21 +1,21 @@ -{ - "app":{ - "bundleName":"ohos.acts.multimedia.mediaLibrary", - "vendor":"huawei", - "versionCode":1000000, - "versionName":"1.0.0", - "debug":false, - "icon":"$media:icon", - "label":"$string:entry_MainAbility", - "description":"$string:mainability_description", - "distributedNotificationEnabled":true, - "keepAlive":true, - "singleUser":true, - "minAPIVersion":8, - "targetAPIVersion":8, - "car":{ - "apiCompatibleVersion":8, - "singleUser":false - } - } -} +{ + "app":{ + "bundleName":"ohos.acts.multimedia.mediaLibrary", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:entry_MainAbility", + "description":"$string:mainability_description", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/element/string.json old mode 100644 new mode 100755 index c1dee63527ae5e3c37f3736f6b68189e8df6f201..9b9d5b5e10c7ce74908c32b43d24568367b46d97 --- a/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/media/app_icon.png b/multimedia/medialibrary/mediaLibrary_js_standard/AppScope/resources/base/media/app_icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/BUILD.gn b/multimedia/medialibrary/mediaLibrary_js_standard/BUILD.gn old mode 100644 new mode 100755 index 4b12606708452a2ddae186b8427c32f96d6c0b5e..f2951e28ac2a4fd6061569b7ad04f9a7762ae72a --- a/multimedia/medialibrary/mediaLibrary_js_standard/BUILD.gn +++ b/multimedia/medialibrary/mediaLibrary_js_standard/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//test/xts/tools/build/suite.gni") diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/Test.json b/multimedia/medialibrary/mediaLibrary_js_standard/Test.json old mode 100644 new mode 100755 index 18fbadf3058fd390262311b7efcd43433feb9c19..868729d527d50c7ce4712ed14372457ae3530ab8 --- a/multimedia/medialibrary/mediaLibrary_js_standard/Test.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/Test.json @@ -1,67 +1,67 @@ -{ - "description": "Configuration for mediaLibrary Tests", - "driver": { - "type": "JSUnitTest", - "test-timeout": "600000", - "package": "ohos.acts.multimedia.mediaLibrary", - "shell-timeout": "600000" - }, - "kits": [ - { - "type": "ShellKit", - "pre-push": [ - ], - "run-command": [ - "rm -rf /storage/media/100/local/files/*", - "rm -rf /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/*", - "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", - "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "PushKit", - "pre-push": [ - ], - "push": [ - "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", - "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" - ] - }, - { - "type": "ShellKit", - "run-command": [ - "mkdir -pv /storage/media/100/local/files/Pictures/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic022,DeleteCb01,AblumInfo,DeletePro01,Dynamic03,Temp}", - "mkdir -pv /storage/media/100/local/files/Videos/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", - "mkdir -pv /storage/media/100/local/files/Audios/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", - "mkdir -pv /storage/media/100/local/files/Documents/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01}", - "for d in Static Album/Static Dynamic Dynamic01 Dynamic022 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", - "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", - "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", - "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); 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 DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;", - "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d ;done;", - "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d ;done;", - "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d ;done;", - - "chmod -R 777 /storage/media/100/local/files/*", - "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", - "hilog -Q pidoff", - "hilog -b D -D 0xD002B70", - "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "sleep 10", - "cem publish -e usual.event.SCREEN_OFF", - "sleep 10" - ] - }, - { - "test-file-name": [ - "ActsMediaLibraryJsTest.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] +{ + "description": "Configuration for mediaLibrary Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "600000", + "package": "ohos.acts.multimedia.mediaLibrary", + "shell-timeout": "600000" + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [ + ], + "run-command": [ + "rm -rf /storage/media/100/local/files/*", + "rm -rf /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/*", + "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", + "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", + "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mkdir -pv /storage/media/100/local/files/Pictures/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic022,DeleteCb01,AblumInfo,DeletePro01,Dynamic03,Temp}", + "mkdir -pv /storage/media/100/local/files/Videos/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", + "mkdir -pv /storage/media/100/local/files/Audios/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", + "mkdir -pv /storage/media/100/local/files/Documents/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01}", + "for d in Static Album/Static Dynamic Dynamic01 Dynamic022 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;", + "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", + "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", + "for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); 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 DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;", + "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d ;done;", + "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d ;done;", + "for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d ;done;", + + "chmod -R 777 /storage/media/100/local/files/*", + "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", + "hilog -Q pidoff", + "hilog -b D -D 0xD002B70", + "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", + "sleep 10", + "cem publish -e usual.event.SCREEN_OFF", + "sleep 10" + ] + }, + { + "test-file-name": [ + "ActsMediaLibraryJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/Application/AbilityStage.ts old mode 100644 new mode 100755 index 51cb02ba3f5c7011c1cd433d07deebd47a195704..14f230e140160dc5f94ecc462304621178f4cf64 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/Application/AbilityStage.ts +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/Application/AbilityStage.ts @@ -1,9 +1,9 @@ -import AbilityStage from "@ohos.application.AbilityStage" - -export default class MyAbilityStage extends AbilityStage { - onCreate() { - console.log("[Demo] MyAbilityStage onCreate") - globalThis.stageOnCreateRun = 1; - globalThis.stageContext = this.context; - } -} +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/MainAbility/MainAbility.ts old mode 100644 new mode 100755 index 2f9d6d1f23f95d9fc891fbc550cd5a589cfb6c89..72b03d747b3e2e8bdf18ea37c54c789bebb767bb --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,36 +1,36 @@ -import Ability from '@ohos.application.Ability' - -export default class MainAbility extends Ability { - onCreate(want,launchParam){ - // Ability is creating, initialize resources for this ability - console.log("[Demo] MainAbility onCreate") - globalThis.abilityWant = want; - } - - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("[Demo] MainAbility onDestroy") - } - - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("[Demo] MainAbility onWindowStageCreate") - globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) - } - - onWindowStageDestroy() { - //Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") - } - - onForeground() { - // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") - } - - onBackground() { - // Ability has back to background - console.log("[Demo] MainAbility onBackground") - } +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } }; \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/index/index.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/index/index.ets old mode 100644 new mode 100755 index b15b989b903b686d0e3766c5662235d1695b0193..578783ebc22394b888f6d961ce7ef6be4bd7a51f --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/index/index.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/index/index.ets @@ -1,68 +1,68 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import file from '@system.file'; - -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" -import testsuite from "../../test/List.test.ets" - - -@Entry -@Component -struct Index { - - aboutToAppear(){ - console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - const reportExtend = new ReportExtend(file) - - core.addService('report', reportExtend) - core.init() - core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - console.info('testsuite()---->') - testsuite(globalThis.abilityContext) - core.execute() - console.info('core.execute()---->') - } - - build() { - Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(25) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import file from '@system.file'; + +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import testsuite from "../../test/List.test.ets" + + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + const reportExtend = new ReportExtend(file) + + core.addService('report', reportExtend) + core.init() + core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + console.info('testsuite()---->') + testsuite(globalThis.abilityContext) + core.execute() + console.info('core.execute()---->') + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/second/second.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/second/second.ets old mode 100644 new mode 100755 index 1c1c727ff11ecc97909f482c35268db87ae23bb4..1f2a06b64cdadcc83027bb6797e24536a2c85757 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/second/second.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/pages/second/second.ets @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import router from '@system.router'; - -@Entry -@Component -struct Second { - private content: string = "Second Page" - - build() { - Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(`${this.content}`) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('back to index') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailCallBack.test.ets deleted file mode 100644 index b952f06ba92644ea8f5d327f5e862b17524dbf07..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailCallBack.test.ets +++ /dev/null @@ -1,869 +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 image from '@ohos.multimedia.image'; -import featureAbility from '@ohos.ability.featureAbility'; -import { - sleep, -} from '../../../../../../common'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -export default function FileAssetGetThumbnailCallBackTest(abilityContext){ - describe('FileAssetGetThumbnailCallBackTest', function () { - // image组件空调用避免image被优化 - image.createPixelMap(new ArrayBuffer(4096), {size:{height:1,width:2}}).then((pixelmap) =>{ - }); - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - let fileKeyObj = mediaLibrary.FileKey; - let imagetype = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - let imageFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [imagetype.toString()], - order: fileKeyObj.DATE_ADDED, - }; - let videoFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [videoType.toString()], - order: fileKeyObj.DATE_ADDED, - }; - let audioFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [audioType.toString()], - order: fileKeyObj.DATE_ADDED, - }; - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(async function () { await sleep(200)}); - afterAll(function () {}); - - // ------------------------------ image type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined){ - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_01 failed'); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_01 pixel image info ' + info); - console.info('MediaLibraryTest : 001_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_01 pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_01 failed'); - done(); - } - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined) { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_02 failed'); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_02 pixel image info ' + info); - console.info('MediaLibraryTest : 001_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_02 failed'); - done(); - } - } - }); - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - asset.getThumbnail(async (err,pixelmap) => { - if(pixelmap == undefined) { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_03 failed'); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_03 pixel image info ' + info); - console.info('MediaLibraryTest : 001_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_03 failed'); - done(); - } - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined) { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_04 failed'); - done(); - } else{ - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_04 pixel image info ' + info); - console.info('MediaLibraryTest : 001_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_04 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_04 failed'); - done(); - } - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined) { - expect(true).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_05 pixel image info ' + info); - console.info('MediaLibraryTest : 001_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_05 pixel height ' + info.size.height); - expect(info.size.width == size.width || info.size.height == size.height).assertFalse(); - console.info('MediaLibraryTest : getFileAssets 001_05 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_05 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined) { - expect(true).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_06 pixel image info ' + info); - console.info('MediaLibraryTest : 001_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_06 pixel height ' + info.size.height); - expect(info.size.width == size.width || info.size.height == size.height).assertFalse(); - console.info('MediaLibraryTest : getThumbnail 001_06 failed'); - done(); - } - }); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_06 failed '); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - asset.getThumbnail(size,async (err, pixelmap) => { - if(pixelmap == undefined) { - expect(false).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_07 failed'); - done(); - } - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------image type end-------------------------- - - // ------------------------------video type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_01 pixel image info ' + info); - console.info('MediaLibraryTest : 002_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_01 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_01 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_02 pixel image info ' + info); - console.info('MediaLibraryTest : 002_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_02 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - asset.getThumbnail(async (err, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail 002_03 Successfull ' + pixelmap); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_03 pixel image info ' + info); - console.info('MediaLibraryTest : 002_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_03 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_04 pixel image info ' + info); - console.info('MediaLibraryTest : 002_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_05 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_05 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - asset.getThumbnail(size, async (err, pixelmap) => { - if(pixelmap == undefined) { - console.info('MediaLibraryTest : getThumbnail 002_05 passed'); - expect(true).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_05 pixel image info ' + info); - console.info('MediaLibraryTest : 002_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_05 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 002_05 failed'); - expect(false).assertTrue(); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_05 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - const pixelmap = await asset.getThumbnail(size, async (err, pixelmap) => { - if(pixelmap ==undefined) { - console.info('MediaLibraryTest : getThumbnail 002_06 passed'); - expect(true).assertTrue(); - done(); - }else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_06 pixel image info ' + info); - console.info('MediaLibraryTest : 002_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_06 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 003_01 failed'); - expect(false).assertTrue(); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_06 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_07 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------video type end-------------------------- - - // ------------------------------audio type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_01 pixel image info ' + info); - console.info('MediaLibraryTest : 003_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_01 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_01 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_02 pixel image info ' + info); - console.info('MediaLibraryTest : 003_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_02 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - asset.getThumbnail(async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_03 pixel image info ' + info); - console.info('MediaLibraryTest : 003_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_03 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_04 pixel image info ' + info); - console.info('MediaLibraryTest : 003_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_04 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_04 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - asset.getThumbnail(size, async (err, pixelmap) => { - if(pixelmap ==undefined) { - console.info('MediaLibraryTest : getThumbnail 003_05 passed'); - expect(true).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : getThumbnail 003_06 failed'); - console.info('MediaLibraryTest : 003_05 pixel image info ' + info); - console.info('MediaLibraryTest : 003_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_05 pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_05 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - asset.getThumbnail(size, async (err, pixelmap) => { - if(pixelmap ==undefined) { - console.info('MediaLibraryTest : getThumbnail 003_06 passed'); - expect(true).assertTrue(); - done(); - } else { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 003_06 failed'); - - expect(false).assertTrue(); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_06 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - asset.getThumbnail(size, async (err, pixelmap) => { - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_07 failed'); - done(); - } - }); - - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------audio type end-------------------------- - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailPromise.test.ets deleted file mode 100644 index 06dc79909d6f418e3eb811eb2a8c7eb148655a77..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/FileAssetGetThumbnailPromise.test.ets +++ /dev/null @@ -1,767 +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 image from '@ohos.multimedia.image'; -import featureAbility from '@ohos.ability.featureAbility'; - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, -} from '../../../../../../common'; -export default function FileAssetGetThumbnailPromiseTest(abilityContext){ - describe('FileAssetGetThumbnailPromiseTest', function () { - // image组件空调用避免image被优化 - image.createPixelMap(new ArrayBuffer(4096), {size:{height:1,width:2}}).then((pixelmap) =>{ - }); - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - let fileKeyObj = mediaLibrary.FileKey; - let imagetype = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - let imageFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [imagetype.toString()], - order: fileKeyObj.DATE_ADDED, - }; - let videoFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [videoType.toString()], - order: fileKeyObj.DATE_ADDED, - }; - let audioFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [audioType.toString()], - order: fileKeyObj.DATE_ADDED, - }; - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(async function () { await sleep(200)}); - afterAll(function () {}); - - // ------------------------------ image type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_01 pixel image info ' + info); - console.info('MediaLibraryTest : 001_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_01 pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_01 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_02 pixel image info ' + info); - console.info('MediaLibraryTest : 001_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_02 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - const pixelmap = await asset.getThumbnail(); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_03 pixel image info ' + info); - console.info('MediaLibraryTest : 001_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_03 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_04 pixel image info ' + info); - console.info('MediaLibraryTest : 001_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_04 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_04 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_05 pixel image info ' + info); - console.info('MediaLibraryTest : 001_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_05 pixel height ' + info.size.height); - expect(false).assertTrue(); - console.info('MediaLibraryTest : getFileAssets 001_05 failed'); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_05 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 001_06 pixel image info ' + info); - console.info('MediaLibraryTest : 001_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 001_06 pixel height ' + info.size.height); - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_06 failed'); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 001_06 passed '); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_07 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 001_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------image type end-------------------------- - - // ------------------------------video type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_01 pixel image info ' + info); - console.info('MediaLibraryTest : 002_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_01 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_01 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_02 pixel image info ' + info); - console.info('MediaLibraryTest : 002_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_02 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - const pixelmap = await asset.getThumbnail(); - console.info('MediaLibraryTest : getThumbnail 002_03 Successfull ' + pixelmap); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_03 pixel image info ' + info); - console.info('MediaLibraryTest : 002_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_03 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_04 pixel image info ' + info); - console.info('MediaLibraryTest : 002_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_05 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 001_05 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_05 pixel image info ' + info); - console.info('MediaLibraryTest : 002_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_05 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 002_05 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_05 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 002_06 pixel image info ' + info); - console.info('MediaLibraryTest : 002_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 002_06 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 003_01 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_06 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 002_07 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 002_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------video type end-------------------------- - - // ------------------------------audio type start ----------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_01 pixel image info ' + info); - console.info('MediaLibraryTest : 003_01 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_01 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_01 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_01 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_01 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 128, height: 256 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_02 pixel image info ' + info); - console.info('MediaLibraryTest : 003_02 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_02 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_02 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_02 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_02 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by no arg - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 256, height: 256 }; - const pixelmap = await asset.getThumbnail(); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_03 pixel image info ' + info); - console.info('MediaLibraryTest : 003_03 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_03 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_03 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_03 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_03 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1, height: 1 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_04 pixel image info ' + info); - console.info('MediaLibraryTest : 003_04 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_04 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_04 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_04 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_04 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 0, height: 0 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : getThumbnail 003_06 failed'); - console.info('MediaLibraryTest : 003_05 pixel image info ' + info); - console.info('MediaLibraryTest : 003_05 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_05 pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_05 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: -128, height: -128 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - console.info('MediaLibraryTest : getThumbnail 003_06 failed'); - - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_06 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioFetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset = dataList[0]; - let size = { width: 1024, height: 1024 }; - const pixelmap = await asset.getThumbnail(size); - const info = await pixelmap.getImageInfo(); - console.info('MediaLibraryTest : 003_06 pixel image info ' + info); - console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); - console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); - if (info.size.width == size.width && info.size.height == size.height) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_07 passed'); - done(); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : getThumbnail 003_07 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : getThumbnail 003_07 failed ' + error.message); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------audio type end-------------------------- - }); -} - 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 old mode 100644 new mode 100755 index 5d3a829d881a8b4f0e6ac1096f8eb32b252f3095..139c43ebc9d0bdcb15ab1f27da0bf207f92f2377 --- 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 @@ -1,49 +1,31 @@ -/* - * 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 getPermissionTest from './getPermission.test.ets' -import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets' -import FileAssetGetThumbnailCallBackTest from './FileAssetGetThumbnailCallBack.test.ets' -import FileAssetGetThumbnailPromiseTest from './FileAssetGetThumbnailPromise.test.ets' -import fileAssetPromise2Test from './fileAssetPromise2.test.ets' -import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets' -import fileAssetTestPromiseTest from './fileAssetTestPromise.test.ets' -import fileAssetUriTestCallBackTest from './fileAssetUriTestCallBack.test.ets' -import fileAssetUriTestPromiseTest from './fileAssetUriTestPromise.test.ets' -import filekeyTestCallBackTest from './filekeyTestCallBack.test.ets' -import filekeyTestPromiseTest from './filekeyTestPromise.test.ets' -import fileTestCallBackTest from './fileTestCallBack.test.ets' -import fileTestPromiseTest from './fileTestPromise.test.ets' -import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets' -import mediaLibraryTestPromiseTest from './mediaLibraryTestPromise.test.ets' -import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' - -export default function testsuite(abilityContext) { - getPermissionTest() - fileAssetCallBack2Test(abilityContext) - FileAssetGetThumbnailCallBackTest(abilityContext) - FileAssetGetThumbnailPromiseTest(abilityContext) - fileAssetPromise2Test(abilityContext) - fileAssetTestCallbackTest(abilityContext) - fileAssetTestPromiseTest(abilityContext) - fileAssetUriTestCallBackTest(abilityContext) - fileAssetUriTestPromiseTest(abilityContext) - filekeyTestCallBackTest(abilityContext) - filekeyTestPromiseTest(abilityContext) - fileTestCallBackTest(abilityContext) - fileTestPromiseTest(abilityContext) - mediaLibraryTestCallBackTest(abilityContext) - mediaLibraryTestPromiseTest(abilityContext) - mediaLibraryTestPromiseOnOffTest(abilityContext) -} +/* + * 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 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' +import mediaLibraryTestPromiseTest from './mediaLibraryTestPromise.test.ets' +import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' + +export default function testsuite(abilityContext) { + getPermissionTest() + fileAssetCallBack2Test(abilityContext) + fileAssetTestCallbackTest(abilityContext) + fileTestCallBackTest(abilityContext) + mediaLibraryTestCallBackTest(abilityContext) + mediaLibraryTestPromiseTest(abilityContext) + mediaLibraryTestPromiseOnOffTest(abilityContext) +} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/MediaScannerFrameWork1.0.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/MediaScannerFrameWork1.0.test.ets old mode 100644 new mode 100755 index 4d54e324c0159eeaab70fa6d104a06b36315e506..9c9edaa11e24fd67dd39cf9496d45307905eb891 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/MediaScannerFrameWork1.0.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/MediaScannerFrameWork1.0.test.ets @@ -1,1260 +1,1260 @@ -/* - * 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - - -describe('GET_MEDIA_AUDIO_VIDEO_IMAGE_ALBUM.test.js', function () { -console.info("MediaLibraryTest : mediaLibrary Instance before"); - -const context = featureAbility.getContext(); -const media = mediaLibrary.getMediaLibrary(context); - -//const media = mediaLibrary.getMediaLibrary(); -let scannerObj = mediaLibrary.getScannerInstance(); -console.info("MediaLibraryTest :mediaLibrary Instance after"); -let path = "/storage/media/local/files/" - -beforeAll(function () { -//onsole.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); - -}) - -beforeEach(function () { -//console.info('MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); - -}) -afterEach(function () { -//console.info('MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); - -}) -afterAll(function () { -//console.info('MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_DIR_PUBLIC_DIRECTORY_EMPTY_001 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - -it('SUB_SCANNER_CB_SCAN_DIR_PUBLIC_DIRECTORY_EMPTY_001', 0, async function (done) { - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest :MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(path,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN PUBLIC DIRECOTY IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : 001_SUB_MEDIA_MEDIALIBRARY_SCAN_DIR_DATA_MEDIA : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : 001_SUB_MEDIA_MEDIALIBRARY_SCAN_DIR_DATA_MEDIA : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002', 0, async function (done) { - console.info('MediaLibraryTest : create Image album (jpg)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "image.jpg", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN IMAGE ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "audio.mp3", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN AUDIO ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004', 0, async function (done) { - console.info('MediaLibraryTest : create Video album (MP4)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - let mediaType = mediaLibrary.MediaType.VIDEO; - await media.createAsset(mediaType, "video.mp4", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanVideoAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanVideoAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN VIDEO ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_DOC_ALBUM_005', 0, async function (done) { - console.info('MediaLibraryTest : create doc album (txt)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); - let mediaType = mediaLibrary.MediaType.FILE; - await media.createAsset(mediaType, "Doc.txt", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanDocAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanDocAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN DOC ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - - - - /* * - * @tc.number : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_NONEXISTING_ALBUM_009', 0, async function (done) { - let modifiedAlbumPath = "Pictures/NONEXISTING/"; - await sleep(1000); - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(modifiedAlbumPath,async (err, data) => { - if (data == undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN OF NON EXISTING ALBUM IS UNSUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 : PASS'); - } else { - console.info('MediaLibraryTest : status is '+ data.status); - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - - /* * - * @tc.number : SUB_SCANNER_CB_UNICODE_ALBUM_010 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_SCANNER_CB_UNICODE_ALBUM_010', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"来自于华为公司/").then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_UNICODE_ALBUM_010 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_UNICODE_ALBUM_010 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - - }) - - /* * - * @tc.number : SUB_SCANNER_CB_CANONICAL_ALBUM_011 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_CANONICAL_ALBUM_011', 0, async function (done) { - console.info('MediaLibraryTest : create Image album (jpg)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"1/2/3/4/").then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/"+path1+"../../../../" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Image album (jpg) SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_CANONICAL_ALBUM_011 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_CANONICAL_ALBUM_011 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - -/* * - * @tc.number : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012', 0, async function (done) { - let nonPublicDirectoryPath = "/data/media" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest :MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(nonPublicDirectoryPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - if (data.status != 0){ - console.info('MediaLibraryTest : SCAN NON PUBLIC DIRECOTY IS UNSUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : PASS'); - }else{ - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : FAIL'); - } - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - -it('SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013', 0, async function (done) { - console.info('MediaLibraryTest : create Image album (jpg)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "Scan_image_01.jpg", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Image album (jpg) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014', 0, async function (done) { - console.info('MediaLibraryTest : create Image album (png)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "Scan_image_02.png", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Image album (png) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (AAC)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "audio.aac", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN AUDIO ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (FLAC)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "audio.flac", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (FLAC) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (WAV)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "audio.wav", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (WAV) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "scan_audio.MP3", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (OGG)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "audio.0GG", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (OGG) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020', 0, async function (done) { - console.info('MediaLibraryTest : create Video album (MP4)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - let mediaType = mediaLibrary.MediaType.VIDEO; - await media.createAsset(mediaType, "scan_video.mp4", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanVideoAlbumPath = "/storage/media/100/local/files/"+path1 - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanVideoAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Video album (MP4) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_DOC_FILE_021 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_DOC_FILE_021', 0, async function (done) { - console.info('MediaLibraryTest : create doc album (txt)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); - let mediaType = mediaLibrary.MediaType.FILE; - await media.createAsset(mediaType, "Scan_Doc.txt", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanDocAlbumPath = "/storage/media/100/local/files/Documents/Scan_Doc.txt" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanDocAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN doc album (txt) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_FILE_021 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_FILE_021 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "open_close_scan_audio.mp3", path1).then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - asset.open('rw', (openError, fd) => { - console.info("MediaLibraryTest :openAsset successfully:"); - if(fd > 0){ - asset.close(fd); - console.info("MediaLibraryTest :closeAsset successfully:"); - }else{ - console.info('MediaLibraryTest :File Open Failed!' + openError); - } - }); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - - let scanAudioAlbumPath = "/storage/media/100/local/files/Music/open_close_scan_audio.mp3" - if (scannerObj == null || scannerObj == undefined) { - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanFile(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : status is ' + data.status); - console.info('MediaLibraryTest : status is ' + data.fileUri); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 : PASS'); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : scandfile has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 : FAIL'); - } - await sleep (10000); - done(); - }); - await sleep (10000); - done(); - } - await sleep (10000); - done(); - }) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_EMPTY_PATH_025', 0, async function (done) { - console.info('MediaLibraryTest : starting of scan file'); - let audioAlbumPath = ""; - if (scannerObj == null || scannerObj == undefined) { - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanFile(audioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is ' + data.status); - if (data.status == 1){ - expect(true).assertTrue(); - console.info('MediaLibraryTest : status is ' + data.fileUri); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : PASS'); - }else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : scandfile has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : FAIL'); - } - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : scandfile has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : FAIL'); - } - await sleep (10000); - done(); - }); - await sleep (10000); - done(); - } - await sleep (10000); - done(); - }) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026', 0, async function (done) { - console.info('MediaLibraryTest : starting of scan file'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let audioAlbumPath = path1+"/NONEXISTING.aac"; - if (scannerObj == null || scannerObj == undefined) { - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanFile(audioAlbumPath,async (err, data) => { - if (data != undefined) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : status is ' + data.status); - console.info('MediaLibraryTest : status is ' + data.fileUri); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 : PASS'); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : scandfile has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 : FAIL'); - } - await sleep (10000); - done(); - }); - await sleep (10000); - done(); - } - await sleep (10000); - done(); -}) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3 unicode)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - let mediaType = mediaLibrary.MediaType.AUDIO; - await media.createAsset(mediaType, "来自于华为公司_1.MP3", path1+"/来自于华为公司_1").then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/Music/来自于华为公司_1"+"/来自于华为公司_1.MP3" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - if (data.status == -1) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (MP3 unicode) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : FAIL'); - } - - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028', 0, async function (done) { - console.info('MediaLibraryTest : create Audio album (MP3)'); - let scanAudioAlbumPath = "/storage/media/100/local/files/Music/audio.mp3" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - - /* * - * @tc.number : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - - it('SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029', 0, async function (done) { - console.info('MediaLibraryTest : create Image album (JPG)'); - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - let mediaType = mediaLibrary.MediaType.IMAGE; - await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"1/2/3/4/").then (function (asset) { - console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); - }).catch(function(err){ - console.info("MediaLibraryTest :createAsset failed with error:"+ err); - }); - await sleep(1000); - let scanImageAlbumPath = "/storage/media/100/local/files/Pictures/1/2/3/4/../../../../image.jpg" - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanFile(scanImageAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN Image album (JPG) SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); - }) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 - * @tc.name : CreateAlbum-->ModifyAlbum - * @tc.desc : CreateAlbum-->ModifyAlbum - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006', 0, async function (done) { - let allTypefetchOp = { - selections: '', - selectionArgs: [], - }; - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName); - const newName = 'newhello'; - console.info('#############MediaLibraryTest : original album name is '+ album.albumName); - album.albumName = newName; - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let passed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_01 passed'); - expect(true).assertTrue(); - done(); - passed = true; - } - } - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error); - } - done(); - let modifiedAlbumPath = "/storage/media/100/local/files/"+"newhello"; - await sleep(1000); - console.info('MediaLibraryTest : starting of scan dir'); - if (scannerObj == null || scannerObj == undefined){ - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanDir(modifiedAlbumPath,async (err, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : status is '+ data.status); - console.info('MediaLibraryTest : SCAN MODIFED ALBUM IS SUCCESSFULL'); - expect(true).assertTrue(); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 : PASS'); - } else { - expect(true).assertfalse(); - console.info('MediaLibraryTest : scandir has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 : FAIL'); - } - await sleep (10000); - done(); - }); - } - await sleep(1000); - done(); -}) - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - -it('SUB_SCANNER_CB_SCAN_AUDIO_MP4_AFTER_MODIFY_022', 0, async function (done) { - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.VIDEO; - let imagesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - }; - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - console.info('##################MediaLibraryTest : ASSET is ' + asset); - console.info('##################MediaLibraryTest : ASSET Title is ' + asset.title); - console.info('##################MediaLibraryTest : ASSET Title is ' + asset.id); - const newTitle = 'newTitle'; - asset.title = newTitle; - const id = asset.id; - await asset.commitModify(); - - //const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult.getAllObject(); - let passed = false; - for (let i = 0; i < dataList.length; i++) { - const asset = dataList[i]; - if (asset.id == id && asset.title == newTitle) { - passed = true; - break; - } - } - done(); - } catch (error) { - console.info('FileAsset commitModify 002 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - await sleep(1000); - let scanAudioAlbumPath = "/storage/media/100/local/files/Movies/newTitle.mp4" - if (scannerObj == null || scannerObj == undefined) { - console.info('MediaLibraryTest : Error sannerObj is null'); - } else { - scannerObj.scanFile(scanAudioAlbumPath,async (err, data) => { - if (data != undefined) { - expect(true).assertTrue(); - console.info('MediaLibraryTest : status is ' + data.status); - console.info('MediaLibraryTest : status is ' + data.fileUri); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 : PASS'); - } else { - expect(false).assertTrue(); - console.info('MediaLibraryTest : scandfile has an error'); - console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 : FAIL'); - } - await sleep (10000); - done(); - }); - await sleep (10000); - done(); - } - await sleep (10000); - done(); - -}); - -function sleep (ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_DELETE_ALBUM_007[MANUAL TEST] - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_MODIFY_DELETE_ALBUM_008[MANUAL TEST] - * @tc.name : CreateAlbum-->ModifyAlbum-->DeleteAlbum-->Scan - * @tc.desc : CreateAlbum-->ModifyAlbum-->DeleteAlbum-->Scan - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - -/* * - * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_DELETE_023 [Manual test] - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + + +describe('GET_MEDIA_AUDIO_VIDEO_IMAGE_ALBUM.test.js', function () { +console.info("MediaLibraryTest : mediaLibrary Instance before"); + +const context = featureAbility.getContext(); +const media = mediaLibrary.getMediaLibrary(context); + +//const media = mediaLibrary.getMediaLibrary(); +let scannerObj = mediaLibrary.getScannerInstance(); +console.info("MediaLibraryTest :mediaLibrary Instance after"); +let path = "/storage/media/local/files/" + +beforeAll(function () { +//onsole.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + +}) + +beforeEach(function () { +//console.info('MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); + +}) +afterEach(function () { +//console.info('MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + +}) +afterAll(function () { +//console.info('MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_DIR_PUBLIC_DIRECTORY_EMPTY_001 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + +it('SUB_SCANNER_CB_SCAN_DIR_PUBLIC_DIRECTORY_EMPTY_001', 0, async function (done) { + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest :MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(path,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN PUBLIC DIRECOTY IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : 001_SUB_MEDIA_MEDIALIBRARY_SCAN_DIR_DATA_MEDIA : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : 001_SUB_MEDIA_MEDIALIBRARY_SCAN_DIR_DATA_MEDIA : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002', 0, async function (done) { + console.info('MediaLibraryTest : create Image album (jpg)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "image.jpg", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN IMAGE ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_ALBUM_002 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "audio.mp3", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN AUDIO ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_ALBUM_003 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004', 0, async function (done) { + console.info('MediaLibraryTest : create Video album (MP4)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + let mediaType = mediaLibrary.MediaType.VIDEO; + await media.createAsset(mediaType, "video.mp4", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanVideoAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanVideoAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN VIDEO ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_ALBUM_004 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_DOC_ALBUM_005', 0, async function (done) { + console.info('MediaLibraryTest : create doc album (txt)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); + let mediaType = mediaLibrary.MediaType.FILE; + await media.createAsset(mediaType, "Doc.txt", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanDocAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanDocAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN DOC ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_ALBUM_005 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + + + + /* * + * @tc.number : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_NONEXISTING_ALBUM_009', 0, async function (done) { + let modifiedAlbumPath = "Pictures/NONEXISTING/"; + await sleep(1000); + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(modifiedAlbumPath,async (err, data) => { + if (data == undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN OF NON EXISTING ALBUM IS UNSUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 : PASS'); + } else { + console.info('MediaLibraryTest : status is '+ data.status); + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_NONEXISTING_ALBUM_009 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + + /* * + * @tc.number : SUB_SCANNER_CB_UNICODE_ALBUM_010 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_SCANNER_CB_UNICODE_ALBUM_010', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"来自于华为公司/").then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_UNICODE_ALBUM_010 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_UNICODE_ALBUM_010 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + + }) + + /* * + * @tc.number : SUB_SCANNER_CB_CANONICAL_ALBUM_011 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_CANONICAL_ALBUM_011', 0, async function (done) { + console.info('MediaLibraryTest : create Image album (jpg)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"1/2/3/4/").then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/"+path1+"../../../../" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Image album (jpg) SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_CANONICAL_ALBUM_011 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_CANONICAL_ALBUM_011 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + +/* * + * @tc.number : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012', 0, async function (done) { + let nonPublicDirectoryPath = "/data/media" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest :MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(nonPublicDirectoryPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + if (data.status != 0){ + console.info('MediaLibraryTest : SCAN NON PUBLIC DIRECOTY IS UNSUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : PASS'); + }else{ + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : FAIL'); + } + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_NON_PUBLIC_DIRECTORY_012 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + +it('SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013', 0, async function (done) { + console.info('MediaLibraryTest : create Image album (jpg)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "Scan_image_01.jpg", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Image album (jpg) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_JPG_FILE_013 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014', 0, async function (done) { + console.info('MediaLibraryTest : create Image album (png)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "Scan_image_02.png", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Image album (png) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_IMAGE_PNG_FILE_014 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (AAC)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "audio.aac", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN AUDIO ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_AAC_FILE_015 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (FLAC)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "audio.flac", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (FLAC) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_FLAC_FILE_016 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (WAV)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "audio.wav", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (WAV) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_WAV_FILE_017 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "scan_audio.MP3", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_FILE_018 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (OGG)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "audio.0GG", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (OGG) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_OGG_FILE_019 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020', 0, async function (done) { + console.info('MediaLibraryTest : create Video album (MP4)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + let mediaType = mediaLibrary.MediaType.VIDEO; + await media.createAsset(mediaType, "scan_video.mp4", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanVideoAlbumPath = "/storage/media/100/local/files/"+path1 + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanVideoAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Video album (MP4) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_VIDEO_MP4_FILE_020 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_DOC_FILE_021 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_DOC_FILE_021', 0, async function (done) { + console.info('MediaLibraryTest : create doc album (txt)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOCUMENTS); + let mediaType = mediaLibrary.MediaType.FILE; + await media.createAsset(mediaType, "Scan_Doc.txt", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanDocAlbumPath = "/storage/media/100/local/files/Documents/Scan_Doc.txt" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanDocAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN doc album (txt) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_FILE_021 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_DOC_FILE_021 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "open_close_scan_audio.mp3", path1).then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + asset.open('rw', (openError, fd) => { + console.info("MediaLibraryTest :openAsset successfully:"); + if(fd > 0){ + asset.close(fd); + console.info("MediaLibraryTest :closeAsset successfully:"); + }else{ + console.info('MediaLibraryTest :File Open Failed!' + openError); + } + }); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + + let scanAudioAlbumPath = "/storage/media/100/local/files/Music/open_close_scan_audio.mp3" + if (scannerObj == null || scannerObj == undefined) { + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanFile(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : status is ' + data.status); + console.info('MediaLibraryTest : status is ' + data.fileUri); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 : PASS'); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : scandfile has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_OPEN_CLOSE_024 : FAIL'); + } + await sleep (10000); + done(); + }); + await sleep (10000); + done(); + } + await sleep (10000); + done(); + }) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_EMPTY_PATH_025', 0, async function (done) { + console.info('MediaLibraryTest : starting of scan file'); + let audioAlbumPath = ""; + if (scannerObj == null || scannerObj == undefined) { + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanFile(audioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is ' + data.status); + if (data.status == 1){ + expect(true).assertTrue(); + console.info('MediaLibraryTest : status is ' + data.fileUri); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : PASS'); + }else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : scandfile has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : FAIL'); + } + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : scandfile has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_EMPTY_PATH_025 : FAIL'); + } + await sleep (10000); + done(); + }); + await sleep (10000); + done(); + } + await sleep (10000); + done(); + }) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026', 0, async function (done) { + console.info('MediaLibraryTest : starting of scan file'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let audioAlbumPath = path1+"/NONEXISTING.aac"; + if (scannerObj == null || scannerObj == undefined) { + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanFile(audioAlbumPath,async (err, data) => { + if (data != undefined) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : status is ' + data.status); + console.info('MediaLibraryTest : status is ' + data.fileUri); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 : PASS'); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : scandfile has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_NONEXISTING_PATH_026 : FAIL'); + } + await sleep (10000); + done(); + }); + await sleep (10000); + done(); + } + await sleep (10000); + done(); +}) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3 unicode)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + let mediaType = mediaLibrary.MediaType.AUDIO; + await media.createAsset(mediaType, "来自于华为公司_1.MP3", path1+"/来自于华为公司_1").then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/Music/来自于华为公司_1"+"/来自于华为公司_1.MP3" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + if (data.status == -1) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (MP3 unicode) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : FAIL'); + } + + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_UNICODE_PATH_AND_FILE_027 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028', 0, async function (done) { + console.info('MediaLibraryTest : create Audio album (MP3)'); + let scanAudioAlbumPath = "/storage/media/100/local/files/Music/audio.mp3" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Audio album (MP3) IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_SAME_FILE_AGAIN_028 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + + /* * + * @tc.number : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + it('SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029', 0, async function (done) { + console.info('MediaLibraryTest : create Image album (JPG)'); + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + let mediaType = mediaLibrary.MediaType.IMAGE; + await media.createAsset(mediaType, "image_UNICODE.jpg", path1+"1/2/3/4/").then (function (asset) { + console.info("MediaLibraryTest :createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("MediaLibraryTest :createAsset failed with error:"+ err); + }); + await sleep(1000); + let scanImageAlbumPath = "/storage/media/100/local/files/Pictures/1/2/3/4/../../../../image.jpg" + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanFile(scanImageAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN Image album (JPG) SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_CANONICAL_PATH_FILE_AGAIN_029 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); + }) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 + * @tc.name : CreateAlbum-->ModifyAlbum + * @tc.desc : CreateAlbum-->ModifyAlbum + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006', 0, async function (done) { + let allTypefetchOp = { + selections: '', + selectionArgs: [], + }; + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName); + const newName = 'newhello'; + console.info('#############MediaLibraryTest : original album name is '+ album.albumName); + album.albumName = newName; + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let passed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_01 passed'); + expect(true).assertTrue(); + done(); + passed = true; + } + } + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error); + } + done(); + let modifiedAlbumPath = "/storage/media/100/local/files/"+"newhello"; + await sleep(1000); + console.info('MediaLibraryTest : starting of scan dir'); + if (scannerObj == null || scannerObj == undefined){ + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanDir(modifiedAlbumPath,async (err, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : status is '+ data.status); + console.info('MediaLibraryTest : SCAN MODIFED ALBUM IS SUCCESSFULL'); + expect(true).assertTrue(); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 : PASS'); + } else { + expect(true).assertfalse(); + console.info('MediaLibraryTest : scandir has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_MODIFIED_ALBUM_006 : FAIL'); + } + await sleep (10000); + done(); + }); + } + await sleep(1000); + done(); +}) + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + +it('SUB_SCANNER_CB_SCAN_AUDIO_MP4_AFTER_MODIFY_022', 0, async function (done) { + let fileKeyObj = mediaLibrary.FileKey; + let imageType = mediaLibrary.MediaType.VIDEO; + let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], + }; + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + console.info('##################MediaLibraryTest : ASSET is ' + asset); + console.info('##################MediaLibraryTest : ASSET Title is ' + asset.title); + console.info('##################MediaLibraryTest : ASSET Title is ' + asset.id); + const newTitle = 'newTitle'; + asset.title = newTitle; + const id = asset.id; + await asset.commitModify(); + + //const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.title == newTitle) { + passed = true; + break; + } + } + done(); + } catch (error) { + console.info('FileAsset commitModify 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + await sleep(1000); + let scanAudioAlbumPath = "/storage/media/100/local/files/Movies/newTitle.mp4" + if (scannerObj == null || scannerObj == undefined) { + console.info('MediaLibraryTest : Error sannerObj is null'); + } else { + scannerObj.scanFile(scanAudioAlbumPath,async (err, data) => { + if (data != undefined) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : status is ' + data.status); + console.info('MediaLibraryTest : status is ' + data.fileUri); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 : PASS'); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : scandfile has an error'); + console.info('MediaLibraryTest : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_MODIFY_022 : FAIL'); + } + await sleep (10000); + done(); + }); + await sleep (10000); + done(); + } + await sleep (10000); + done(); + +}); + +function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_DELETE_ALBUM_007[MANUAL TEST] + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_MODIFY_DELETE_ALBUM_008[MANUAL TEST] + * @tc.name : CreateAlbum-->ModifyAlbum-->DeleteAlbum-->Scan + * @tc.desc : CreateAlbum-->ModifyAlbum-->DeleteAlbum-->Scan + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + +/* * + * @tc.number : SUB_SCANNER_CB_SCAN_AUDIO_MP3_AFTER_DELETE_023 [Manual test] + * @tc.name : + * @tc.desc : + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + + +}) + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestCallBack.test.ets old mode 100644 new mode 100755 index 7c173874d9c7dfda85fe4fbec4090de52e4a46c4..217f4f744857daa1247d9b43db8aa0f5e36a5759 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestCallBack.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestCallBack.test.ets @@ -1,426 +1,426 @@ -/* - * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, -} from '../../../../../../common'; -describe('file.callback.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - beforeAll(function () { - console.info('File Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); - }); - beforeEach(function () { - console.info('File Callback MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); - }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { - console.info('File Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01 - * @tc.name : favorite - * @tc.desc : favorite by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image01.jpg', path); - asset.favorite(true, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02 - * @tc.name : favorite - * @tc.desc : favorite by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image02.jpg', path); - asset.favorite(false, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03 - * @tc.name : favorite - * @tc.desc : favorite by 666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image03.jpg', path); - asset.favorite(666, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 success'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 fail, message = ' + err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04 - * @tc.name : favorite - * @tc.desc : favorite by '666' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image04.jpg', path); - asset.favorite('666', (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 success'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 fail, message = ' + err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05 - * @tc.name : favorite - * @tc.desc : favorite by 0.666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image05.jpg', path); - asset.favorite(0.666, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 success'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 fail, message = ' + err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06 - * @tc.name : favorite - * @tc.desc : favorite by null - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image06.jpg', path); - asset.favorite(null, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 success'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 fail, message = ' + err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01 - * @tc.name : isFavorite - * @tc.desc : Is Favourite true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image07.jpg', path); - await asset.favorite(true); - asset.isFavorite((err, isFavorite) => { - if (err == undefined && isFavorite == true) { - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 isFavorite = ' + isFavorite); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02 - * @tc.name : isFavorite - * @tc.desc : Is Favourite true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image0702.jpg', path); - await asset.favorite(false); - asset.isFavorite((err, isFavorite) => { - if (err == undefined && isFavorite == false) { - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 isFavorite = ' + isFavorite); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01 - * @tc.name : trash - * @tc.desc : Trash by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image08.jpg', path); - asset.trash(true, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01 fail ,message = ', err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02 - * @tc.name : trash - * @tc.desc : Trash by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image09.jpg', path); - asset.trash(false, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02 fail ,message = ', err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03 - * @tc.name : trash - * @tc.desc : Trash by 666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image10.jpg', path); - asset.trash(666, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03 fail ,message = ', err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04 - * @tc.name : trash - * @tc.desc : Trash by '666' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image11.jpg', path); - asset.trash('666', (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04 fail ,message = ', err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05 - * @tc.name : trash - * @tc.desc : Trash by 0.666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image12.jpg', path); - asset.trash(0.666, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05 fail ,message = ', err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06 - * @tc.name : trash - * @tc.desc : Trash by null - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image13.jpg', path); - asset.trash(null, (err) => { - if (err == undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06'); - expect(false).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06 fail ,message = ', err); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01 - * @tc.name : isTrash - * @tc.desc : isTrash true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image14.jpg', path); - await asset.trash(true); - asset.isTrash((err, isTrash) => { - if (err == undefined && isTrash == true) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01 fail ,message = ', err); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02 - * @tc.name : isTrash - * @tc.desc : isTrash false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02', 0, async function (done) { - const asset = await media.createAsset(mediaType, 'image15.jpg', path); - await asset.trash(false); - asset.isTrash((err, isTrash) => { - if (err == undefined && isTrash == false) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02 fail ,message = ', err); - expect(false).assertTrue(); - done(); - } - }); - }); -}); +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, +} from '../../../../../../common'; +describe('file.callback.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + beforeAll(function () { + console.info('File Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); + beforeEach(function () { + console.info('File Callback MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(async function () { await sleep(200)}); + afterAll(function () { + console.info('File Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01 + * @tc.name : favorite + * @tc.desc : favorite by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image01.jpg', path); + asset.favorite(true, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02 + * @tc.name : favorite + * @tc.desc : favorite by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image02.jpg', path); + asset.favorite(false, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03 + * @tc.name : favorite + * @tc.desc : favorite by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image03.jpg', path); + asset.favorite(666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04 + * @tc.name : favorite + * @tc.desc : favorite by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image04.jpg', path); + asset.favorite('666', (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05 + * @tc.name : favorite + * @tc.desc : favorite by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image05.jpg', path); + asset.favorite(0.666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06 + * @tc.name : favorite + * @tc.desc : favorite by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image06.jpg', path); + asset.favorite(null, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01 + * @tc.name : isFavorite + * @tc.desc : Is Favourite true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image07.jpg', path); + await asset.favorite(true); + asset.isFavorite((err, isFavorite) => { + if (err == undefined && isFavorite == true) { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 isFavorite = ' + isFavorite); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02 + * @tc.name : isFavorite + * @tc.desc : Is Favourite true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image0702.jpg', path); + await asset.favorite(false); + asset.isFavorite((err, isFavorite) => { + if (err == undefined && isFavorite == false) { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 isFavorite = ' + isFavorite); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01 + * @tc.name : trash + * @tc.desc : Trash by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image08.jpg', path); + asset.trash(true, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02 + * @tc.name : trash + * @tc.desc : Trash by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image09.jpg', path); + asset.trash(false, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03 + * @tc.name : trash + * @tc.desc : Trash by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image10.jpg', path); + asset.trash(666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04 + * @tc.name : trash + * @tc.desc : Trash by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image11.jpg', path); + asset.trash('666', (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05 + * @tc.name : trash + * @tc.desc : Trash by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image12.jpg', path); + asset.trash(0.666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06 + * @tc.name : trash + * @tc.desc : Trash by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image13.jpg', path); + asset.trash(null, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01 + * @tc.name : isTrash + * @tc.desc : isTrash true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image14.jpg', path); + await asset.trash(true); + asset.isTrash((err, isTrash) => { + if (err == undefined && isTrash == true) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02 + * @tc.name : isTrash + * @tc.desc : isTrash false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image15.jpg', path); + await asset.trash(false); + asset.isTrash((err, isTrash) => { + if (err == undefined && isTrash == false) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestPromise.test.ets old mode 100644 new mode 100755 index 5116b6e2c867ab7d507915ceb228c52ae4f07031..e228bf7a803b261675d8e9577428bd6ea61d7b40 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/favtrashTestPromise.test.ets @@ -1,422 +1,422 @@ -/* - * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, -} from '../../../../../../common'; -describe('file.promise.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - beforeAll(function () { - console.info('File Promise MediaLibraryTest: beforeAll : Prerequisites at the test suite level, which are executed before the test suite is executed.'); - }); - beforeEach(function () { - console.info('File Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); - }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { - console.info('File Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01 - * @tc.name : favorite - * @tc.desc : favorite by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image01.jpg', path); - await asset.favorite(true); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_01 success'); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_01 fail, message = ' + error); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02 - * @tc.name : favorite - * @tc.desc : favorite by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image02.jpg', path); - await asset.favorite(false); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_02 success'); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_02 fail, message = ' + error); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03 - * @tc.name : favorite - * @tc.desc : favorite by 666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image03.jpg', path); - await asset.favorite(666); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_03 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_03 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04 - * @tc.name : favorite - * @tc.desc : favorite by '666' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image04.jpg', path); - await asset.favorite('666'); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_04 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_04 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05 - * @tc.name : favorite - * @tc.desc : favorite by 0.666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image05.jpg', path); - await asset.favorite(0.666); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_05 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_05 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06 - * @tc.name : favorite - * @tc.desc : favorite by null - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image06.jpg', path); - await asset.favorite(); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_06 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_06 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01 - * @tc.name : isFavorite - * @tc.desc : Is Favourite - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image07.jpg', path); - await asset.favorite(true); - let isFavorite = await asset.isFavorite(); - if (isFavorite == true) { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - expect(true).assertTrue(); - } - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02 - * @tc.name : isFavorite - * @tc.desc : Is Favourite - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image0702.jpg', path); - await asset.favorite(false); - let isFavorite = await asset.isFavorite(); - if (isFavorite == false) { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - expect(true).assertTrue(); - } - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01 - * @tc.name : trash - * @tc.desc : Trash by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image08.jpg', path); - await asset.trash(true); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01'); - expect(true).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01 fail ,message = ', trashError); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02 - * @tc.name : trash - * @tc.desc : Trash by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image09.jpg', path); - await asset.trash(false); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02'); - expect(true).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02 fail ,message = ', trashError); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03 - * @tc.name : trash - * @tc.desc : Trash by 666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image10.jpg', path); - await asset.trash(666); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03'); - expect(false).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04 - * @tc.name : trash - * @tc.desc : Trash by '666' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image11.jpg', path); - await asset.trash('666'); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04'); - expect(false).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05 - * @tc.name : trash - * @tc.desc : Trash by 0.666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image12.jpg', path); - await asset.trash(0.666); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05'); - expect(false).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06 - * @tc.name : trash - * @tc.desc : Trash by null - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image13.jpg', path); - await asset.trash(); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06'); - expect(false).assertTrue(); - done(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01 - * @tc.name : isTrash - * @tc.desc : isTrash true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image14.jpg', path); - await asset.trash(true); - let isTrash = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_01 = ' + isTrash); - if (isTrash) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02 - * @tc.name : isTrash - * @tc.desc : isTrash false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02', 0, async function (done) { - try { - const asset = await media.createAsset(mediaType, 'image15.jpg', path); - await asset.trash(false); - let isTrash = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_02 = ' + isTrash); - if (!isTrash) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_02 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); -}); +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, +} from '../../../../../../common'; +describe('file.promise.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + beforeAll(function () { + console.info('File Promise MediaLibraryTest: beforeAll : Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); + beforeEach(function () { + console.info('File Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(async function () { await sleep(200)}); + afterAll(function () { + console.info('File Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01 + * @tc.name : favorite + * @tc.desc : favorite by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image01.jpg', path); + await asset.favorite(true); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_01 success'); + expect(true).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_01 fail, message = ' + error); + expect(false).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02 + * @tc.name : favorite + * @tc.desc : favorite by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image02.jpg', path); + await asset.favorite(false); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_02 success'); + expect(true).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_02 fail, message = ' + error); + expect(false).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03 + * @tc.name : favorite + * @tc.desc : favorite by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image03.jpg', path); + await asset.favorite(666); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_03 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_03 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04 + * @tc.name : favorite + * @tc.desc : favorite by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image04.jpg', path); + await asset.favorite('666'); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_04 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_04 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05 + * @tc.name : favorite + * @tc.desc : favorite by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image05.jpg', path); + await asset.favorite(0.666); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_05 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_05 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06 + * @tc.name : favorite + * @tc.desc : favorite by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image06.jpg', path); + await asset.favorite(); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_06 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_06 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01 + * @tc.name : isFavorite + * @tc.desc : Is Favourite + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image07.jpg', path); + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite == true) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02 + * @tc.name : isFavorite + * @tc.desc : Is Favourite + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image0702.jpg', path); + await asset.favorite(false); + let isFavorite = await asset.isFavorite(); + if (isFavorite == false) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01 + * @tc.name : trash + * @tc.desc : Trash by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image08.jpg', path); + await asset.trash(true); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01'); + expect(true).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01 fail ,message = ', trashError); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02 + * @tc.name : trash + * @tc.desc : Trash by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image09.jpg', path); + await asset.trash(false); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02'); + expect(true).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02 fail ,message = ', trashError); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03 + * @tc.name : trash + * @tc.desc : Trash by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image10.jpg', path); + await asset.trash(666); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04 + * @tc.name : trash + * @tc.desc : Trash by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image11.jpg', path); + await asset.trash('666'); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05 + * @tc.name : trash + * @tc.desc : Trash by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image12.jpg', path); + await asset.trash(0.666); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06 + * @tc.name : trash + * @tc.desc : Trash by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image13.jpg', path); + await asset.trash(); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01 + * @tc.name : isTrash + * @tc.desc : isTrash true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image14.jpg', path); + await asset.trash(true); + let isTrash = await asset.isTrash(); + console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_01 = ' + isTrash); + if (isTrash) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_01 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02 + * @tc.name : isTrash + * @tc.desc : isTrash false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image15.jpg', path); + await asset.trash(false); + let isTrash = await asset.isTrash(); + console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_02 = ' + isTrash); + if (!isTrash) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_02 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAsset2.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAsset2.test.ets old mode 100644 new mode 100755 index 29877b7a3f5da5fea880b902907419b5b593434b..e5db1d3f07cba5b0fab46e910199bb425cae5818 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAsset2.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAsset2.test.ets @@ -1,398 +1,398 @@ -/* - * 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 { 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(); - } -} -describe('fileAsset2.test.js', async function () { - let fileKeyObj = mediaLibrary.FileKey; - - let imageType = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - 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 allTypefetchOp = { - selections: '', - selectionArgs: [], - }; - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(context); - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(function () {}); - afterAll(function () {}); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_001 - * @tc.name : commitModify - * @tc.desc : Modify displayName - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const newName = 'newName'; - asset.displayName = newName; - const id = asset.id; - await asset.commitModify(); - - const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult2.getAllObject(); - let passed = false; - for (let i = 0; i < dataList.length; i++) { - const asset = dataList[i]; - if (asset.id == id && asset.displayName == newName) { - passed = true; - break; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 001 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002 - * @tc.name : commitModify - * @tc.desc : Modify title - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const newTitle = 'newTitle'; - asset.title = newTitle; - const id = asset.id; - await asset.commitModify(); - - const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult2.getAllObject(); - let passed = false; - for (let i = 0; i < dataList.length; i++) { - const asset = dataList[i]; - if (asset.id == id && asset.title == newTitle) { - passed = true; - break; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 002 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003 - * @tc.name : commitModify - * @tc.desc : Modify relativePath - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) { - try { - const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - - const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - let relativePath = asset.relativePath; - let newrelativePath = path1; - if (relativePath == path1) { - newrelativePath = path2; - } - - asset.relativePath = newrelativePath; - const id = asset.id; - await asset.commitModify(); - - const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult2.getAllObject(); - let passed = false; - for (let i = 0; i < dataList.length; i++) { - const asset = dataList[i]; - if (asset.id == id && asset.relativePath == newrelativePath) { - passed = true; - break; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 003 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004 - * @tc.name : commitModify - * @tc.desc : Modify orientation - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_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; - await asset.commitModify(); - - const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult2.getAllObject(); - let passed = false; - for (let i = 0; i < dataList.length; i++) { - const asset = dataList[i]; - if (asset.id == id && asset.orientation == neworientation) { - passed = true; - break; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 004 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_005 - * @tc.name : commitModify - * @tc.desc : Modify uri - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_005', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const id = asset.id; - const newUri = 'newUri'; - - asset.uri = newUri; - - await asset.commitModify(); - - console.info('FileAsset commitModify 005 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 005 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_006 - * @tc.name : commitModify - * @tc.desc : Modify mediaType - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_006', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - const id = asset.id; - const newMediaType = 'newMediaType'; - - asset.mediaType = newMediaType; - - await asset.commitModify(); - - console.info('FileAsset commitModify 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('FileAsset commitModify 006 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001 - * @tc.name : isDirectory - * @tc.desc : isDirectory asset - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - 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(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_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_promise_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_004', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(allTypefetchOp); - const asset = await fetchFileResult.getFirstObject(); - printAttr(asset); - checkAttrs(done, asset, '004'); - } catch (error) { - console.info('FileAsset checkAttr 003 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); -}); +/* + * 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 { 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(); + } +} +describe('fileAsset2.test.js', async function () { + let fileKeyObj = mediaLibrary.FileKey; + + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + 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 allTypefetchOp = { + selections: '', + selectionArgs: [], + }; + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_001 + * @tc.name : commitModify + * @tc.desc : Modify displayName + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newName = 'newName'; + asset.displayName = newName; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.displayName == newName) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002 + * @tc.name : commitModify + * @tc.desc : Modify title + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newTitle = 'newTitle'; + asset.title = newTitle; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.title == newTitle) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003 + * @tc.name : commitModify + * @tc.desc : Modify relativePath + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) { + try { + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + + const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + let relativePath = asset.relativePath; + let newrelativePath = path1; + if (relativePath == path1) { + newrelativePath = path2; + } + + asset.relativePath = newrelativePath; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.relativePath == newrelativePath) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004 + * @tc.name : commitModify + * @tc.desc : Modify orientation + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_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; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.orientation == neworientation) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 004 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_005 + * @tc.name : commitModify + * @tc.desc : Modify uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_005', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newUri = 'newUri'; + + asset.uri = newUri; + + await asset.commitModify(); + + console.info('FileAsset commitModify 005 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 005 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_006 + * @tc.name : commitModify + * @tc.desc : Modify mediaType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_006', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newMediaType = 'newMediaType'; + + asset.mediaType = newMediaType; + + await asset.commitModify(); + + console.info('FileAsset commitModify 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001 + * @tc.name : isDirectory + * @tc.desc : isDirectory asset + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + 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(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_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_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + 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_promise_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_promise_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + 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_promise_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_promise_003', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + 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_promise_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_promise_004', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(allTypefetchOp); + const asset = await fetchFileResult.getFirstObject(); + 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/fileAssetCallBack2.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetCallBack2.test.ets old mode 100644 new mode 100755 index 92b38ead9ca3c6f9a61d329a17f9fcd786d196d0..6f33f642f93c6f5b11c597953db3627b2cfb71e2 --- 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 @@ -1,349 +1,349 @@ -/* - * 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(); - } - }); - }); -} - +/* + * 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/fileAssetPromise2.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetPromise2.test.ets deleted file mode 100644 index 6c863c89c88ea1fbf2eabfc9a63cee4aa279ca11..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetPromise2.test.ets +++ /dev/null @@ -1,323 +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 fileAssetPromise2Test(abilityContext){ - describe('fileAssetPromise2Test', 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_promise_001 - * @tc.name : commitModify - * @tc.desc : Modify displayName - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_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; - await asset.commitModify(); - - 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_promise_002 - * @tc.name : commitModify - * @tc.desc : Modify title - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_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; - await asset.commitModify(); - - 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_promise_003 - * @tc.name : commitModify - * @tc.desc : Modify relativePath - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_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; - await asset.commitModify(); - - 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_promise_004 - * @tc.name : commitModify - * @tc.desc : Modify orientation - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_commitModify_promise_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; - await asset.commitModify(); - - 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_promise_001 - * @tc.name : isDirectory - * @tc.desc : isDirectory asset - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - 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(); - } - }); - - /** - * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_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_promise_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - - 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_promise_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_promise_004', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(allTypefetchOp); - const asset = await fetchFileResult.getFirstObject(); - 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 old mode 100644 new mode 100755 index f15ceb1aff5610b325b2220e57f72eb71fabebbd..2dec1d4fce3f0648e1a5cfc0d1d6d37a57a141d1 --- 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 @@ -1,1086 +1,1086 @@ -/* - * 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 ================================ - }); -} +/* + * 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/fileAssetTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetTestPromise.test.ets deleted file mode 100644 index 379bd356cba1646fdeb7dff3e3b87721e06f73af..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetTestPromise.test.ets +++ /dev/null @@ -1,840 +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 fileAssetTestPromiseTest(abilityContext){ - describe('fileAssetTestPromiseTest', 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_PROMISE_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_PROMISE_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 fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic02/', fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('rw'); - - 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); - - console.log(' fd: ' + fd) - console.log(' bytesRead: ' + res.bytesRead) - console.log(' write: ' + write) - 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_PROMISE_005_01 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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/Dynamic02/', type.toString()], - } - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(isNum(fd)).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - - console.log(' bytesRead: ' + res.bytesRead) - // fd: 64 - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - let write = await fileio.write(fd, buf); - - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 error:' + error); - - if (isNum(fd)) { - - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_03', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - 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); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== FILE END ================================== - - //======================== IMAGE BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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/Dynamic022/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.log('1111111111111111:' + dataList.length) - asset = dataList[0]; - console.log('2222222222222222:' + asset.id) - fd = await asset.open('rw'); - 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); - - console.log(' fd: ' + fd) - console.log(' bytesRead: ' + res.bytesRead) - console.log(' write: ' + write) - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_08', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - } - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic022/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(isNum(fd)).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 error:' + error); - - console.log(' fd: ' + fd) - if (isNum(fd)) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_09', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic022/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(isNum(fd)).assertTrue(); - - console.log(' 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); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== IMAGE END ================================== - - //======================== AUDIO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - 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(); - - console.log(' fd: ' + fd) - console.log(' bytesRead: ' + res.bytesRead) - console.log(' 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_PROMISE_005_10 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_11', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - } - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(isNum(fd)).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 error:' + error); - - console.log(' fd: ' + fd) - if (isNum(fd)) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_12', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(isNum(fd)).assertTrue(); - fd1 = await asset1.open('r'); - - console.log(' fd: ' + fd) - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== AUDIO END ================================== - - //======================== VIDEO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - - asset = dataList[0]; - fd = await asset.open('rw'); - 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); - - console.log(' fd: ' + fd) - console.log(' bytesRead: ' + res.bytesRead) - console.log(' write: ' + write) - if (isNum(fd) && res.bytesRead == assetProps.bytesRead && write == assetProps.write) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_14', 0, async function (done) { - let asset; - let fd; - let assetProps = { - bytesRead: 4096, - } - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('r'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 fd:' + fd); - expect(isNum(fd)).assertTrue(); - - console.log(' fd: ' + fd) - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 res.bytesRead:' - + res.bytesRead); - expect(res.bytesRead == assetProps.bytesRead).assertTrue(); - let write = await fileio.write(fd, buf); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 close fd:' + fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_005_15', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic02/', type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 dataList.length:' - + dataList.length); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 fd:' + fd); - expect(isNum(fd)).assertTrue(); - fd1 = await asset1.open('r'); - - console.log(' fd: ' + fd) - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== VIDEO END ================================== - - //======================== CLOSE BEGIN ================================ - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('r'); - expect(isNum(fd)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 fd:' + fd); - await asset.close(fd); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 close fd:' + fd); - fd1 = await asset.open('r'); - expect(isNum(fd1)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 fd1:' + fd1); - await asset.close(fd1); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 close fd1:' - + fd1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('r'); - expect(isNum(fd)).assertTrue - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 fd:' + fd); - await asset.close(fd); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 clode fd:' + fd); - fd1 = await asset.open('r'); - expect(isNum(fd1)).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 fd1:' + fd1); - await asset.close(fd1); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 clode fd1:' - + fd1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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'); - await asset.close(fd); - fd1 = await asset.open('r'); - await asset.close(fd1); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 fd:' + fd); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 fd:' + fd1); - - - if (isNum(fd) && isNum(fd1)) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 false'); - expect(false).assertTrue(); - done(); - } - done; - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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_PROMISE_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_PROMISE_005_35 dataList.length:' - + dataList.length); - asset = dataList[0]; - fd = await asset.open('r'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 fd:' + fd); - expect(isNum(fd)).assertTrue(); - await asset.close(fd); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 close fd:' + fd); - fd1 = await asset.open('r'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 fd1:' + fd1); - expect(isNum(fd1)).assertTrue(); - await asset.close(fd1); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 close fd1:' - + fd1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_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/fileAssetUriTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetUriTestCallBack.test.ets deleted file mode 100644 index 54964b89ba52cb0f9cb258c2d60e75d8b107a560..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetUriTestCallBack.test.ets +++ /dev/null @@ -1,93 +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, it, expect} from 'deccjsunit/index'; - -export default function fileAssetUriTestCallBackTest(abilityContext){ - describe('fileAssetUriTestCallBackTest', function() { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - const fileKeyObj = mediaLibrary.FileKey; - //======================== FILE BEGIN ================================== - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_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_URI_CALLBACK_005_35', 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() ], - }; - const fetchFileResult = await media.getFileAssets(fetchOp); - expect(fetchFileResult != undefined).assertTrue(); - let firstObject = await fetchFileResult.getFirstObject(); - const id = firstObject.id; - const uri = firstObject.uri; - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 uri:' - + uri); - const serachUri = 'datashare:///media/image/' + id; - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 serachUri:' - + serachUri); - - let serchfetchOp = { - uri:serachUri.toString(), - selections : fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs : [ type.toString()], - }; - - const result = await media.getFileAssets(serchfetchOp); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 getFileAssets by uri:' - + serachUri + ",result.getCount():" + result.getCount()); - asset = await result.getFirstObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 asset.uri:' - + asset.uri); - expect(asset.uri == serachUri).assertTrue(); - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd:' + fd); - asset.close(fd, async (error) => { - fd1 = await asset.open('r'); - expect(fd1 > 0).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd1:' - + fd1); - await asset.close(fd1); - done(); - }); - } catch (error) { - console.info( - `MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 error:${error}`); - expect(false).assertTrue(); - done(); - } - }); - //======================== CLOSE BEGIN ================================ - }); -} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets deleted file mode 100644 index 9e7bf113277851692d59a6e150601145e3b17f4a..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileAssetUriTestPromise.test.ets +++ /dev/null @@ -1,90 +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, it, expect} from 'deccjsunit/index'; - -export default function fileAssetUriTestPromiseTest(abilityContext){ - describe('fileAssetUriTestPromiseTest', function() { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(abilityContext); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - const fileKeyObj = mediaLibrary.FileKey; - //======================== FILE BEGIN ================================== - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_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_URI_PROMISE_005_35', 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() ], - }; - const fetchFileResult = await media.getFileAssets(fetchOp); - expect(fetchFileResult != undefined).assertTrue(); - let firstObject = await fetchFileResult.getFirstObject(); - const id = firstObject.id; - const uri = firstObject.uri; - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 uri:' + uri); - const serachUri = 'datashare:///media/image/' + id; - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 serachUri:' - + serachUri); - - let serchfetchOp = { - uri : serachUri.toString(), - selections : fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs : [ type.toString() ], - }; - - const result = await media.getFileAssets(serchfetchOp); - console.info( - 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 getFileAssets by uri:' - + serachUri + ",result.getCount():" + result.getCount()); - asset = await result.getFirstObject(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 asset.uri:' - + asset.uri); - expect(asset.uri == serachUri).assertTrue(); - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd:' + fd); - await asset.close(fd); - fd1 = await asset.open('r'); - expect(fd1 > 0).assertTrue(); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd1:' + fd1); - await asset.close(fd1); - done(); - } catch (error) { - console.info( - `MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 error:${error}`); - 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 old mode 100644 new mode 100755 index f0205d0bdc2426b5cfb854b6527c59eb5524a79e..8993383e736956c674918b9de2e48f94d220fd72 --- 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 @@ -1,744 +1,744 @@ -/* - * 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 ----------------------------- - }); -} - +/* + * 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/fileTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileTestPromise.test.ets deleted file mode 100644 index 20d731e24843eeeb16b50235229a1e1d50674f60..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/fileTestPromise.test.ets +++ /dev/null @@ -1,723 +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_PROMISE getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } else if (asset[attr] == undefined) { - console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } -} - -let path; -let presetAsset; -let displayName; -let id; -let mediaType; -let orientation = 0; - -export default function fileTestPromiseTest(abilityContext){ - describe('fileTestPromiseTest', 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_PROMISE_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_PROMISE_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; - const creatAsset1 = await media.createAsset( - imageType, - `${new Date().getTime()}.jpg`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.jpg`; - const asset2 = dataList[1]; - const creatAsset2 = await media.createAsset(imageType, displayName, path); - const fd2 = await asset2.open('rw'); - 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_PROMISE createAsset 001_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 001_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 001_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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()}`; - await asset.commitModify(); - 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_PROMISE getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 001_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 001_11 failed, message = ' + error); - } - }); - - // ------------------------------- image type end ----------------------------- - - // ------------------------------- video type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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]; - const creatAsset1 = await media.createAsset( - videoType, - `${new Date().getTime()}.mp4`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp4`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(videoType, displayName, path); - const fd2 = await asset2.open('rw'); - 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_PROMISE createAsset 002_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 002_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 002_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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()}`; - await asset.commitModify(); - 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_PROMISE getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 002_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 002_11 failed, message = ' + error); - } - }); - // ------------------------------- video type end ----------------------------- - - // ------------------------------- audio type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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]; - const creatAsset1 = await media.createAsset( - audioType, - `${new Date().getTime()}.mp3`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp3`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(audioType, displayName, path); - const fd2 = await asset2.open('rw'); - 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_PROMISE createAsset 003_01 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 003_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 003_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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()}`; - await asset.commitModify(); - - 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_PROMISE getFileAssets 003_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 003_08 failed, message = ' + error); - } - }); - - // ------------------------------- audio type end ----------------------------- - - // ------------------------------ file type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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]; - const creatAsset1 = await media.createAsset( - fileType, - `${new Date().getTime()}.bat`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.bat`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(fileType, displayName, path); - const fd2 = await asset2.open('rw'); - 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_PROMISE createAsset 004_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 004_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE getFileAssets 004_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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()}`; - await asset.commitModify(); - 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_PROMISE getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_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_PROMISE_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_PROMISE createAsset 004_08 failed, message = ' + error); - } - }); - - // ------------------------------- file type end ----------------------------- - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestCallBack.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestCallBack.test.ets deleted file mode 100644 index 875066feeb014dce6505a9f5de806792f00c4193..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestCallBack.test.ets +++ /dev/null @@ -1,398 +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 { 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.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; - -let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; - -let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let allsfetchOp = { - selections: '', - selectionArgs: [], -}; - -//const context = featureAbility.getContext(); -//const media = mediaLibrary.getMediaLibrary(context); - -const filekeys = { - parent: 'PARENT', - mimeType: 'MIME_TYPE', - size: 'SIZE', - dateAdded: 'DATE_ADDED', - title: 'TITLE', - duration: 'DURATION', - width: 'WIDTH', - height: 'HEIGHT', - orientation: 'ORIENTATION', - albumId: 'ALBUM_ID', - albumName: 'ALBUM_NAME', - artist: 'ARTIST', - audioAlbum: 'AUDIOALBUM', - dateModified: 'DATE_MODIFIED', - dateTaken: 'DATE_TAKEN', -} - -//async function getFileAssetsBy(done, type) { -// let assetOp = imagesfetchOp -// if(type == 'audioAlbum' || type == 'artist' || type == 'duration') { -// assetOp = audiosfetchOp -// } -// const fetchFileResult = await media.getFileAssets(assetOp); -// const asset = await fetchFileResult.getFirstObject(); -// let Op = { -// selections: fileKeyObj[filekeys[type]] + '= ?', -// selectionArgs: [asset[type] + ''], -// }; -// -// try { -// media.getFileAssets(Op, async(err, fetchFileResult) => { -// if (fetchFileResult == undefined) { -// expect(false).assertTrue(); -// done(); -// } else { -// try { -// const fetchCount = await fetchFileResult.getCount(); -// console.log('getFileAssetsBy ' + type + 'fetchCount = ' + fetchCount); -// expect(fetchCount > 0).assertTrue(); -// done(); -// } catch (error) { -// console.log('getFileAssetsBy ' + type + ' failed error message = ' + error); -// } -// } -// }); -// } catch (error) { -// expect(false).assertTrue(); -// done(); -// } -//} -function printAttr (done, asset, tNum) { - -} -export default function filekeyTestCallBackTest(abilityContext){ - describe('filekeyTestCallBackTest', function () { - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(async function () { await sleep(200)}); - afterAll(function () {}); - const media = mediaLibrary.getMediaLibrary(abilityContext); - - async function getFileAssetsBy(done, type) { - let assetOp = imagesfetchOp - if(type == 'audioAlbum' || type == 'artist' || type == 'duration') { - assetOp = audiosfetchOp - } - const fetchFileResult = await media.getFileAssets(assetOp); - const asset = await fetchFileResult.getFirstObject(); - let Op = { - selections: fileKeyObj[filekeys[type]] + '= ?', - selectionArgs: [asset[type] + ''], - }; - - try { - media.getFileAssets(Op, async(err, fetchFileResult) => { - if (fetchFileResult == undefined) { - expect(false).assertTrue(); - done(); - } else { - try { - const fetchCount = await fetchFileResult.getCount(); - console.log('getFileAssetsBy ' + type + 'fetchCount = ' + fetchCount); - expect(fetchCount > 0).assertTrue(); - done(); - } catch (error) { - console.log('getFileAssetsBy ' + type + ' failed error message = ' + error); - } - } - }); - } catch (error) { - expect(false).assertTrue(); - done(); - } - } - - /** - * @tc.number : test_fileKey_001 - * @tc.name : getFileAssets - * @tc.desc : filekey parentOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('test_fileKey_001', 0, async function (done) { - getFileAssetsBy(done, 'parent'); - }); - - /** - * @tc.number : test_fileKey_002 - * @tc.name : getFileAssets - * @tc.desc : filekey mimeTypeOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_002', 0, async function (done) { - getFileAssetsBy(done, 'mimeType'); - }); - - /** - * @tc.number : test_fileKey_003 - * @tc.name : getFileAssets - * @tc.desc : filekey sizeOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_003', 0, async function (done) { - getFileAssetsBy(done, 'size'); - }); - - /** - * @tc.number : test_fileKey_004 - * @tc.name : getFileAssets - * @tc.desc : filekey dateAddedOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_004', 0, async function (done) { - - getFileAssetsBy(done, 'dateAdded'); - }); - - /** - * @tc.number : test_fileKey_005 - * @tc.name : getFileAssets - * @tc.desc : filekey dateModifiedOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_005', 0, async function (done) { - getFileAssetsBy(done, 'dateModified'); - }); - - /** - * @tc.number : test_fileKey_006 - * @tc.name : getFileAssets - * @tc.desc : filekey dateTakenOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_006', 0, async function (done) { - getFileAssetsBy(done, 'dateTaken'); - }); - - /** - * @tc.number : test_fileKey_007 - * @tc.name : getFileAssets - * @tc.desc : filekey titleOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_007', 0, async function (done) { - getFileAssetsBy(done, 'title'); - }); - - /** - * @tc.number : test_fileKey_008 - * @tc.name : getFileAssets - * @tc.desc : filekey durationOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_008', 0, async function (done) { - getFileAssetsBy(done, 'duration'); - }); - - /** - * @tc.number : test_fileKey_009 - * @tc.name : getFileAssets - * @tc.desc : filekey widthOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_009', 0, async function (done) { - getFileAssetsBy(done, 'width'); - }); - - /** - * @tc.number : test_fileKey_010 - * @tc.name : getFileAssets - * @tc.desc : filekey heightOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_010', 0, async function (done) { - getFileAssetsBy(done, 'height'); - }); - - /** - * @tc.number : test_fileKey_011 - * @tc.name : getFileAssets - * @tc.desc : filekey orientationOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_011', 0, async function (done) { - getFileAssetsBy(done, 'orientation'); - }); - - /** - * @tc.number : test_fileKey_012 - * @tc.name : getFileAssets - * @tc.desc : filekey widthOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_012', 0, async function (done) { - getFileAssetsBy(done, 'albumId'); - }); - - /** - * @tc.number : test_fileKey_0013 - * @tc.name : getFileAssets - * @tc.desc : filekey albumNameOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0013', 0, async function (done) { - getFileAssetsBy(done, 'albumName'); - }); - - /** - * @tc.number : test_fileKey_0014 - * @tc.name : getFileAssets - * @tc.desc : filekey artistOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0014', 0, async function (done) { - getFileAssetsBy(done, 'artist'); - }); - - /** - * @tc.number : test_fileKey_0015 - * @tc.name : getFileAssets - * @tc.desc : filekey audioAlbumOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0015', 0, async function (done) { - getFileAssetsBy(done, 'audioAlbum'); - }); - - /** - * @tc.number : test_fileKey_0016 - * @tc.name : getFileAssets - * @tc.desc : filekey relative_path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0016', 0, async function (done) { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - const path = await media.getPublicDirectory(DIR_IMAGE); - let fileAsset = await media.createAsset(mediaType, 'forRelative.jpg', path); - if (fileAsset == undefined) { - console.info('MediaLibraryTest : FETCHRESULT createAsset fail'); - expect(false).assertTrue(); - done(); - return; - } - let fetchOption = { - selections: fileKeyObj.RELATIVE_PATH + '= ?', - selectionArgs: [path] - } - let fetchFileResult = await media.getFileAssets(fetchOption); - let firstObject = await fetchFileResult.getFirstObject(); - expect(firstObject.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK test_fileKey_0016 failed, message = ' + error); - } - }); - - /** - * @tc.number : test_fileKey_0017 - * @tc.name : getFileAssets - * @tc.desc : filekey display_name - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0017', 0, async function (done) { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - const path = await media.getPublicDirectory(DIR_IMAGE); - let name = 'forDisplay.jpg' - let fileAsset = await media.createAsset(mediaType, name, path); - if (fileAsset == undefined) { - console.info('MediaLibraryTest : FETCHRESULT createAsset fail'); - expect(false).assertTrue(); - done(); - return; - } - let fetchOption = { - selections: fileKeyObj.DISPLAY_NAME + '= ?', - selectionArgs: [name] - } - let fetchFileResult = await media.getFileAssets(fetchOption); - let firstObject = await fetchFileResult.getFirstObject(); - expect(firstObject.displayName == name).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_CALLBACK test_fileKey_0017 failed, message = ' + error); - } - }); - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestPromise.test.ets deleted file mode 100644 index 4abe9b4c5f209cde7fcb11a8d1499052a6981281..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/filekeyTestPromise.test.ets +++ /dev/null @@ -1,307 +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 { - sleep, -} from '../../../../../../common'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -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.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; - -let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; - -let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let allsfetchOp = { - selections: '', - selectionArgs: [], -}; - -//const context = featureAbility.getContext(); -//const media = mediaLibrary.getMediaLibrary(context); - -const filekeys = { - parent: 'PARENT', - mimeType: 'MIME_TYPE', - size: 'SIZE', - dateAdded: 'DATE_ADDED', - title: 'TITLE', - duration: 'DURATION', - width: 'WIDTH', - height: 'HEIGHT', - orientation: 'ORIENTATION', - albumId: 'ALBUM_ID', - albumName: 'ALBUM_NAME', - artist: 'ARTIST', - audioAlbum: 'AUDIOALBUM', - dateModified: 'DATE_MODIFIED', - dateTaken: 'DATE_TAKEN', -} - -//async function getFileAssetsBy(done, type) { -// let assetOp = imagesfetchOp -// if(type == 'audioAlbum' || type == 'artist' || type == 'duration') { -// assetOp = audiosfetchOp -// } -// const fetchFileResult = await media.getFileAssets(assetOp); -// const asset = await fetchFileResult.getFirstObject(); -// let Op = { -// selections: fileKeyObj[filekeys[type]] + '= ?', -// selectionArgs: [asset[type] + ''], -// }; -// -// try { -// let fetchFileResult = await media.getFileAssets(Op); -// const fetchCount = fetchFileResult.getCount(); -// expect(fetchCount > 0).assertTrue(); -// done(); -// } catch (error) { -// expect(false).assertTrue(); -// done(); -// } -//} -function printAttr (done, asset, tNum) { - -} -export default function filekeyTestPromiseTest(abilityContext){ - describe('filekeyTestPromiseTest', function () { - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(async function () { await sleep(200)}); - afterAll(function () {}); - const media = mediaLibrary.getMediaLibrary(abilityContext); - async function getFileAssetsBy(done, type) { - let assetOp = imagesfetchOp - if(type == 'audioAlbum' || type == 'artist' || type == 'duration') { - assetOp = audiosfetchOp - } - const fetchFileResult = await media.getFileAssets(assetOp); - const asset = await fetchFileResult.getFirstObject(); - let Op = { - selections: fileKeyObj[filekeys[type]] + '= ?', - selectionArgs: [asset[type] + ''], - }; - - try { - let fetchFileResult = await media.getFileAssets(Op); - const fetchCount = fetchFileResult.getCount(); - expect(fetchCount > 0).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - } - - /** - * @tc.number : test_fileKey_001 - * @tc.name : getFileAssets - * @tc.desc : filekey parentOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('test_fileKey_001', 0, async function (done) { - getFileAssetsBy(done, 'parent'); - }); - - /** - * @tc.number : test_fileKey_002 - * @tc.name : getFileAssets - * @tc.desc : filekey mimeTypeOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_002', 0, async function (done) { - getFileAssetsBy(done, 'mimeType'); - }); - - /** - * @tc.number : test_fileKey_003 - * @tc.name : getFileAssets - * @tc.desc : filekey sizeOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_003', 0, async function (done) { - getFileAssetsBy(done, 'size'); - }); - - /** - * @tc.number : test_fileKey_004 - * @tc.name : getFileAssets - * @tc.desc : filekey dateAddedOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_004', 0, async function (done) { - - getFileAssetsBy(done, 'dateAdded'); - }); - - /** - * @tc.number : test_fileKey_005 - * @tc.name : getFileAssets - * @tc.desc : filekey dateModifiedOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_005', 0, async function (done) { - getFileAssetsBy(done, 'dateModified'); - }); - - /** - * @tc.number : test_fileKey_006 - * @tc.name : getFileAssets - * @tc.desc : filekey dateTakenOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_006', 0, async function (done) { - getFileAssetsBy(done, 'dateTaken'); - }); - - /** - * @tc.number : test_fileKey_007 - * @tc.name : getFileAssets - * @tc.desc : filekey titleOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_007', 0, async function (done) { - getFileAssetsBy(done, 'title'); - }); - - /** - * @tc.number : test_fileKey_008 - * @tc.name : getFileAssets - * @tc.desc : filekey durationOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_008', 0, async function (done) { - getFileAssetsBy(done, 'duration'); - }); - - /** - * @tc.number : test_fileKey_009 - * @tc.name : getFileAssets - * @tc.desc : filekey widthOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_009', 0, async function (done) { - getFileAssetsBy(done, 'width'); - }); - - /** - * @tc.number : test_fileKey_010 - * @tc.name : getFileAssets - * @tc.desc : filekey heightOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_010', 0, async function (done) { - getFileAssetsBy(done, 'height'); - }); - - /** - * @tc.number : test_fileKey_011 - * @tc.name : getFileAssets - * @tc.desc : filekey orientationOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_011', 0, async function (done) { - getFileAssetsBy(done, 'orientation'); - }); - - /** - * @tc.number : test_fileKey_012 - * @tc.name : getFileAssets - * @tc.desc : filekey widthOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_012', 0, async function (done) { - getFileAssetsBy(done, 'albumId'); - }); - - /** - * @tc.number : test_fileKey_0013 - * @tc.name : getFileAssets - * @tc.desc : filekey albumNameOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0013', 0, async function (done) { - getFileAssetsBy(done, 'albumName'); - }); - - /** - * @tc.number : test_fileKey_0014 - * @tc.name : getFileAssets - * @tc.desc : filekey artistOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0014', 0, async function (done) { - getFileAssetsBy(done, 'artist'); - }); - - /** - * @tc.number : test_fileKey_0015 - * @tc.name : getFileAssets - * @tc.desc : filekey audioAlbumOp - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('test_fileKey_0015', 0, async function (done) { - getFileAssetsBy(done, 'audioAlbum'); - }); - }); -} - diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/getPermission.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/getPermission.test.ets old mode 100644 new mode 100755 index 4eedcf8ac502e0003ac7c5bb36aaf97dce95b2b9..39b1976021e6869b995a6cf0ca0b890451821841 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/getPermission.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/getPermission.test.ets @@ -1,47 +1,47 @@ -/* - * 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 { describe, beforeAll,afterAll, it, expect } from 'deccjsunit/index'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import bundle from '@ohos.bundle'; - -export default function getPermissionTest() { - describe("get_permission", function () { - - /** - * @tc.number SUB_DF_GRANT_USER_GRANTED_PERMISSION_0000 - * @tc.name grant_user_granted_permission_async_000 - * @tc.desc Test grantUserGrantedPermission() interfaces, grant permission. - * @tc.size MEDIUM - * @tc.type Function - * @tc.level Level 0 - * @tc.require - */ - it("grant_user_granted_permission_async_000", 0, async function (done) { - let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); - let tokenID = appInfo.accessTokenId; - let atManager = abilityAccessCtrl.createAtManager(); - let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); - let result2 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1); - let result3 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1); - let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); - let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); - let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); - expect(result1 == 0 && result2 == 0 && result3 == 0).assertTrue(); - expect(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0).assertTrue(); - done(); - }); - }); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll,afterAll, it, expect } from 'deccjsunit/index'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; + +export default function getPermissionTest() { + describe("get_permission", function () { + + /** + * @tc.number SUB_DF_GRANT_USER_GRANTED_PERMISSION_0000 + * @tc.name grant_user_granted_permission_async_000 + * @tc.desc Test grantUserGrantedPermission() interfaces, grant permission. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it("grant_user_granted_permission_async_000", 0, async function (done) { + let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); + let tokenID = appInfo.accessTokenId; + let atManager = abilityAccessCtrl.createAtManager(); + let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); + let result2 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1); + let result3 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1); + let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); + let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); + let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); + expect(result1 == 0 && result2 == 0 && result3 == 0).assertTrue(); + expect(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0).assertTrue(); + done(); + }); + }); } \ No newline at end of file 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 old mode 100644 new mode 100755 index 113295b05f7cf1c922bfa2bf0fafc68e0cf2452f..b89eaafcfd102cccf825d3e23013b5593bd58ecf --- 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 @@ -1,1003 +1,1003 @@ -/* - * 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(); - } - }); - }); -} - +/* + * 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(); + } + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets old mode 100644 new mode 100755 index 441bb1022dd2669a872aadc7af4e6bb28587c300..91bec658c0769f483fed29eebb7001ccc9e18f81 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromise.test.ets @@ -1,917 +1,917 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -import { - sleep, -} from '../../../../../../common'; -let fileKeyObj = mediaLibrary.FileKey; -let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; -let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; -let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; -let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; -let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - -let imageType = mediaLibrary.MediaType.IMAGE; -let videoType = mediaLibrary.MediaType.VIDEO; -let audioType = mediaLibrary.MediaType.AUDIO; -let fileType = mediaLibrary.MediaType.FILE; - -let imagesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; -let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; -let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let filesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], -}; - -let imageRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Static01/', imageType.toString()], -}; -let videoRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Static01/', videoType.toString()], -}; -let audioRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Static01/', audioType.toString()], -}; -let fileRelativefetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Static01/', fileType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", -}; - -let imageAndVideofetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString()], -}; -let imageAndVideoAndfilefetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString(), fileType.toString()], - order: fileKeyObj.DATE_ADDED + " DESC", -}; -let imageAndVideoAndfileAndAudiofetchOp = { - selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + - fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', - selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', 'Audios/Static01/', imageType.toString(), videoType.toString(), fileType.toString(), audioType.toString(),], - order: fileKeyObj.DATE_ADDED + " DESC", -}; - - -let allTypefetchOp = { - selections: '', - selectionArgs: [], -}; - -async function copyFile(fd1, fd2) { - let stat = await fileio.fstat(fd1); - let buf = new ArrayBuffer(stat.size); - await fileio.read(fd1, buf); - await fileio.write(fd2, buf); -} - -const props = { - image: { - mimeType: 'image/*', - displayName: '01.jpg', - relativePath: 'Pictures/Static01/', - size: '348113', - mediaType: imageType.toString(), - title: '01', - width: '1279', - height: '1706', - orientation: '0', - duration: '0', - albumId: '1118', - }, - video: { - mimeType: 'video/mp4', - displayName: '01.mp4', - relativePath: 'Videos/Static01/', - size: '4853005', - mediaType: videoType.toString(), - title: '01', - width: '1280', - height: '720', - orientation: '0', - duration: '10100', - }, - audio: { - mimeType: 'audio/mpeg', - displayName: '01.mp3', - relativePath: 'Audios/Static01/', - size: '1958311', - mediaType: audioType.toString(), - title: '01', - artist: '元数据测试', - width: '219600', - height: '219600', - orientation: '0', - duration: '219600', - }, - file: { - mimeType: 'file/*', - displayName: '01.dat', - relativePath: 'Documents/Static01/', - size: '10', - mediaType: fileType.toString(), - title: '01', - width: '0', - height: '0', - orientation: '0', - duration: '0', - } -} -function isNum(value) { - return typeof value === 'number' && !isNaN(value); -} -async function checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) { - expect(fetchFileResult != undefined).assertTrue(); - expect(fetchFileResult.getCount() == count).assertTrue(); - let asset = await fetchFileResult.getFirstObject(); - - if (count > 1) { - type = asset.mimeType.match(/[a-z]+/g)[0] - } - if (type == 'audio' && asset.artist != props[type].artist) { - expect(false).assertTrue(); - done(); - } - if (typesArr) { - let assetList = await fetchFileResult.getAllObject(); - for (const assetItem of assetList) { - expect(typesArr.includes(assetItem.mimeType)).assertTrue(); - } - } - if(!isNum(asset.dateTaken)) { - expect(false).assertTrue(); - done(); - } - if ( - asset.mimeType != props[type].mimeType || - asset.displayName != props[type].displayName || - asset.relativePath != props[type].relativePath || - asset.size != props[type].size || - asset.mediaType != props[type].mediaType || - asset.title != props[type].title || - asset.width != props[type].width || - asset.height != props[type].height || - asset.orientation != props[type].orientation || - asset.duration != props[type].duration - ) { - expect(false).assertTrue(); - done(); - } -} - -export default function mediaLibraryTestPromiseTest(abilityContext){ - describe('mediaLibraryTestPromiseTest', function () { - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(abilityContext); - - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(async function () { await sleep(200)}); - afterAll(function () { }); - - var timestamp = new Date().getTime(); - var jpgName = timestamp + '.jpg'; - var videoName = timestamp + '.mp4'; - var audioName = timestamp + '.mp3'; - var fileName = timestamp + '.mp3'; - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 - * @tc.name : getMediaLibrary - * @tc.desc : Obtains a MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { - try { - expect(media != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageRelativefetchOp); - let count = 1; - let type = 'image'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videoRelativefetchOp); - let count = 1; - let type = 'video'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audioRelativefetchOp); - let count = 1; - let type = 'audio'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(fileRelativefetchOp); - let count = 1; - let type = 'file'; - await checkFileAssetAttr(done, fetchFileResult, type, count, null) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); - let count = 2; - let type = 'video'; - let typesArr = ['image/*', 'video/mp4'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp); - let count = 3; - let type = 'file'; - let typesArr = ['image/*', 'video/mp4', 'file/*'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp); - let count = 4; - let type = 'audio'; - let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg'] - await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', - selectionArgs: ['abc'], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 008 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['abc', audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 009 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 009 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 010 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 010 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 011 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 011 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_CAMERA - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { - try { - let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; - - const dicResult = await media.getPublicDirectory(DIR_CAMERA); - - expect(dicResult == 'Camera/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { - try { - let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; - - const dicResult = await media.getPublicDirectory(DIR_VIDEO); - console.log(dicResult); - expect(dicResult == 'Videos/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { - try { - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - - const dicResult = await media.getPublicDirectory(DIR_IMAGE); - - expect(dicResult == 'Pictures/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { - try { - let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; - - const dicResult = await media.getPublicDirectory(DIR_AUDIO); - - expect(dicResult == 'Audios/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { - try { - let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - - const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS); - - expect(dicResult == 'Documents/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory 110 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { - try { - await media.getPublicDirectory(110); - console.info('MediaLibraryTest : getPublicDirectory 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getPublicDirectory 006 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 002 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 002 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 003 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 004 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 004 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(audioType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 005 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 006 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(audioType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 007 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(fileType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 008 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const filePath = path + "image/"; - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(imageType, jpgName, filePath); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - console.info('MediaLibraryTest : createAsset 009 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} - +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import { + sleep, +} from '../../../../../../common'; +let fileKeyObj = mediaLibrary.FileKey; +let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; +let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; +let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; +let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; +let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; +let fileType = mediaLibrary.MediaType.FILE; + +let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let filesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; + +let imageRelativefetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Pictures/Static01/', imageType.toString()], +}; +let videoRelativefetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Videos/Static01/', videoType.toString()], +}; +let audioRelativefetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Audios/Static01/', audioType.toString()], +}; +let fileRelativefetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Documents/Static01/', fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC", +}; + +let imageAndVideofetchOp = { + selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', + selectionArgs: ['Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString()], +}; +let imageAndVideoAndfilefetchOp = { + selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', + selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString(), fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC", +}; +let imageAndVideoAndfileAndAudiofetchOp = { + selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' + + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)', + selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', 'Audios/Static01/', imageType.toString(), videoType.toString(), fileType.toString(), audioType.toString(),], + order: fileKeyObj.DATE_ADDED + " DESC", +}; + + +let allTypefetchOp = { + selections: '', + selectionArgs: [], +}; + +async function copyFile(fd1, fd2) { + let stat = await fileio.fstat(fd1); + let buf = new ArrayBuffer(stat.size); + await fileio.read(fd1, buf); + await fileio.write(fd2, buf); +} + +const props = { + image: { + mimeType: 'image/*', + displayName: '01.jpg', + relativePath: 'Pictures/Static01/', + size: '348113', + mediaType: imageType.toString(), + title: '01', + width: '1279', + height: '1706', + orientation: '0', + duration: '0', + albumId: '1118', + }, + video: { + mimeType: 'video/mp4', + displayName: '01.mp4', + relativePath: 'Videos/Static01/', + size: '4853005', + mediaType: videoType.toString(), + title: '01', + width: '1280', + height: '720', + orientation: '0', + duration: '10100', + }, + audio: { + mimeType: 'audio/mpeg', + displayName: '01.mp3', + relativePath: 'Audios/Static01/', + size: '1958311', + mediaType: audioType.toString(), + title: '01', + artist: '元数据测试', + width: '219600', + height: '219600', + orientation: '0', + duration: '219600', + }, + file: { + mimeType: 'file/*', + displayName: '01.dat', + relativePath: 'Documents/Static01/', + size: '10', + mediaType: fileType.toString(), + title: '01', + width: '0', + height: '0', + orientation: '0', + duration: '0', + } +} +function isNum(value) { + return typeof value === 'number' && !isNaN(value); +} +async function checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) { + expect(fetchFileResult != undefined).assertTrue(); + expect(fetchFileResult.getCount() == count).assertTrue(); + let asset = await fetchFileResult.getFirstObject(); + + if (count > 1) { + type = asset.mimeType.match(/[a-z]+/g)[0] + } + if (type == 'audio' && asset.artist != props[type].artist) { + expect(false).assertTrue(); + done(); + } + if (typesArr) { + let assetList = await fetchFileResult.getAllObject(); + for (const assetItem of assetList) { + expect(typesArr.includes(assetItem.mimeType)).assertTrue(); + } + } + if(!isNum(asset.dateTaken)) { + expect(false).assertTrue(); + done(); + } + if ( + asset.mimeType != props[type].mimeType || + asset.displayName != props[type].displayName || + asset.relativePath != props[type].relativePath || + asset.size != props[type].size || + asset.mediaType != props[type].mediaType || + asset.title != props[type].title || + asset.width != props[type].width || + asset.height != props[type].height || + asset.orientation != props[type].orientation || + asset.duration != props[type].duration + ) { + expect(false).assertTrue(); + done(); + } +} + +export default function mediaLibraryTestPromiseTest(abilityContext){ + describe('mediaLibraryTestPromiseTest', function () { + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(abilityContext); + + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(async function () { await sleep(200)}); + afterAll(function () { }); + + var timestamp = new Date().getTime(); + var jpgName = timestamp + '.jpg'; + var videoName = timestamp + '.mp4'; + var audioName = timestamp + '.mp3'; + var fileName = timestamp + '.mp3'; + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 + * @tc.name : getMediaLibrary + * @tc.desc : Obtains a MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { + try { + expect(media != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageRelativefetchOp); + let count = 1; + let type = 'image'; + await checkFileAssetAttr(done, fetchFileResult, type, count, null) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(videoRelativefetchOp); + let count = 1; + let type = 'video'; + await checkFileAssetAttr(done, fetchFileResult, type, count, null) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(audioRelativefetchOp); + let count = 1; + let type = 'audio'; + await checkFileAssetAttr(done, fetchFileResult, type, count, null) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(fileRelativefetchOp); + let count = 1; + let type = 'file'; + await checkFileAssetAttr(done, fetchFileResult, type, count, null) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); + let count = 2; + let type = 'video'; + let typesArr = ['image/*', 'video/mp4'] + await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp); + let count = 3; + let type = 'file'; + let typesArr = ['image/*', 'video/mp4', 'file/*'] + await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp); + let count = 4; + let type = 'audio'; + let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg'] + await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', + selectionArgs: ['abc'], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 008 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 008 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['abc', audioType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 009 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 009 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 010 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 010 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 011 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 011 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_CAMERA + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { + try { + let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; + + const dicResult = await media.getPublicDirectory(DIR_CAMERA); + + expect(dicResult == 'Camera/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { + try { + let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; + + const dicResult = await media.getPublicDirectory(DIR_VIDEO); + console.log(dicResult); + expect(dicResult == 'Videos/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { + try { + let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; + + const dicResult = await media.getPublicDirectory(DIR_IMAGE); + + expect(dicResult == 'Pictures/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { + try { + let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; + + const dicResult = await media.getPublicDirectory(DIR_AUDIO); + + expect(dicResult == 'Audios/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { + try { + let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + + const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS); + + expect(dicResult == 'Documents/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory 110 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { + try { + await media.getPublicDirectory(110); + console.info('MediaLibraryTest : getPublicDirectory 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getPublicDirectory 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + + const creatAsset1 = await media.createAsset(imageType, jpgName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, jpgName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 002 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 002 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, videoName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 003 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, videoName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 004 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 004 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(audioType, audioName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 005 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, audioName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 006 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(audioType, fileName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 007 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(fileType, fileName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 008 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 008 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const filePath = path + "image/"; + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, jpgName, filePath); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + console.info('MediaLibraryTest : createAsset 009 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + }); +} + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets old mode 100644 new mode 100755 index 3ead107e486358c6d30056594edc9cc5092108f1..3d7848207a4b3a9d8eb9082eafb5792739d90391 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/ets/test/mediaLibraryTestPromiseOnOff.test.ets @@ -1,647 +1,647 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import fileio from '@ohos.fileio'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -export default function mediaLibraryTestPromiseOnOffTest(abilityContext){ - describe('mediaLibraryTestPromiseOnOffTest', function () { - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(abilityContext); - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(function () { }); - afterAll(function () { }); - let fileKeyObj = mediaLibrary.FileKey; - let imageType = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - let fileType = mediaLibrary.MediaType.FILE; - - let imagesfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Pictures/Dynamic01/', imageType.toString()], - }; - let videosfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Videos/Dynamic01/', videoType.toString()], - }; - let audiosfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Audios/Dynamic01/', audioType.toString()], - }; - let filesfetchOp = { - selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['Documents/Dynamic01/', fileType.toString()], - }; - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001 - * @tc.name : ON - * @tc.desc : ON Image ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) { - try { - let conut = 0; - media.on('imageChange', () => { - console.info('MediaLibraryTest : on 001 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 001 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002 - * @tc.name : ON - * @tc.desc : ON Video ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) { - try { - let conut = 0; - media.on('videoChange', () => { - console.info('MediaLibraryTest : on 002 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 002 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003 - * @tc.name : ON - * @tc.desc : ON Audio ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) { - try { - let conut = 0; - media.on('audioChange', () => { - console.info('MediaLibraryTest : on 003 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 003 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004 - * @tc.name : ON - * @tc.desc : ON File ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) { - try { - let conut = 0; - media.on('fileChange', () => { - console.info('MediaLibraryTest : on 004 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut > 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 004 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005 - * @tc.name : ON - * @tc.desc : ON ALBUM ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) { - try { - let conut = 0; - media.on('albumChange', () => { - console.info('MediaLibraryTest : on 005 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 005 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('albumChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 - * @tc.name : ON - * @tc.desc : ON DEVICE ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) { - try { - let conut = 0; - expect(true).assertTrue(); - done(); - media.on('deviceChange', () => { - console.info('MediaLibraryTest : on 006 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('deviceChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 - * @tc.name : ON - * @tc.desc : ON REMOTE_FILE ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) { - try { - let conut = 0; - expect(true).assertTrue(); - done(); - media.on('remoteFileChange', () => { - console.info('MediaLibraryTest : on 007 callback'); - conut++; - }); - const fetchFileResult = await media.getFileAssets(filesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - expect(conut == 0).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('remoteFileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001 - * @tc.name : off - * @tc.desc : off Image ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) { - try { - media.on('imageChange', () => { - console.info('MediaLibraryTest : off 001 failed'); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('imageChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 001 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('imageChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002 - * @tc.name : off - * @tc.desc : off video ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) { - try { - media.on('videoChange', () => { - console.info('MediaLibraryTest : off 002 failed'); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('videoChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 002 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 002 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('videoChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003 - * @tc.name : off - * @tc.desc : off audio ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) { - try { - media.on('audioChange', () => { - console.info('MediaLibraryTest : off 003 failed'); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('audioChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 003 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 003 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('audioChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004 - * @tc.name : off - * @tc.desc : off file ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) { - try { - media.on('fileChange', () => { - console.info('MediaLibraryTest : off 004 failed'); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'changename'; - media.off('fileChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 004 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 004 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005 - * @tc.name : off - * @tc.desc : off album ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { - try { - media.on('albumChange', () => { - console.info('MediaLibraryTest : off 005 failed'); - expect(false).assertTrue(); - media.off('albumChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'albumChange'; - media.off('albumChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 005 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 005 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 - * @tc.name : off - * @tc.desc : off device ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006', 0, async function (done) { - try { - media.on('deviceChange', () => { - console.info('MediaLibraryTest : off 006 failed'); - expect(false).assertTrue(); - media.off('deviceChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'deviceChange'; - media.off('deviceChange'); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 006 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007 - * @tc.name : off - * @tc.desc : off remoteFile ASSET - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007', 0, async function (done) { - try { - media.on('remoteFileChange', () => { - console.info('MediaLibraryTest : off 007 failed'); - expect(false).assertTrue(); - media.off('remoteFileChange'); - done(); - }); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 300) - }) - - media.off('remoteFileChange'); - const fetchFileResult = await media.getFileAssets(videosfetchOp); - const asset = await fetchFileResult.getFirstObject(); - asset.title = asset.title + 'remoteFileChange'; - await new Promise(res => { - setTimeout(() => { - res(true) - }, 600) - }) - await asset.commitModify(); - await new Promise(res => { - setTimeout(() => { - res(true) - }, 1000) - }) - console.info('MediaLibraryTest : off 007 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); - expect(false).assertTrue(); - media.off('fileChange'); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001 - * @tc.name : release - * @tc.desc : Release MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) { - try { - await media.release(); - console.info('MediaLibraryTest : release 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : release 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - }); -} - - +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +export default function mediaLibraryTestPromiseOnOffTest(abilityContext){ + describe('mediaLibraryTestPromiseOnOffTest', function () { + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(abilityContext); + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(function () { }); + afterAll(function () { }); + let fileKeyObj = mediaLibrary.FileKey; + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + let fileType = mediaLibrary.MediaType.FILE; + + let imagesfetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Pictures/Dynamic01/', imageType.toString()], + }; + let videosfetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Videos/Dynamic01/', videoType.toString()], + }; + let audiosfetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Audios/Dynamic01/', audioType.toString()], + }; + let filesfetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['Documents/Dynamic01/', fileType.toString()], + }; + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001 + * @tc.name : ON + * @tc.desc : ON Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) { + try { + let conut = 0; + media.on('imageChange', () => { + console.info('MediaLibraryTest : on 001 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut > 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 001 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002 + * @tc.name : ON + * @tc.desc : ON Video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) { + try { + let conut = 0; + media.on('videoChange', () => { + console.info('MediaLibraryTest : on 002 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut > 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 002 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003 + * @tc.name : ON + * @tc.desc : ON Audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) { + try { + let conut = 0; + media.on('audioChange', () => { + console.info('MediaLibraryTest : on 003 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut > 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 003 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004 + * @tc.name : ON + * @tc.desc : ON File ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) { + try { + let conut = 0; + media.on('fileChange', () => { + console.info('MediaLibraryTest : on 004 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut > 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 004 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005 + * @tc.name : ON + * @tc.desc : ON ALBUM ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) { + try { + let conut = 0; + media.on('albumChange', () => { + console.info('MediaLibraryTest : on 005 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut == 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 005 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('albumChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON DEVICE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('deviceChange', () => { + console.info('MediaLibraryTest : on 006 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut == 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON REMOTE_FILE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('remoteFileChange', () => { + console.info('MediaLibraryTest : on 007 callback'); + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + expect(conut == 0).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001 + * @tc.name : off + * @tc.desc : off Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) { + try { + media.on('imageChange', () => { + console.info('MediaLibraryTest : off 001 failed'); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + media.off('imageChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 001 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002 + * @tc.name : off + * @tc.desc : off video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) { + try { + media.on('videoChange', () => { + console.info('MediaLibraryTest : off 002 failed'); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + media.off('videoChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 002 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 002 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003 + * @tc.name : off + * @tc.desc : off audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) { + try { + media.on('audioChange', () => { + console.info('MediaLibraryTest : off 003 failed'); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + media.off('audioChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 003 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 003 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004 + * @tc.name : off + * @tc.desc : off file ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) { + try { + media.on('fileChange', () => { + console.info('MediaLibraryTest : off 004 failed'); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'changename'; + media.off('fileChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 004 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 004 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005 + * @tc.name : off + * @tc.desc : off album ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { + try { + media.on('albumChange', () => { + console.info('MediaLibraryTest : off 005 failed'); + expect(false).assertTrue(); + media.off('albumChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'albumChange'; + media.off('albumChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 005 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 005 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 + * @tc.name : off + * @tc.desc : off device ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006', 0, async function (done) { + try { + media.on('deviceChange', () => { + console.info('MediaLibraryTest : off 006 failed'); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'deviceChange'; + media.off('deviceChange'); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 006 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007 + * @tc.name : off + * @tc.desc : off remoteFile ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007', 0, async function (done) { + try { + media.on('remoteFileChange', () => { + console.info('MediaLibraryTest : off 007 failed'); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + }); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 300) + }) + + media.off('remoteFileChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.title = asset.title + 'remoteFileChange'; + await new Promise(res => { + setTimeout(() => { + res(true) + }, 600) + }) + await asset.commitModify(); + await new Promise(res => { + setTimeout(() => { + res(true) + }, 1000) + }) + console.info('MediaLibraryTest : off 007 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001 + * @tc.name : release + * @tc.desc : Release MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) { + try { + await media.release(); + console.info('MediaLibraryTest : release 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : release 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + }); +} + + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/module.json b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/module.json old mode 100644 new mode 100755 index 82fb1970953e8e320b149a3885c079feaf97b750..8e0400fc761d17bbb4800f146c44da034a4bb89e --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/module.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/module.json @@ -1,67 +1,67 @@ -{ - "module": { - "name": "phone", - "type": "entry", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:mainability_description", - "mainElement": "MainAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "uiSyntax": "ets", - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", - "description": "$string:mainability_description", - "icon": "$media:icon", - "label": "$string:entry_MainAbility", - "visible": true, - "orientation": "portrait", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_BUNDLE_INFO", - "reason": "use ohos.permission.GET_BUNDLE_INFO" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - }, - { - "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, - { - "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", - "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.MEDIA_LOCATION", - "reason":"use ohos.permission.MEDIA_LOCATION" - }, - { - "name": "ohos.permission.READ_MEDIA", - "reason":"use ohos.permission.READ_MEDIA" - }, - { - "name": "ohos.permission.WRITE_MEDIA", - "reason":"use ohos.permission.WRITE_MEDIA" - } - ] - } -} +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:mainability_description", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ohos.acts.multimedia.mediaLibrary.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:mainability_description", + "icon": "$media:icon", + "label": "$string:entry_MainAbility", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.MEDIA_LOCATION", + "reason":"use ohos.permission.MEDIA_LOCATION" + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason":"use ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason":"use ohos.permission.WRITE_MEDIA" + } + ] + } +} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/element/string.json b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/element/string.json old mode 100644 new mode 100755 index d75a3fee650de2abaabfd60f40d90d9c6a4b0b0b..32237ee203edf64926964fb238fa44e396ddf577 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/element/string.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "MediaLibraryJSTestMain" - }, - { - "name": "mainability_description", - "value": "MediaLibraryJSTestMain Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "MediaLibraryJSTestMain" + }, + { + "name": "mainability_description", + "value": "MediaLibraryJSTestMain Ability" + } + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/media/icon.png b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/media/icon.png old mode 100644 new mode 100755 diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/profile/main_pages.json b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/profile/main_pages.json old mode 100644 new mode 100755 index 6898b31d2085f478ee1ed9d933a5910cbf901d92..96b478210df9884592229ae2db6f6bb7f86c14f4 --- a/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/profile/main_pages.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ -{ - "src": [ - "pages/index/index", - "pages/second/second" - ] +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] } \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/signature/openharmony_sx.p7b b/multimedia/medialibrary/mediaLibrary_js_standard/signature/openharmony_sx.p7b old mode 100644 new mode 100755