From b354e7254a1700ca7732a4d17b1e1d0e2f714c6b Mon Sep 17 00:00:00 2001 From: zhang-daiyue Date: Mon, 21 Feb 2022 22:55:14 +0800 Subject: [PATCH] Add xts test cases and remove path. Complete the following file test cases - albumTestCallBack.test.js - albumTestPromise.test.js - favtrashTestCallBack.test.js - favtrashTestPromise.test.js remove path fileKeyObj.PATH -> fileKeyObj.dateAdded Signed-off-by: zhang-daiyue Change-Id: Iee605a0560d32a32961982e602b8459cd8421f49 --- .../src/main/js/test/FileAssetGetThumbnail.js | 30 +- .../main/js/test/albumTestCallBack.test.js | 662 +++++++++++++++--- .../src/main/js/test/albumTestPromise.test.js | 329 ++++++--- .../main/js/test/favtrashTestCallBack.test.js | 426 +++++++++++ .../main/js/test/favtrashTestPromise.test.js | 422 +++++++++++ 5 files changed, 1663 insertions(+), 206 deletions(-) create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestCallBack.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestPromise.test.js diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnail.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnail.js index ccb44bc96..460e1bfdf 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnail.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnail.js @@ -38,35 +38,23 @@ describe('GetFileAssets_GetCount_GetAllObjects', function () { var MEDIA_TYPE = 'media_type'; let fileKeyObj = mediaLibrary.FileKey - // let fetchOp = { - // selections : mediaLibrary.PATH + "= ? OR " + mediaLibrary.MEDIA_TYPE + "=?", - // selectionArgs : ["/data/media/images", "IMAGE"], - // order : "ASC", - // } - - // let fetchOp = { - // selections : mediaLibrary.FileKey.PATH + "= ? OR " + mediaLibrary.FileKey.MEDIA_TYPE + "=?", - // selectionArgs : ["/data/media/images", "IMAGE"], - // order : "ASC", - // } - let type = mediaLibrary.MediaType.IMAGE let videoType = mediaLibrary.MediaType.VIDEO let audioType = mediaLibrary.MediaType.AUDIO let fetchOp = { - selections : fileKeyObj.MEDIA_TYPE + "=?", - selectionArgs : [type.toString()], - order: fileKeyObj.PATH, + selections: fileKeyObj.MEDIA_TYPE + "=?", + selectionArgs: [type.toString()], + order: fileKeyObj.dateAdded, } let videoFetchOp = { - selections : fileKeyObj.MEDIA_TYPE + "=?", - selectionArgs : [videoType.toString()], - order: fileKeyObj.PATH, + selections: fileKeyObj.MEDIA_TYPE + "=?", + selectionArgs: [videoType.toString()], + order: fileKeyObj.dateAdded, } let audioFetchOp = { - selections : fileKeyObj.MEDIA_TYPE + "=?", - selectionArgs : [audioType.toString()], - order: fileKeyObj.PATH, + selections: fileKeyObj.MEDIA_TYPE + "=?", + selectionArgs: [audioType.toString()], + order: fileKeyObj.dateAdded, } beforeAll(function () { //onsole.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestCallBack.test.js index d0c083570..fc508a42e 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestCallBack.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestCallBack.test.js @@ -14,154 +14,620 @@ */ import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' +import featureAbility from '@ohos.ability.featureAbility'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -let fileKeyObj = mediaLibrary.FileKey +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +let fileKeyObj = mediaLibrary.FileKey; let mediaType = mediaLibrary.MediaType.IMAGE; let AlbumNoArgsfetchOp = { - selections: "", + selections: '', selectionArgs: [], -} +}; let AlbumHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", + selections: fileKeyObj.MEDIA_TYPE + '= ?', selectionArgs: [mediaType.toString()], -} -let type1 = mediaLibrary.MediaType.IMAGE +}; + let fileHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", - selectionArgs: [type1.toString()], -} + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [mediaType.toString()], +}; let fileNoArgsfetchOp = { - selections: "", + selections: '', selectionArgs: [], -} +}; describe('album.callback.test.js', function () { - let path = "Pictures/" + let path = 'Pictures/'; + console.info('MediaLibraryTest : Delete begin'); + let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp); + let assetList = await fetchFileResult.getAllObject(); + assetList.forEach(getAllObjectInfoDelete); + console.info('MediaLibraryTest : Delete end'); + await media.createAsset(mediaType, 'imageAlbum0003.jpg', path); + await media.createAsset(mediaType2, 'imageAlbum0004.avi', path); var context = featureAbility.getContext(); console.info('MediaLibraryTest : getMediaLibrary IN'); var media = mediaLibrary.getMediaLibrary(context); console.info('MediaLibraryTest : getMediaLibrary OUT'); var album; beforeAll(function () { - onsole.info('Album Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + onsole.info('Album Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); + beforeEach(function () { + console.info('Album Callback MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(function () { + console.info('Album Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + }); + afterAll(function () { + console.info('Album Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); - }) + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by AlbumNoArgsfetchOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - beforeEach(function () { - console.info('Album Callback MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01', 0, async function (done) { + media.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_01 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_01 album.count = ' + album.count); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); - }) - afterEach(function () { - console.info('Album Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - }) - afterAll(function () { - console.info('Album Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02', 0, async function (done) { + media.getAlbums(null, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 album.count = ' + album.count); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_01 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by AlbumHasArgsfetchOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - }) + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_01', 0, async function (done) { + media.getAlbums(AlbumHasArgsfetchOp, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_01 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_01 album.count = ' + album.count); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + done(); + }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001 - * @tc.name : Get Album by AlbumNoArgsfetchOp - * @tc.desc : Get Album by AlbumNoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_02 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by 666 * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001', 0, async function (done) { - media.getAlbums(AlbumNoArgsfetchOp, getAlbumsCallBack); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_02', 0, async function (done) { + media.getAlbums(666, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 album.count = ' + album.count); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_02 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002 - * @tc.name : Get Album by AlbumHasArgsfetchOp - * @tc.desc : Get Album by AlbumHasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_03 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by '666' * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002', 0, async function (done) { - media.getAlbums(AlbumHasArgsfetchOp, getAlbumsCallBack); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_03', 0, async function (done) { + media.getAlbums('666', (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_03 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_03 album.count = ' + album.count); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 001_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); done(); }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_04 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - function getAllObjectInfo(data) { - if (data != undefined) { - console.info('MediaLibraryTest : ALBUM_CALLBACK id is ' + data.id); - console.info('MediaLibraryTest : ALBUM_CALLBACK uri is ' + data.uri); - console.info('MediaLibraryTest : ALBUM_CALLBACK displayName is ' + data.displayName); - console.info('MediaLibraryTest : ALBUM_CALLBACK mediaType is ' + data.title); - console.info('MediaLibraryTest : ALBUM_CALLBACK relativePath is ' + data.relativePath); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getAllObjectInfo no album'); - } - } + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_04', 0, async function (done) { + media.getAlbums(0.666, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_04 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_04 album.count = ' + album.count); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_04 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + done(); + }); - function getAlbumsNoArgsCallBack(err, albumList) { - if (albumList != undefined) { - console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbumsCallBack success'); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack : FAIL'); - done(); - } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_05 + * @tc.name : media.getAlbums + * @tc.desc : Get Album true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - } + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_05', 0, async function (done) { + media.getAlbums(true, (err, albumList) => { + if (albumList != undefined) { + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_05 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_05 album.count = ' + album.count); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbum 002_05 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + done(); + }); - function getAlbumsCallBack(err, albumList) { - if (albumList != undefined) { - album = albumList[0]; - console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbumsCallBack album.albumName = ' + album.albumName); - album.albumName = "helloCallBack"; - album.commitModify(commitModifyCallBack); - album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack); - album.getFileAssets(fileHasArgsfetchOp, getFileAssetsCallBack); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack : FAIL'); - done(); - } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name 'hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - } + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01', 0, async function (done) { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 album.albumName(old) = ' + album.albumName); + album.albumName = 'hello'; + album.commitModify((err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 album.albumName(new) = ' + album.albumName); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); - function commitModifyCallBack(err, data) { - if (data != undefined) { - console.info('MediaLibraryTest : ALBUM_CALLBACK Modify album.albumName = ' + album.albumName); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK Modify Unsuccessfull ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK Modify : FAIL'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name '' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02', 0, async function (done) { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 album.albumName(old) = ' + album.albumName); + album.albumName = ''; + album.commitModify((err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_02 album.albumName(new) = ' + album.albumName); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_02 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_03 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name '?*hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_03', 0, async function (done) { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 album.albumName(old) = ' + album.albumName); + album.albumName = '?*hello'; + album.commitModify((err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_03 album.albumName(new) = ' + album.albumName); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name 'i123456...119' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04', 0, async function (done) { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_01 album.albumName(old) = ' + album.albumName); + var name = 'i'; + for (var i = 0; i < 120; i++) { + title += 'i'; } + album.albumName = name; + album.commitModify((err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_03 album.albumName(new) = ' + album.albumName); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK Modify 003_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); - } + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_01 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileNoArgsfetchOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_01', 0, async function (done) { + album.getFileAssets(fileNoArgsfetchOp, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 getAllObject :PASS'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_01 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_02', 0, async function (done) { + album.getFileAssets(null, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_02 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_02 getAllObject :PASS'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_02 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_02 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_01 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ - function getFileAssetsCallBack(err, albumFetchFileResult) { - if (albumFetchFileResult != undefined) { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssetsCallBack success'); - albumFetchFileResult.getAllObject((err1, data1) => { - if (data1 != undefined) { - data1.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : getFileAssetsCallBack getAllObject :PASS'); - done(); - } - console.info('MediaLibraryTest : getFileAssetsCallBack getFileAssets :No data'); - done(); - }); - done(); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_01', 0, async function (done) { + album.getFileAssets(fileHasArgsfetchOp, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 getAllObject :PASS'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_02 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp2 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_02', 0, async function (done) { + let type2 = mediaLibrary.MediaType.VIDEO; + let fileHasArgsfetchOp2 = { + selections: fileKeyObj.MEDIA_TYPE + ' = ?', + selectionArgs: [type2.toString()], + }; + album.getFileAssets(fileHasArgsfetchOp2, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 getAllObject :PASS'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_03 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_03', 0, async function (done) { + let fileHasArgsfetchOp3 = { + selections: fileKeyObj.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; + album.getFileAssets(fileHasArgsfetchOp3, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getAllObject :PASS'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_04 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_04', 0, async function (done) { + let type4 = mediaLibrary.MediaType.VIDEO; + let fileHasArgsfetchOp4 = { + selections: '666' + '= ?', + selectionArgs: [type4.toString()], + }; + album.getFileAssets(fileHasArgsfetchOp4, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getAllObject :PASS'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_05 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_05', 0, async function (done) { + let fileHasArgsfetchOp5 = { + selections: '666' + '= ?', + selectionArgs: ['666'], + }; + album.getFileAssets(fileHasArgsfetchOp5, (err, albumFetchFileResult) => { + if (albumFetchFileResult != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets success'); + albumFetchFileResult.getAllObject((err1, data1) => { + if (data1 != undefined) { + data1.forEach(getAllObjectInfo); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 success'); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getAllObject :PASS'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err1); + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 getFileAssets :No data'); + expect(false).assertTrue(); + done(); + } + }); + } else { + console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + function getAllObjectInfo(data) { + if (data != undefined) { + console.info('MediaLibraryTest : ALBUM_CALLBACK id is ' + data.id); + console.info('MediaLibraryTest : ALBUM_CALLBACK uri is ' + data.uri); + console.info('MediaLibraryTest : ALBUM_CALLBACK displayName is ' + data.displayName); + console.info('MediaLibraryTest : ALBUM_CALLBACK mediaType is ' + data.title); + console.info('MediaLibraryTest : ALBUM_CALLBACK relativePath is ' + data.relativePath); } else { - console.info('MediaLibraryTest : ASSET_CALLBACK getFileAssetsCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK getFileAssetsCallBack : FAIL'); - done(); + console.info('MediaLibraryTest : ALBUM_CALLBACK getAllObjectInfo no album'); } - } -}) \ No newline at end of file +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestPromise.test.js index 07d0e9900..95eb6b15f 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumTestPromise.test.js @@ -14,60 +14,60 @@ */ import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' +import featureAbility from '@ohos.ability.featureAbility'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -let fileKeyObj = mediaLibrary.FileKey +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +let fileKeyObj = mediaLibrary.FileKey; let mediaType = mediaLibrary.MediaType.IMAGE; let mediaType2 = mediaLibrary.MediaType.VIDEO; let AlbumNoArgsfetchOp = { - selections: "", + selections: '', selectionArgs: [], -} +}; let AlbumHasArgsfetchOp = { - elections: fileKeyObj.MEDIA_TYPE + "= ?", + selections: fileKeyObj.MEDIA_TYPE + '= ?', selectionArgs: [mediaType.toString()], -} +}; let fileHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + "= ?", + selections: fileKeyObj.MEDIA_TYPE + '= ?', selectionArgs: [mediaType.toString()], -} +}; let fileNoArgsfetchOp = { - selections: "", + selections: '', selectionArgs: [], -} - -describe('album.promise.test.js', function () { - - let path = "Pictures/" - var asset; +}; + +describe('album.promise.test.js', async function () { + let path = 'Pictures/'; + console.info('MediaLibraryTest : Delete begin'); + let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp); + let assetList = await fetchFileResult.getAllObject(); + assetList.forEach(getAllObjectInfoDelete); + console.info('MediaLibraryTest : Delete end'); + await media.createAsset(mediaType, 'imageAlbum0003.jpg', path); + await media.createAsset(mediaType2, 'imageAlbum0004.avi', path); var context = featureAbility.getContext(); console.info('MediaLibraryTest : getMediaLibrary IN'); var media = mediaLibrary.getMediaLibrary(context); console.info('MediaLibraryTest : getMediaLibrary OUT'); - var album; - beforeAll(function () { - onsole.info('Album Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); - - }) + beforeAll(function () { + onsole.info('Album Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); beforeEach(function () { - console.info('Album Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); - - }) + console.info('Album Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); afterEach(function () { - console.info('Album Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); - - }) + console.info('Album Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + }); afterAll(function () { - console.info('Album Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + console.info('Album Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); - }) - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001 - * @tc.name : Get Album by AlbumNoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01 + * @tc.name : media.getAlbums * @tc.desc : Get Album by AlbumNoArgsfetchOp * @tc.size : MEDIUM * @tc.type : Function @@ -76,15 +76,8 @@ describe('album.promise.test.js', function () { it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) { try { - console.info('MediaLibraryTest : Delete begin'); - let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp); - let assetList = await fetchFileResult.getAllObject(); - assetList.forEach(getAllObjectInfoDelete); - console.info('MediaLibraryTest : Delete end'); - asset = await media.createAsset(mediaType, "imageAlbum0003.jpg", path); - asset = await media.createAsset(mediaType2, "imageAlbum0004.avi", path); - let albumList = await media.getAlbums(AlbumNoArgsfetchOp); - album = albumList[0]; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 album.albumName = ' + album.albumName); console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 album.count = ' + album.count); expect(true).assertTrue(); @@ -96,10 +89,19 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) { try { - let albumList = await media.getAlbums(); - album = albumList[0]; + const albumList = await media.getAlbums(); + const album = albumList[0]; console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_02 album.albumName = ' + album.albumName); expect(false).assertTrue(); done(); @@ -111,8 +113,8 @@ describe('album.promise.test.js', function () { }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002 - * @tc.name : Get Album by AlbumHasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01 + * @tc.name : media.getAlbums * @tc.desc : Get Album by AlbumHasArgsfetchOp * @tc.size : MEDIUM * @tc.type : Function @@ -121,10 +123,10 @@ describe('album.promise.test.js', function () { it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) { try { - let albumHasList = await media.getAlbums(AlbumHasArgsfetchOp); - let albumHas = albumHasList[0]; - console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 albumHas.albumName = ' + albumHas.albumName); - console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 album.count = ' + album.count); + const albumList = await media.getAlbums(AlbumHasArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 albumHas.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 002_01 album.count = ' + album.count); expect(true).assertTrue(); done(); } catch (error) { @@ -134,9 +136,18 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) { try { - let albumHasList = await media.getAlbums(666); + await media.getAlbums(666); expect(false).assertTrue(); done(); } catch (error) { @@ -146,9 +157,18 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) { try { - let albumHasList = await media.getAlbums("666"); + await media.getAlbums('666'); expect(false).assertTrue(); done(); } catch (error) { @@ -158,9 +178,18 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) { try { - let albumHasList = await media.getAlbums(0.666); + await media.getAlbums(0.666); expect(false).assertTrue(); done(); } catch (error) { @@ -170,9 +199,18 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05 + * @tc.name : media.getAlbums + * @tc.desc : Get Album by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) { try { - let albumHasList = await media.getAlbums(); + await media.getAlbums(true); expect(false).assertTrue(); done(); } catch (error) { @@ -183,9 +221,9 @@ describe('album.promise.test.js', function () { }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003 - * @tc.name : Modify Album - * @tc.desc : Modify Album + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name 'hello' * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 @@ -193,10 +231,13 @@ describe('album.promise.test.js', function () { it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) { try { - album.albumName = "hello"; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName); + album.albumName = 'hello'; await album.commitModify(); expect(true).assertTrue(); - console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName(new) = ' + album.albumName); done(); } catch (error) { console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 fail, message = ' + error); @@ -205,9 +246,20 @@ describe('album.promise.test.js', function () { done(); }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name '' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) { try { - album.albumName = ""; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + album.albumName = ''; await album.commitModify(); console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 album.albumName = ' + album.albumName); expect(false).assertTrue(); @@ -218,22 +270,61 @@ describe('album.promise.test.js', function () { done(); }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name '?*hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_03', 0, async function (done) { try { - album.albumName = "?*hello"; + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + album.albumName = '?*hello'; await album.commitModify(); - console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 album.albumName = ' + album.albumName); + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_03 album.albumName = ' + album.albumName); expect(false).assertTrue(); } catch (error) { - console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 fail, message = ' + error); + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_03 fail, message = ' + error); expect(true).assertTrue(); } done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004 - * @tc.name : Get Album Assets by fileNoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04 + * @tc.name : album.commitModify + * @tc.desc : Modify Album name 'i123456...119' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) { + try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; + var name = 'i'; + for (var i = 0; i < 120; i++) { + title += 'i'; + } + album.albumName = name; + await album.commitModify(); + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 album.albumName = ' + album.albumName); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_01 + * @tc.name : album.getFileAssets * @tc.desc : Get Album Assets by fileNoArgsfetchOp * @tc.size : MEDIUM * @tc.type : Function @@ -242,6 +333,8 @@ describe('album.promise.test.js', function () { it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_01', 0, async function (done) { try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; let albumFetchFileResult = await album.getFileAssets(fileNoArgsfetchOp); let albumAssetList = await albumFetchFileResult.getAllObject(); albumAssetList.forEach(getAllObjectInfo); @@ -255,22 +348,35 @@ describe('album.promise.test.js', function () { done(); }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_02 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_02', 0, async function (done) { try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; let albumFetchFileResult = await album.getFileAssets(); + let albumAssetList = await albumFetchFileResult.getAllObject(); + albumAssetList.forEach(getAllObjectInfo); console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_02 success'); - expect(false).assertTrue(); + expect(true).assertTrue(); } catch (error) { console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_02 fail, message = ' + error); - expect(true).assertTrue(); + expect(false).assertTrue(); done(); } done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005 - * @tc.name : Get Album Assets by fileHasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_01 + * @tc.name : album.getFileAssets * @tc.desc : Get Album Assets by fileHasArgsfetchOp * @tc.size : MEDIUM * @tc.type : Function @@ -279,6 +385,8 @@ describe('album.promise.test.js', function () { it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_01', 0, async function (done) { try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; let albumFetchFileResult = await album.getFileAssets(fileHasArgsfetchOp); let albumAssetList = await albumFetchFileResult.getAllObject(); albumAssetList.forEach(getAllObjectInfo); @@ -292,13 +400,24 @@ describe('album.promise.test.js', function () { done(); }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_02 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp2 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_02', 0, async function (done) { - let type2 = mediaLibrary.MediaType.VIDEO + let type2 = mediaLibrary.MediaType.VIDEO; let fileHasArgsfetchOp2 = { - selections: fileKeyObj.MEDIA_TYPE + " = ?", + selections: fileKeyObj.MEDIA_TYPE + ' = ?', selectionArgs: [type2.toString()], - } + }; try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; await album.getFileAssets(fileHasArgsfetchOp2); console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_02 success'); expect(true).assertTrue(); @@ -310,54 +429,90 @@ describe('album.promise.test.js', function () { } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_03 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_03', 0, async function (done) { let fileHasArgsfetchOp3 = { - selections: fileKeyObj.MEDIA_TYPE + " = ?", - selectionArgs: ["666"], - } + selections: fileKeyObj.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; await album.getFileAssets(fileHasArgsfetchOp3); console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_03 success'); - expect(true).assertTrue(); + expect(false).assertTrue(); done(); } catch (error) { console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_03 fail, message = ' + error); - expect(false).assertTrue(); + expect(true).assertTrue(); + done(); } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_04 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_04', 0, async function (done) { - let type4 = mediaLibrary.MediaType.VIDEO + let type4 = mediaLibrary.MediaType.VIDEO; let fileHasArgsfetchOp4 = { - selections: "666" + "= ?", + selections: '666' + '= ?', selectionArgs: [type4.toString()], - } + }; try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; await album.getFileAssets(fileHasArgsfetchOp4); console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_04 success'); - expect(true).assertTrue(); + expect(false).assertTrue(); done(); } catch (error) { console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_04 fail, message = ' + error); - expect(false).assertTrue(); + expect(true).assertTrue(); + done(); } }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_05 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_05', 0, async function (done) { let fileHasArgsfetchOp5 = { - selections: "666" + "= ?", - selectionArgs: ["666"], - } + selections: '666' + '= ?', + selectionArgs: ['666'], + }; try { + const albumList = await media.getAlbums(AlbumNoArgsfetchOp); + const album = albumList[0]; await album.getFileAssets(fileHasArgsfetchOp5); console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_05 success'); - expect(true).assertTrue(); + expect(false).assertTrue(); done(); } catch (error) { console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_05 fail, message = ' + error); - expect(false).assertTrue(); + expect(true).assertTrue(); + done(); } }); @@ -390,4 +545,4 @@ describe('album.promise.test.js', function () { } }); } -}) \ No newline at end of file +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestCallBack.test.js new file mode 100644 index 000000000..91c392331 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestCallBack.test.js @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('file.callback.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + beforeAll(function () { + console.info('File Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); + beforeEach(function () { + console.info('File Callback MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(function () { + console.info('File Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + }); + afterAll(function () { + console.info('File Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01 + * @tc.name : favorite + * @tc.desc : favorite by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image01.jpg', path); + asset.favorite(true, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02 + * @tc.name : favorite + * @tc.desc : favorite by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image02.jpg', path); + asset.favorite(false, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03 + * @tc.name : favorite + * @tc.desc : favorite by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image03.jpg', path); + asset.favorite(666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04 + * @tc.name : favorite + * @tc.desc : favorite by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image04.jpg', path); + asset.favorite('666', (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05 + * @tc.name : favorite + * @tc.desc : favorite by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image05.jpg', path); + asset.favorite(0.666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06 + * @tc.name : favorite + * @tc.desc : favorite by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image06.jpg', path); + asset.favorite(null, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 success'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 fail, message = ' + err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01 + * @tc.name : isFavorite + * @tc.desc : Is Favourite true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image07.jpg', path); + await asset.favorite(true); + asset.isFavorite((err, isFavorite) => { + if (err == undefined && isFavorite == true) { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 isFavorite = ' + isFavorite); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02 + * @tc.name : isFavorite + * @tc.desc : Is Favourite true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image0702.jpg', path); + await asset.favorite(false); + asset.isFavorite((err, isFavorite) => { + if (err == undefined && isFavorite == false) { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 isFavorite = ' + isFavorite); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 fail, message = ' + err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01 + * @tc.name : trash + * @tc.desc : Trash by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image08.jpg', path); + asset.trash(true, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02 + * @tc.name : trash + * @tc.desc : Trash by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image09.jpg', path); + asset.trash(false, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03 + * @tc.name : trash + * @tc.desc : Trash by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image10.jpg', path); + asset.trash(666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04 + * @tc.name : trash + * @tc.desc : Trash by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image11.jpg', path); + asset.trash('666', (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05 + * @tc.name : trash + * @tc.desc : Trash by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image12.jpg', path); + asset.trash(0.666, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06 + * @tc.name : trash + * @tc.desc : Trash by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image13.jpg', path); + asset.trash(null, (err) => { + if (err == undefined) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06 fail ,message = ', err); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01 + * @tc.name : isTrash + * @tc.desc : isTrash true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image14.jpg', path); + await asset.trash(true); + asset.isTrash((err, isTrash) => { + if (err == undefined && isTrash == true) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02 + * @tc.name : isTrash + * @tc.desc : isTrash false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02', 0, async function (done) { + const asset = await media.createAsset(mediaType, 'image15.jpg', path); + await asset.trash(false); + asset.isTrash((err, isTrash) => { + if (err == undefined && isTrash == false) { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02 fail ,message = ', err); + expect(false).assertTrue(); + done(); + } + }); + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestPromise.test.js new file mode 100644 index 000000000..49ee073bd --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favtrashTestPromise.test.js @@ -0,0 +1,422 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('file.promise.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + beforeAll(function () { + console.info('File Promise MediaLibraryTest: beforeAll : Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }); + beforeEach(function () { + console.info('File Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(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'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01 + * @tc.name : favorite + * @tc.desc : favorite by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image01.jpg', path); + await asset.favorite(true); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_01 success'); + expect(true).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_01 fail, message = ' + error); + expect(false).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02 + * @tc.name : favorite + * @tc.desc : favorite by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image02.jpg', path); + await asset.favorite(false); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_02 success'); + expect(true).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_02 fail, message = ' + error); + expect(false).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03 + * @tc.name : favorite + * @tc.desc : favorite by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image03.jpg', path); + await asset.favorite(666); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_03 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_03 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04 + * @tc.name : favorite + * @tc.desc : favorite by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image04.jpg', path); + await asset.favorite('666'); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_04 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_04 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05 + * @tc.name : favorite + * @tc.desc : favorite by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image05.jpg', path); + await asset.favorite(0.666); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_05 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_05 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06 + * @tc.name : favorite + * @tc.desc : favorite by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image06.jpg', path); + await asset.favorite(); + console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_06 success'); + expect(false).assertTrue(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE close 007_06 fail, message = ' + error); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01 + * @tc.name : isFavorite + * @tc.desc : Is Favourite + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image07.jpg', path); + await asset.favorite(true); + let isFavorite = await asset.isFavorite(); + if (isFavorite == true) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02 + * @tc.name : isFavorite + * @tc.desc : Is Favourite + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image0702.jpg', path); + await asset.favorite(false); + let isFavorite = await asset.isFavorite(); + if (isFavorite == false) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } else { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite); + expect(true).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01 + * @tc.name : trash + * @tc.desc : Trash by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image08.jpg', path); + await asset.trash(true); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01'); + expect(true).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01 fail ,message = ', trashError); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02 + * @tc.name : trash + * @tc.desc : Trash by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image09.jpg', path); + await asset.trash(false); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02'); + expect(true).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02 fail ,message = ', trashError); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03 + * @tc.name : trash + * @tc.desc : Trash by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image10.jpg', path); + await asset.trash(666); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04 + * @tc.name : trash + * @tc.desc : Trash by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image11.jpg', path); + await asset.trash('666'); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05 + * @tc.name : trash + * @tc.desc : Trash by 0.666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image12.jpg', path); + await asset.trash(0.666); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06 + * @tc.name : trash + * @tc.desc : Trash by null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image13.jpg', path); + await asset.trash(); + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06'); + expect(false).assertTrue(); + done(); + } catch (trashError) { + console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06 fail ,message = ' + trashError); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01 + * @tc.name : isTrash + * @tc.desc : isTrash true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image14.jpg', path); + await asset.trash(true); + let isTrash = await asset.isTrash(); + console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_01 = ' + isTrash); + if (isTrash) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_01 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02 + * @tc.name : isTrash + * @tc.desc : isTrash false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02', 0, async function (done) { + try { + const asset = await media.createAsset(mediaType, 'image15.jpg', path); + await asset.trash(false); + let isTrash = await asset.isTrash(); + console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_02 = ' + isTrash); + if (!isTrash) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } + done(); + } catch (error) { + console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_02 fail, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); +}); -- GitLab