diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index 89c38a1bea38ba02806c1626f4c694a4626f4bb0..0ad584ca9f3dc5f4930e838d0b1595644ee07f64 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -27,7 +27,7 @@ group("multimedia") { #"media/media_js_standard/videoPlayer:video_player_js_hap", #"media/media_js_standard/videoRecorder:video_recorder_js_hap", - #"medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap", + "medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap", #"media/media_js_standard/audioRecorder:audio_recorder_js_hap", ] diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/Test.json b/multimedia/medialibrary/mediaLibrary_js_standard/Test.json index 7fc7813724af8e20e36f8b09cfe0ba11d570fcff..2347155359d3abc191401c54c4d9182ada44a520 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/Test.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/Test.json @@ -14,7 +14,9 @@ "push": [ "./resource/medialibrary/01.jpg ->/storage/media/100/local/files", "./resource/medialibrary/01.mp3 ->/storage/media/100/local/files", - "./resource/medialibrary/01.mp4 ->/storage/media/100/local/files" + "./resource/medialibrary/01.mp4 ->/storage/media/100/local/files", + "./resource/medialibrary/test.dat ->/storage/media/100/local/files", + "./resource/medialibrary/test2.dat ->/storage/media/100/local/files" ] }, { @@ -35,6 +37,9 @@ "cp /storage/media/100/local/files/01.mp3 /storage/media/100/local/files/camera/02.mp3", "cp /storage/media/100/local/files/01.mp4 /storage/media/100/local/files/camera/01.mp4", "cp /storage/media/100/local/files/01.mp4 /storage/media/100/local/files/camera/02.mp4", + "mkdir /storage/media/100/local/files/File", + "cp /storage/media/100/local/files/test.dat /storage/media/100/local/files/File/test.dat", + "cp /storage/media/100/local/files/test2.dat /storage/media/100/local/files/File/test2.dat", "chmod -R 777 /storage/media/100/local/files/*", "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", "killall com.ohos.medialibrary.MediaScannerAbilityA", @@ -53,3 +58,4 @@ } ] } + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/config.json b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/config.json index bd7d14fc7a864b01aac9b333359705230b97ea2a..6b3b968134fcb0c70805b5143fcc6c84bb269649 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/config.json +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/config.json @@ -75,7 +75,7 @@ "autoDesignWidth": true } } - ] + ], "reqPermissions": [ { "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" @@ -85,4 +85,4 @@ } ] } -} \ No newline at end of file +} diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js index b32a15bce2ec3364e70878e0c02cfddf9e239c07..030ee1ce4516f99e17292176d1b75e36de9d2adc 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js @@ -12,14 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +require('./favoriteTestCallBack.test.js') +require('./favoriteTestPromise.test.js') require('./fileTestPromise.test.js') -require('./albumTestPromise.test.js') -require('./fileTestCallBack.test.js') -require('./favTestCallBack.test.js') -require('./albumTestCallBack.test.js') -require('./getMediaFileAssetStatus.test.js') -require('./favTestPromise.test.js') -require('./fileTestCallBack.test.js') -require('./favTestCallBack.test.js') -require('./albumTestCallBack.test.js') -require('./FileAssetGetThumbnail.js') diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestCallBack.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3b2776a01135449057f3a5220ae2c82fbddbd5a9 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestCallBack.test.js @@ -0,0 +1,1389 @@ +/* + * 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'; +const fileKeyObj = mediaLibrary.FileKey; +const fileType = mediaLibrary.MediaType.FILE; +const imageType = mediaLibrary.MediaType.IMAGE; +const videoType = mediaLibrary.MediaType.VIDEO; +const audioType = mediaLibrary.MediaType.AUDIO; +const fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; +const imageFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +const videoFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +const audioFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; + +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 () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + // ------------------------------ file type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_01 + * @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_001_01', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_01 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_02 + * @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_001_02', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + + }); + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_02 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_03 + * @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_001_03', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('true', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_03 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_03 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_03 pass'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_04 + * @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_001_04', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('false', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_04 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_04 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_04 pass'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_05 + * @tc.name : favorite + * @tc.desc : favorite(file) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_05', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('fav', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_05 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_05 pass'); + expect(true).assertTrue(); + done(); + } + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_05 pass'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_06 + * @tc.name : favorite + * @tc.desc : favorite(file) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_06', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(666, () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_06 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_06 pass'); + expect(true).assertTrue(); + done(); + } + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_06 pass'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_07 + * @tc.name : favorite + * @tc.desc : favorite(file) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_07', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(() => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_07 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_07 pass'); + expect(true).assertTrue(); + done(); + } + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_07 pass'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_08 + * @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_001_08', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_08 pass'); + expect(true).assertTrue(); + done(); + } + }) + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_08 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(file) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_001_09', 0, async function (done) { + try { + media.getFileAssets(fileFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_09 fail'); + expect(false).assertTrue(); + done(); + } + }) + }); + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 001_09 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ file type end ------------------------ + + + // ------------------------------ image type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_01 + * @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_002_01', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_01 failed'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_02 + * @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_002_02', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + + }); + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_03 + * @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_002_03', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('true', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_03 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_04 + * @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_002_04', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('false', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_04 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_05 + * @tc.name : favorite + * @tc.desc : favorite(image) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_05', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('fav', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_05 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_06 + * @tc.name : favorite + * @tc.desc : favorite(image) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_06', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(666, () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_06 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_07 + * @tc.name : favorite + * @tc.desc : favorite(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_07', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(() => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_07 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_08 + * @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_002_08', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_08 pass'); + expect(true).assertTrue(); + done(); + } + }) + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(image) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_002_09', 0, async function (done) { + try { + media.getFileAssets(imageFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_09 fail'); + expect(false).assertTrue(); + done(); + } + }) + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 002_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ image type end ------------------------ + + // ------------------------------ video type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_01 + * @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_003_01', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_02 + * @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_003_02', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_03 + * @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_003_03', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('true', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_03 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_04 + * @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_003_04', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('false', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_04 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_05 + * @tc.name : favorite + * @tc.desc : favorite(video) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_05', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('fav', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_05 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_06 + * @tc.name : favorite + * @tc.desc : favorite(video) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_06', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(666, () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_06 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_07 + * @tc.name : favorite + * @tc.desc : favorite(video) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_07', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(() => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_07 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_08 + * @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_003_08', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_08 pass'); + expect(true).assertTrue(); + done(); + } + }) + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(video) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_003_09', 0, async function (done) { + try { + media.getFileAssets(videoFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_09 fail'); + expect(false).assertTrue(); + done(); + } + }) + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 003_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ video type end ------------------------ + + // ------------------------------ audio type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_01 + * @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_004_01', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_02 + * @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_004_02', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_03 + * @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_004_03', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('true', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_03 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_04 + * @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_004_04', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('false', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_04 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_05 + * @tc.name : favorite + * @tc.desc : favorite(audio) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_05', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite('fav', () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_05 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_06 + * @tc.name : favorite + * @tc.desc : favorite(audio) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_06', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(666, () => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_06 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_07 + * @tc.name : favorite + * @tc.desc : favorite(audio) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_07', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + try { + asset.favorite(() => { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_07 fail'); + expect(false).assertTrue(); + done(); + }) + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_08 + * @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_004_08', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_08 pass'); + expect(true).assertTrue(); + done(); + } + }) + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(audio) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_004_09', 0, async function (done) { + try { + media.getFileAssets(audioFetchOp, (error, fileAssets) => { + fileAssets.getAllObject((error, dataList) =>{ + const asset = dataList[0]; + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_09 fail'); + expect(false).assertTrue(); + done(); + } + }) + }); + }); + }); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_CALLBACK 004_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ audio type end ------------------------ +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestPromise.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e9ce86074c6b6b3bdb55ad546a0c6482e6aed90e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestPromise.test.js @@ -0,0 +1,1112 @@ +/* + * 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'; +const fileKeyObj = mediaLibrary.FileKey; +const fileType = mediaLibrary.MediaType.FILE; +const imageType = mediaLibrary.MediaType.IMAGE; +const videoType = mediaLibrary.MediaType.VIDEO; +const audioType = mediaLibrary.MediaType.AUDIO; +const fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; +const imageFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +const videoFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +const audioFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; + +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 () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + // ------------------------------ file type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_01 + * @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_001_01', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_01 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_01 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_02 + * @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_001_02', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (!isFavorite) { + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_02 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_02 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_02 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_03 + * @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_001_03', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('true'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_03 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_04 + * @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_001_04', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('false'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_04 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_05 + * @tc.name : favorite + * @tc.desc : favorite(file) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_05', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('fav'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_05 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_06 + * @tc.name : favorite + * @tc.desc : favorite(file) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_06', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(666); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_06 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_07 + * @tc.name : favorite + * @tc.desc : favorite(file) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_07 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_08 + * @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_001_08', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_08 failed'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_08 passed'); + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(file) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_001_09', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(fileFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_09 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_09 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 001_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ file type end ------------------------ + + // ------------------------------ image type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_01 + * @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_002_01', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_01 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_01 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_02 + * @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_002_02', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (!isFavorite) { + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_02 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_02 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_02 failed'); + + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_03 + * @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_002_03', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('true'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_03 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_04 + * @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_002_04', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('false'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_04 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_05 + * @tc.name : favorite + * @tc.desc : favorite(image) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_05', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('fav'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_05 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_06 + * @tc.name : favorite + * @tc.desc : favorite(image) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_06', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(666); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_06 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_07 + * @tc.name : favorite + * @tc.desc : favorite(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_07 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_08 + * @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_002_08', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_08 failed'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_08 passed'); + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(image) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_002_09', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imageFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_09 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_09 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 002_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ image type end ------------------------ + + // ------------------------------ video type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_01 + * @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_003_01', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_01 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_01 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_02 + * @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_003_02', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (!isFavorite) { + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_02 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_02 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_02 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_03 + * @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_003_03', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('true'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_03 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_04 + * @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_003_04', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('false'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_04 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_05 + * @tc.name : favorite + * @tc.desc : favorite(video) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_05', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('fav'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_05 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_06 + * @tc.name : favorite + * @tc.desc : favorite(video) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_06', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(666); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_06 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_07 + * @tc.name : favorite + * @tc.desc : favorite(video) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_07 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_08 + * @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_003_08', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_08 failed'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_08 passed'); + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(video) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_003_09', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videoFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_09 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_09 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 003_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ video type end ------------------------ + + // ------------------------------ audio type start ------------------------ + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_01 + * @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_004_01', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_01 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_01 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_02 + * @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_004_02', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (!isFavorite) { + await asset.favorite(true); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_02 failed'); + expect(false).assertTrue(); + done(); + } + } + await asset.favorite(false); + isFavorite = await asset.isFavorite(); + if (!isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_02 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_02 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_03 + * @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_004_03', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('true'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_03 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_04 + * @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_004_04', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('false'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_04 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_05 + * @tc.name : favorite + * @tc.desc : favorite(audio) by 'fav' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_05', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite('fav'); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_05 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_06 + * @tc.name : favorite + * @tc.desc : favorite(audio) by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_06', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(666); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_06 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_07 + * @tc.name : favorite + * @tc.desc : favorite(audio) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(); + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_07 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_08 + * @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_004_08', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_08 failed'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_08 passed'); + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_08 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_09 + * @tc.name : isFavorite + * @tc.desc : isFavorite(audio) result true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_004_09', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audioFetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_09 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_09 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : FAV_ASSET_PROMISE 004_09 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ audio type end ------------------------ +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestPromise.test.js index 137232f6a5ff286709a0d31bb4b435131368e356..44d9c83819dbea2c9643295bb5cd0c007128a474 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestPromise.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 @@ -14,1104 +14,1451 @@ */ import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -let fileKeyObj = mediaLibrary.FileKey -let type1 = mediaLibrary.MediaType.IMAGE -let fileHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", - selectionArgs: [type1.toString()], -} - -let fileNoArgsfetchOp = { - selections: "", - selectionArgs: [], -} -let fileDeviceArgsfetchOp = { - selections: "", - selectionArgs: [], - networdId: "0", +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; + +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 filesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; + +function checkAssetAttr(done, attr, testNum, asset, checkType) { + if (checkType && asset[attr] != checkType) { + console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`); + expect(false).assertTrue(); + done(); + } else if (asset[attr] == undefined) { + console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`); + expect(false).assertTrue(); + done(); + } } - describe('file.promise.test.js', function () { - var asset; - var assetMove; - var assetMovePromise; 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(function () { - console.info('File Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); - }) - afterAll(function () { - console.info('File Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - }) + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + 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 - * @tc.name : Create an asset in predefined path - * @tc.desc : Create an asset in predefined path + * @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) { - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - console.info('MediaLibraryTest : Delete begin'); - let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfoDelete); - console.info('MediaLibraryTest : Delete end'); - let mediaType = mediaLibrary.MediaType.IMAGE; - let path = "Pictures/"; - let pathMove = "Pictures/Move/"; - let pathMovePromise = "Pictures/Move/Promise/"; - asset = await media.createAsset(mediaType, "image01.jpg", path); - assetMove = await media.createAsset(mediaType, "image01Move.jpg", pathMove); - assetMovePromise = await media.createAsset(mediaType, "image01MovePromise.jpg", pathMovePromise); - console.info('MediaLibraryTest : ASSET_PROMISE asset.displayName = ' + asset.displayName); - console.info('MediaLibraryTest : ASSET_PROMISE asset.title = ' + asset.title); - console.info('MediaLibraryTest : ASSET_PROMISE assetMove.displayName = ' + assetMove.displayName); - let relativePath = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - console.info('MediaLibraryTest : ASSET_PROMISE relativePath = ' + relativePath); - done(); - }); - - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) { - try { - let mediaType = mediaLibrary.MediaType.VIDEO; - let path = "Movies/"; - var asset02 = await media.createAsset(mediaType, "video01.avi", path); - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_02 asset.displayName = ' + - asset02.displayName); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_02 fail, message = ' + error); - } - done(); - }); - - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) { - try { - let mediaType = mediaLibrary.MediaType.VIDEO; - let path = ""; - var asset03 = await media.createAsset(mediaType, "video03.avi", path); - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_03 asset.displayName = ' + - asset03.displayName); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_03 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_04', 0, async function (done) { try { - let mediaType; - let path = "Movies/"; - var asset04 = await media.createAsset(mediaType, "video04.avi", path); - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_04 asset.displayName = ' + - asset04.displayName); - expect(false).assertTrue(); + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, 'image01.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); + + const asset2 = dataList[1]; + const creatAsset2 = await media.createAsset(imageType, 'image02.jpg', 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); + + if (creatAsset1.id != creatAsset2.id) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_04 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_05', 0, async function (done) { - try { - let mediaType; - let path; - var asset05 = await media.createAsset(mediaType, "video05.avi", path); - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_05 asset.displayName = ' + - asset05.displayName); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 failed, message = ' + error); expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE create asset 001_05 fail, message = ' + error); - expect(true).assertTrue(); + done(); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002 - * @tc.name : Modify asset - * @tc.desc : Modify asset + * @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_MODIFY_ASSET_PROMISE_002_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) { try { - asset.title = "image03"; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_01 success'); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', '001_02', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', '001_02', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', '001_02', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_02 passed'); expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_01 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_02', 0, async function (done) { + + /** + * @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 { - asset.relativePath = "Pictures/Move/"; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_02 success'); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', '001_03', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', '001_03', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', '001_03', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_03 passed'); expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_02 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_03', 0, async function (done) { + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_04 + * @tc.name : getFileAssets + * @tc.desc : Access to the file size and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_04', 0, async function (done) { try { - asset.displayName = "image02.jpg" - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_03 success'); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', '001_04', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', '001_04', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', '001_04', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_04 passed'); expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_03 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_04 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_04', 0, async function (done) { + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_05 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateAdded and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_05', 0, async function (done) { try { - asset.orientation = 100; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_04 success'); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', '001_05', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', '001_05', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', '001_05', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_05 passed'); expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_04 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_05 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_05', 0, async function (done) { - try { - asset.title = "image04"; - asset.relativePath = "Pictures/Move/Promise/"; - asset.displayName = "image03.jpg" - asset.orientation = 200; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_05 success'); - expect(true).assertTrue(); + + /** + * @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.displayName = 'hhhhhh'; + 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(newAsset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified ) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); + } + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_05 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_06', 0, async function (done) { + /** + * @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 { - asset.title = "image04?*&@"; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_06 success'); - expect(false).assertTrue(); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', '001_08', firstAsset, imageType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', '001_08', midAsset, imageType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', '001_08', lastAsset, imageType); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_08 passed'); + expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_06 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_08 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_07', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_09 + * @tc.name : getFileAssets + * @tc.desc : Get the width attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_09', 0, async function (done) { try { - asset.displayName = "image04?*&.jpg"; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_07 success'); - expect(false).assertTrue(); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', '001_09', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', '001_09', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', '001_09', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_09 passed'); + expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_07 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_09 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_PROMISE_002_08', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_10 + * @tc.name : createAsset + * @tc.desc : Get the height attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_10', 0, async function (done) { try { - var title = "i"; - for (var i = 0; i < 120; i++) { - title += "i"; - } - asset.title = title; - await asset.commitModify(); - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_08 success'); - expect(false).assertTrue(); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'height', '001_10', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'height', '001_10', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'height', '001_10', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_10 passed'); + expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE modify asset 002_08 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_10 failed, message = ' + error); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_003 - * @tc.name : Get assetList By NoArgsfetchOp - * @tc.desc : Get assetList By NoArgsfetchOp + * @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_GET_ASSET_PROMISE_003_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) { try { - let fetchFileResult = await media.getFileAssets(fileDeviceArgsfetchOp); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 003_01 success'); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'orientation', '001_11', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'orientation', '001_11', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'orientation', '001_11', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_11 passed'); expect(true).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 003_01 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_11 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_003_02', 0, async function (done) { - try { - let fetchFileResult = await media.getFileAssets(); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 003_02 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 003_02 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004 - * @tc.name : Get assetList By HasArgsfetchOp - * @tc.desc : Get assetList By HasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_12 + * @tc.name : createAsset + * @tc.desc : Insert a picture record and get the property as picture * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004_01', 0, async function (done) { - try { - let fetchFileResult = await media.getFileAssets(fileHasArgsfetchOp); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_01 success'); - expect(true).assertTrue(); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_12', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, 'image3.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); + if (creatAsset1.mediaType == imageType) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_01 fail, message = ' + error); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 failed ' + error); expect(false).assertTrue(); + done(); } - done(); }); + // ------------------------------- image type end ----------------------------- - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004_02', 0, async function (done) { - let type2 = mediaLibrary.MediaType.VIDEO - let fileHasArgsfetchOp2 = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", - selectionArgs: [type2.toString()], - } - try { - let fetchFileResult = await media.getFileAssets(fileHasArgsfetchOp2); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_02 success'); - expect(true).assertTrue(); + // ------------------------------- 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 { + 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, 'video01.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); + + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(videoType, 'video02.mp4', 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); + if (creatAsset1.id != creatAsset2.id) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_02 fail, message = ' + error); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed' + error); expect(false).assertTrue(); + done(); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004_03', 0, async function (done) { - let fileHasArgsfetchOp3 = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", - selectionArgs: ["666"], - } + /** + * @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 { - let fetchFileResult = await media.getFileAssets(fileHasArgsfetchOp3); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_03 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_03 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004_04', 0, async function (done) { - let type4 = mediaLibrary.MediaType.VIDEO - let fileHasArgsfetchOp4 = { - selections: "666" + "= ?", - selectionArgs: [type4.toString()], - } - try { - let fetchFileResult = await media.getFileAssets(fileHasArgsfetchOp4); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_04 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_04 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', '002_02', firstAsset); - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_PROMISE_004_05', 0, async function (done) { - let fileHasArgsfetchOp5 = { - selections: "666" + "= ?", - selectionArgs: ["666"], - } - try { - let fetchFileResult = await media.getFileAssets(fileHasArgsfetchOp5); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_05 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE get asset 004_05 fail, message = ' + error); + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', '002_02', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', '002_02', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 passed'); expect(true).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005 - * @tc.name : Open and Close asset - * @tc.desc : Open and Close asset + * @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_OPENANDCLOSE_ASSET_PROMISE_005_01', 0, async function (done) { - var fd; - try { - fd = await asset.open('Rw'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_01 success, fd = ' + fd); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_01 fail, message = ' + error); - expect(false).assertTrue(); - } + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) { try { - asset.close(fd); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_01 success'); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_01 fail, message = ' + error); - expect(false).assertTrue(); - } - done(); - }); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02', 0, async function (done) { - var fd; - try { - fd = await asset.open('w'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_02 success, fd = ' + fd); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_02 fail, message = ' + error); - expect(false).assertTrue(); - } - try { - asset.close(fd); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_02 success'); - expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_02 fail, message = ' + error); - expect(false).assertTrue(); - } - done(); - }); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', '002_04', firstAsset); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03', 0, async function (done) { - var fd; - try { - fd = await asset.open(0.666); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_03 success, fd = ' + fd); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_03 fail, message = ' + error); + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', '002_04', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', '002_04', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_03 passed'); expect(true).assertTrue(); - } - try { - asset.close(fd); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_03 success'); - expect(false).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_03 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04', 0, async function (done) { - var fd; + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_04 + * @tc.name : getFileAssets + * @tc.desc : Access to the file size and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_04', 0, async function (done) { try { - fd = await asset.open(); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_04 success, fd = ' + fd); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_04 fail, message = ' + error); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', '002_04', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', '002_04', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', '002_04', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_04 passed'); expect(true).assertTrue(); - } - try { - asset.close(fd); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_04 success'); - expect(false).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_04 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_04 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05', 0, async function (done) { - var fd; + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_05 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateAdded and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_05', 0, async function (done) { try { - fd = await asset.open(''); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_05 success, fd = ' + fd); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_05 fail, message = ' + error); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', '002_05', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', '002_05', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', '002_05', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 passed'); expect(true).assertTrue(); - } - try { - asset.close(fd); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_05 success'); - expect(false).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_05 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06', 0, async function (done) { - var fd; - try { - fd = await asset.open('Rw'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_06 success, fd = ' + fd); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_06 fail, message = ' + error); - } - try { - asset.close(-1); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_06 success'); - expect(false).assertTrue(); + /** + * @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.displayName = 'hhhhhh'; + 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(newAsset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified ) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); + } + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_06 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07', 0, async function (done) { - var fd; - try { - fd = await asset.open('Rw'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_07 success, fd = ' + fd); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_005_0705 fail, 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 { - asset.close(0); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_07 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_07 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08', 0, async function (done) { - var fd; - try { - fd = await asset.open('Rw'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_08 success, fd = ' + fd); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_08 fail, message = ' + error); - } - try { - asset.close("666"); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_08 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_08 fail, message = ' + error); - expect(true).assertTrue(); - } - done(); - }); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', '002_08', firstAsset, videoType); - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09', 0, async function (done) { - var fd; - try { - fd = await asset.open('Rw'); - console.info('MediaLibraryTest : ASSET_PROMISE open 005_09 success, fd = ' + fd); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE open 005_09 fail, message = ' + error); - } - try { - asset.close(); - console.info('MediaLibraryTest : ASSET_PROMISE close 005_09 success'); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 005_09 fail, message = ' + error); + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', '002_08', midAsset, videoType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', '002_08', lastAsset, videoType); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_08 passed'); expect(true).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_08 failed, message = ' + error); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_AND_TRA_ASSET_PROMISE_006 - * @tc.name : Favourite and Trash - * @tc.desc : Favourite and Trash + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_09 + * @tc.name : getFileAssets + * @tc.desc : Get the width attribute * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_09', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_FAV_AND_TRA_ASSET_PROMISE_006', 0, async function (done) { - let isDirectory = await asset.isDirectory(); - let isFavorite = await asset.isFavorite(); - let isTrash = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isDirectory = ' + isDirectory); - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - console.info('MediaLibraryTest : ASSET_PROMISE Trash = ' + isTrash); - await asset.trash(true); - console.info('MediaLibraryTest : ASSET_PROMISE favorite trash'); - await asset.favorite(true); - console.info('MediaLibraryTest : ASSET_PROMISE favorite success'); - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange = ' + isFavoriteChange); - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange = ' + isTrashChange); - done(); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', '002_09', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', '002_09', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', '002_09', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_09 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_09 failed, message = ' + error); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007 - * @tc.name : Favourite - * @tc.desc : Favourite + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_10 + * @tc.name : createAsset + * @tc.desc : Get the height attribute * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_10', 0, async function (done) { try { - await asset.favorite(true); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_03 success'); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'height', '002_10', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'height', '002_10', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'height', '002_10', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_10 passed'); expect(true).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_03 fail, message = ' + error); - expect(false).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_10 failed, message = ' + error); } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_03 = ' + isFavoriteChange); - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02', 0, async function (done) { + + /** + * @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 { - await asset.favorite(false); - console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_02 success'); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'orientation', '002_11', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'orientation', '002_11', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'orientation', '002_11', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_11 passed'); expect(true).assertTrue(); + done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE close 007_02 fail, message = ' + error); - expect(false).assertTrue(); - } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_02 = ' + isFavoriteChange); - done(); - }); - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03', 0, async function (done) { - try { - 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(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_11 failed, message = ' + error); } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_03 = ' + isFavoriteChange); - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12 + * @tc.name : createAsset + * @tc.desc : Get the duration attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12', 0, async function (done) { try { - 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(); - } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_04 = ' + isFavoriteChange); - done(); - }); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05', 0, async function (done) { - try { - 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(); - } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_05 = ' + isFavoriteChange); - done(); - }); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'duration', '002_12', firstAsset); - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06', 0, async function (done) { - try { - 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); + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'duration', '002_12', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'duration', '002_12', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_12 passed'); expect(true).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_12 failed, message = ' + error); } - let isFavoriteChange = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavoriteChange 007_06 = ' + isFavoriteChange); - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008 - * @tc.name : Is Favourite - * @tc.desc : Is Favourite + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_13 + * @tc.name : createAsset + * @tc.desc : Insert a picture record and get the property as picture * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01', 0, async function (done) { - try { - let isFavorite = await asset.isFavorite(); - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); - expect(true).assertTrue(); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_13', 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, 'video3.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); + if (creatAsset1.mediaType == videoType) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 failed'); expect(false).assertTrue(); done(); } - done(); }); - + // ------------------------------- video type end ----------------------------- + + // ------------------------------- audio type start ---------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009 - * @tc.name : Trash - * @tc.desc : Trash + * @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_TRA_ASSET_PROMISE_009_01', 0, async function (done) { - try { - await asset.trash(true); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01'); - expect(true).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01 fail ,message = ', trashError); - expect(false).assertTrue(); - done(); - } - try { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_01 = ' + isTrashChange); - expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_01 fail, message = ' + isTrashChangeError); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 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, 'audio01.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); + + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(audioType, 'audio02.mp3', 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); + + if (creatAsset1.id != creatAsset2.id) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 failed'); expect(false).assertTrue(); done(); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02', 0, async function (done) { - try { - await asset.trash(false); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02'); - expect(true).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02 fail ,message = ', trashError); - 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 { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_02 = ' + isTrashChange); - expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_02 fail ,message = ' + isTrashChangeError); - expect(false).assertTrue(); - done(); - } - done(); - }); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03', 0, async function (done) { - try { - await asset.trash(666); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03'); - expect(false).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } - try { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_03 = ' + isTrashChange); + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', '003_02', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', '003_02', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', '003_02', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_02 passed'); expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_03 fail ,message = ' + isTrashChangeError); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04', 0, async function (done) { - try { - await asset.trash("666"); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04'); - expect(false).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } + /** + * @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 { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_04 = ' + isTrashChange); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', '003_03', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', '003_03', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', '003_03', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_03 passed'); expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_04 fail ,message = ' + isTrashChangeError); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05', 0, async function (done) { - try { - await asset.trash(0.666); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05'); - expect(false).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_04 + * @tc.name : getFileAssets + * @tc.desc : Access to the file size and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_04', 0, async function (done) { try { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_05 = ' + isTrashChange); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', '003_04', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', '003_04', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', '003_04', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_04 passed'); expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_05 fail ,message = ' + isTrashChangeError); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_04 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06', 0, async function (done) { - try { - await asset.trash(); - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06'); - expect(false).assertTrue(); - } catch (trashError) { - console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06 fail ,message = ' + trashError); - expect(true).assertTrue(); - done(); - } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_05 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateAdded and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_05', 0, async function (done) { try { - let isTrashChange = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_06 = ' + isTrashChange); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', '003_05', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', '003_05', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', '003_05', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_05 passed'); expect(true).assertTrue(); - } catch (isTrashChangeError) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrashChange 009_06 fail ,message = ' + isTrashChangeError); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_05 failed, message = ' + error); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010 - * @tc.name : Is trash - * @tc.desc : Is trash + * @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_ISTRASH_ASSET_PROMISE_0010_01', 0, async function (done) { - try { - let isTrash = await asset.isTrash(); - console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_01 = ' + isTrash); - expect(true).assertTrue(); + 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.displayName = 'hhhhhh'; + 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(newAsset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified ) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); + } + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETPUBLICDIRECTORY_PROMISE 0011 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory + * @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_GETPUBLICDIRECTORY_PROMISE 0011_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) { try { - let relativePath = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_01 relativePath = ' + relativePath); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', '003_08', firstAsset, audioType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', '003_08', midAsset, audioType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', '003_08', lastAsset, audioType); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_08 passed'); expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_01 fail, message = ' + error); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_08 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GETPUBLICDIRECTORY_PROMISE 0011_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_09 + * @tc.name : getFileAssets + * @tc.desc : Get the artist attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_09', 0, async function (done) { try { - let relativePath = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_02 relativePath = ' + relativePath); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', '003_09', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', '003_09', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', '003_09', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_09 passed'); expect(true).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_02 fail, message = ' + error); - expect(false).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_09 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GETPUBLICDIRECTORY_PROMISE 0011_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_10 + * @tc.name : createAsset + * @tc.desc : Get the album attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_10', 0, async function (done) { try { - let relativePath = await media.getPublicDirectory("666"); - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_03 relativePath = ' + relativePath); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_03 fail, message = ' + error); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'albumName', '003_10', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'albumName', '003_10', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'albumName', '003_10', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_10 passed'); expect(true).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_10 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GETPUBLICDIRECTORY_PROMISE 0011_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_11 + * @tc.name : createAsset + * @tc.desc : Get the duration attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_11', 0, async function (done) { try { - let relativePath = await media.getPublicDirectory(666); - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_04 relativePath = ' + relativePath); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_04 fail, message = ' + error); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'duration', '003_11', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'duration', '003_11', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'duration', '003_11', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_11 passed'); expect(true).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_11 failed, message = ' + error); } - done(); }); - it('SUB_MEDIA_MEDIALIBRARY_GETPUBLICDIRECTORY_PROMISE 0011_05', 0, async function (done) { - try { - let relativePath = await media.getPublicDirectory(); - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_05 relativePath = ' + relativePath); - expect(false).assertTrue(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_12 + * @tc.name : createAsset + * @tc.desc : Insert a picture record and get the property as picture + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_12', 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, 'audio3.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); + if (creatAsset1.mediaType == audioType) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE getPublicDirectory 0011_05 fail, message = ' + error); - expect(true).assertTrue(); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 failed'); + expect(false).assertTrue(); done(); } - done(); }); + // ------------------------------- audio type end ----------------------------- + // ------------------------------- file type start ---------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISDIR_ASSET_PROMISE_0012 - * @tc.name : Is Directory - * @tc.desc : Is Directory + * @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_DIR_ASSET_PROMISE_0012_01', 0, async function (done) { - try { - let isDirectory = await asset.isDirectory(); - console.info('MediaLibraryTest : ASSET_PROMISE ISDIRECTORY 0012_01 = ' + isDirectory); - expect(true).assertTrue(); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 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, 'file01.txt', 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); + + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(fileType, 'file02.txt', 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); + + if (creatAsset1.id != creatAsset2.id) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE ISDIRECTORY 0012_01 fail ' + error); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed' + error); expect(false).assertTrue(); done(); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_DELETE_ASSET_PROMISE_0013 - * @tc.name : Delete asset - * @tc.desc : Delete asset + * @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_DELETE_ASSET_PROMISE_0013_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) { try { - await media.deleteAsset(asset.uri); - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_01 SUCCESS '); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', '004_02', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', '004_02', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', '004_02', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_02 passed'); expect(true).assertTrue(); done(); } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_01 file, message = ' + error); - expect(false).assertTrue(); - done(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error); } }); - it('SUB_MEDIA_MEDIALIBRARY_DELETE_ASSET_PROMISE_0013_02', 0, async function (done) { + /** + * @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 { - await media.deleteAsset(666); - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_02 SUCCESS '); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_02 file, message = ' + error); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', '004_03', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', '004_03', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', '004_03', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_03 passed'); expect(true).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error); } }); - it('SUB_MEDIA_MEDIALIBRARY_DELETE_ASSET_PROMISE_0013_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_04 + * @tc.name : getFileAssets + * @tc.desc : Access to the file size and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_04', 0, async function (done) { try { - await media.deleteAsset("666"); - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_03 SUCCESS '); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_03 file, message = ' + error); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', '004_04', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', '004_04', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', '004_04', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_04 passed'); expect(true).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_04 failed, message = ' + error); } }); - it('SUB_MEDIA_MEDIALIBRARY_DELETE_ASSET_PROMISE_0013_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_05 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateAdded and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_05', 0, async function (done) { try { - await media.deleteAsset(0.666); - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_04 SUCCESS '); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_04 file, message = ' + error); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', '004_05', firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', '004_05', midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', '004_05', lastAsset); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_05 passed'); expect(true).assertTrue(); done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_05 failed, message = ' + error); } }); - it('SUB_MEDIA_MEDIALIBRARY_DELETE_ASSET_PROMISE_0013_05', 0, async function (done) { - try { - await media.deleteAsset(); - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_05 SUCCESS '); - expect(false).assertTrue(); - done(); + /** + * @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.displayName = 'hhhhhh'; + 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(newAsset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified ) { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); + } + } else { + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); + } } catch (error) { - console.info('MediaLibraryTest : ASSET_PROMISE deleteAsset 0013_05 file, message = ' + error); - expect(true).assertTrue(); - done(); + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error); } }); - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_RELEASE_PROMISE_0014 - * @tc.name : Release - * @tc.desc : Release + * @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 fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); - // it('SUB_MEDIA_MEDIALIBRARY_RELEASE_PROMISE_0014_01', 0, async function (done) { - // try { - // await media.release(); - // console.info('MediaLibraryTest : ASSET_PROMISE release 0014_01 SUCCESS '); - // done(); - // } catch (error) { - // console.info('MediaLibraryTest : ASSET_PROMISE release 0014_01 file, message = ' + error); - // done(); - // } - // }); - - function getAllObjectInfo(data) { - if (data != undefined) { - console.info('MediaLibraryTest : ASSET_PROMISE id is ' + data.id); - console.info('MediaLibraryTest : ASSET_PROMISE uri is ' + data.uri); - console.info('MediaLibraryTest : ASSET_PROMISE displayName is ' + data.displayName); - console.info('MediaLibraryTest : ASSET_PROMISE mediaType is ' + data.title); - console.info('MediaLibraryTest : ASSET_PROMISE relativePath is ' + data.relativePath); - } else { - console.info('MediaLibraryTest : ASSET_PROMISE getAllObjectInfo no assets'); - } - } + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', '004_08', firstAsset, fileType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', '004_08', midAsset, fileType); - function getAllObjectInfoDelete(data3) { - console.info('MediaLibraryTest : id is ' + data3.id); - console.info('MediaLibraryTest : uri is ' + data3.uri); - console.info('MediaLibraryTest : displayName is ' + data3.displayName); - console.info('MediaLibraryTest : mediaType is ' + data3.mediaType); + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', '004_08', lastAsset, fileType); + + console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_08 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_08 failed, message = ' + error); + } + }); - media.deleteAsset(data3.uri, (err4, data4) => { - if (data4 == 0) { - console.info('MediaLibraryTest : Delete Album Successfull ' + data4); - console.info('MediaLibraryTest : Delete Asset : PASS'); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_09 + * @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_09', 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, 'file3.txt', 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); + + if (creatAsset1.mediaType == fileType) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 passed'); + expect(true).assertTrue(); + done(); } else { - console.info('MediaLibraryTest : Album is not modified ' + err4.message); - console.info('MediaLibraryTest : Modify Asset : FAIL'); + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 failed'); + expect(false).assertTrue(); + done(); } - }); - } -}) + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 failed'); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------- file type end ----------------------------- +}); +