diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailCallBack.test.js index dba320bb9a82d06bb24625c8eb1fb4b8fd36bc04..b546df920d555d99fbdb7aad1cee7df2fdbc28b8 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailCallBack.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailCallBack.test.js @@ -1,727 +1,731 @@ -/* - * 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 image from '@@ohos.multimedia.image'; -import featureAbility from '@ohos.ability.featureAbility'; - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -describe('GetFileAssets_GetCount_GetAllObjects', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - var URI; - var name; - var result1; - var albumName; - var albumId; - var i; - var fileAsset; - var MAXNUM = 100; - var PATH = 'data'; - var MEDIA_TYPE = 'media_type'; - let fileKeyObj = mediaLibrary.FileKey; - - 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.dateAdded, - }; - let videoFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [videoType.toString()], - order: fileKeyObj.dateAdded, - }; - let audioFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [audioType.toString()], - order: fileKeyObj.dateAdded, - }; - beforeAll(function () { - }); - - beforeEach(function () { - }); - afterEach(function () { - }); - afterAll(function () { - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 80, height: 80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_01', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 80, height: 80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 80).assertTrue(); - expect(info.size.height == 80).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_02', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 400, height: 400 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 400).assertTrue(); - expect(info.size.height == 400).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 80, height: 80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_03', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 80, height: 80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 80).assertTrue(); - expect(info.size.height == 80).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_04', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 400, height: 400 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 400).assertTrue(); - expect(info.size.height == 400).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_05', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 80, height: 80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 80).assertTrue(); - expect(info.size.height == 80).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_06', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 400, height: 400 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == 400).assertTrue(); - expect(info.size.height == 400).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 256, height: 256 }; - data1.getThumbnail((err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 1, height: 1 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_09 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 0, height: 0 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_010 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_09', 0, async function (done) { - media.getFileAssets(fetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: -80, height: -80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_011 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 256, height: 256 }; - data1.getThumbnail((err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_012 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_012', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 1, height: 1 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_013 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_013', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 0, height: 0 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_014 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_014', 0, async function (done) { - media.getFileAssets(videoFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: -80, height: -80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_015 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_015', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 256, height: 256 }; - data1.getThumbnail((err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_016 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_016', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 1, height: 1 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_017 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_017', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: 0, height: 0 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_018 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_018', 0, async function (done) { - media.getFileAssets(audioFetchOp, (error, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - data.getFirstObject((err1, data1) => { - if (data1 != undefined) { - let size = { width: -80, height: -80 }; - data1.getThumbnail(size, (err2, pixelmap) => { - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - pixelmap.getImageInfo((error, info) => { - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - done(); - }); - }); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - done(); - } - }); - }); -}); +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import image from '@@ohos.multimedia.image'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('fileAssetGetThumbnailCallBack.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + + var URI; + var name; + var result1; + var albumName; + var albumId; + var i; + var fileAsset; + var MAXNUM = 100; + var PATH = 'data'; + var MEDIA_TYPE = 'media_type'; + let fileKeyObj = mediaLibrary.FileKey; + + 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.dateAdded, + }; + let videoFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '=?', + selectionArgs: [videoType.toString()], + order: fileKeyObj.dateAdded, + }; + let audioFetchOp = { + 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.'); + }); + + beforeEach(function () { + //console.info('MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }); + afterEach(function () { + //console.info('MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + }); + afterAll(function () { + //console.info('MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & { width: 80, height: 80 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_01', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 80, height: 80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 80).assertTrue(); + expect(info.size.height == 80).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & { width: 400, height: 400 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_02', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 400, height: 400 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 400).assertTrue(); + expect(info.size.height == 400).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & { width: 80, height: 80 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_03', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 80, height: 80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 80).assertTrue(); + expect(info.size.height == 80).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & { width: 400, height: 400 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_04', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 400, height: 400 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 400).assertTrue(); + expect(info.size.height == 400).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & { width: 400, height: 400 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_05', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 80, height: 80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 80).assertTrue(); + expect(info.size.height == 80).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & { width: 400, height: 400 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_06', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 400, height: 400 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == 400).assertTrue(); + expect(info.size.height == 400).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & & The default size + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 256, height: 256 }; + data1.getThumbnail((err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 1, height: 1 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_09 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_08', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 0, height: 0 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_010 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by fetchOp & { width: -80, height: -80 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_09', 0, async function (done) { + media.getFileAssets(fetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: -80, height: -80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_011 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & & The default size + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_07', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 256, height: 256 }; + data1.getThumbnail((err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_012 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_012', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 1, height: 1 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_013 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_013', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 0, height: 0 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_014 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by videoFetchOp & { width: -80, height: -80 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_014', 0, async function (done) { + media.getFileAssets(videoFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: -80, height: -80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_015 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & & The default size + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_015', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 256, height: 256 }; + data1.getThumbnail((err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_016 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_016', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 1, height: 1 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(false).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_017 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_017', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: 0, height: 0 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_018 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail by audioFetchOp & { width: -80, height: -80 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GET_getThumbnail_018', 0, async function (done) { + media.getFileAssets(audioFetchOp, (error, data) => { + if (data != undefined) { + console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); + data.getFirstObject((err1, data1) => { + if (data1 != undefined) { + let size = { width: -80, height: -80 }; + data1.getThumbnail(size, (err2, pixelmap) => { + console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); + pixelmap.getImageInfo((error, info) => { + console.info('MediaLibraryTest : pixel image info ' + info); + console.info('MediaLibraryTest : pixel width ' + info.size.width); + console.info('MediaLibraryTest : pixel height ' + info.size.height); + expect(false).assertTrue(); + done(); + }); + }); + } + }); + } else { + console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); + console.info('MediaLibraryTest : getFileAssets :FAIL'); + expect(true).assertTrue(); + done(); + } + }); + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailPromise.test.js index a3eb95957fac7a2bad5c21784e8ffb2cda44ada5..a1c19f938b0e6ea99ae5456d4f14ce1623b9ede9 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailPromise.test.js @@ -1,601 +1,759 @@ -/* - * 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 image from '@@ohos.multimedia.image'; -import featureAbility from '@ohos.ability.featureAbility'; - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; - -describe('GetFileAssets_GetCount_GetAllObjects', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - var URI; - var name; - var result1; - var albumName; - var albumId; - var i; - var fileAsset; - var MAXNUM = 100; - var PATH = 'data'; - var MEDIA_TYPE = 'media_type'; - let fileKeyObj = mediaLibrary.FileKey; - - 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.dateAdded, - }; - let videoFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [videoType.toString()], - order: fileKeyObj.dateAdded, - }; - let audioFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '=?', - selectionArgs: [audioType.toString()], - order: fileKeyObj.dateAdded, - }; - beforeAll(function () { - }); - - beforeEach(function () { - }); - afterEach(function () { - }); - afterAll(function () { - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_01 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 80, height: 80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_01', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 80, height: 80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_02 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_02', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 400, height: 400 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_03 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 80, height: 80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_03', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 80, height: 80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_04 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_04', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 400, height: 400 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_05 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 80, height: 80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_05', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 80, height: 80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_06 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 400, height: 400 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_06', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 400, height: 400 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_07 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_07', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 256, height: 256 }; - const pixelmap = await data1.getThumbnail(); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_08 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_08', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 1, height: 1 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_09 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_09', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 0, height: 0 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_010 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by fetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_010', 0, async function (done) { - try { - const data = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: -80, height: -80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_011 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_011', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 256, height: 256 }; - const pixelmap = await data1.getThumbnail(); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_012 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_012', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 1, height: 1 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_013 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_013', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 0, height: 0 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_014 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by videoFetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_014', 0, async function (done) { - try { - const data = await media.getFileAssets(videoFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: -80, height: -80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_015 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & The default size - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_015', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 256, height: 256 }; - const pixelmap = await data1.getThumbnail(); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_016 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 1, height: 1 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_016', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 1, height: 1 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(info.size.width == size.width).assertTrue(); - expect(info.size.height == size.height).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_017 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: 0, height: 0 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_017', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: 0, height: 0 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_018 - * @tc.name : getThumbnail - * @tc.desc : getThumbnail by audioFetchOp & { width: -80, height: -80 } - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_GETTHUMBNAIL_PROMISE_018', 0, async function (done) { - try { - const data = await media.getFileAssets(audioFetchOp); - console.info('MediaLibraryTest : getFileAssets Successfull ' + data.getCount()); - const data1 = await data.getFirstObject(); - let size = { width: -80, height: -80 }; - const pixelmap = await data1.getThumbnail(size); - console.info('MediaLibraryTest : getThumbnail Successfull ' + pixelmap); - const info = pixelmap.getImageInfo(); - console.info('MediaLibraryTest : pixel image info ' + info); - console.info('MediaLibraryTest : pixel width ' + info.size.width); - console.info('MediaLibraryTest : pixel height ' + info.size.height); - expect(false).assertTrue(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + error.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(true).assertTrue(); - } - done(); - }); -}); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import image from '@ohos.multimedia.image'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('FileAssetGetThumbnailPromise.test.js', function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + let fileKeyObj = mediaLibrary.FileKey; + let imagetype = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + let imageFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '=?', + selectionArgs: [imagetype.toString()], + order: fileKeyObj.DATE_ADDED, + }; + let videoFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '=?', + selectionArgs: [videoType.toString()], + order: fileKeyObj.DATE_ADDED, + }; + let audioFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '=?', + selectionArgs: [audioType.toString()], + order: fileKeyObj.DATE_ADDED, + }; + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + // ------------------------------ image type start ----------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 128, height: 128 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_01 pixel image info ' + info); + console.info('MediaLibraryTest : 001_01 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_01 pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_01 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_01 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_01 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 128, height: 256 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_02 pixel image info ' + info); + console.info('MediaLibraryTest : 001_02 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_02 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_02 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_02 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_02 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 256, height: 256 }; + const pixelmap = await asset.getThumbnail(); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_03 pixel image info ' + info); + console.info('MediaLibraryTest : 001_03 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_03 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_03 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_03 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_03 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 1, height: 1 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_04 pixel image info ' + info); + console.info('MediaLibraryTest : 001_04 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_04 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_04 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_04 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_04 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 0, height: 0 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_05 pixel image info ' + info); + console.info('MediaLibraryTest : 001_05 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_05 pixel height ' + info.size.height); + expect(true).assertTrue(); + console.info('MediaLibraryTest : getFileAssets 001_05 failed'); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_05 passed'); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: -128, height: -128 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_06 pixel image info ' + info); + console.info('MediaLibraryTest : 001_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_06 pixel height ' + info.size.height); + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_06 failed'); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_06 passed '); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 1024, height: 1024 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_07 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------image type end-------------------------- + + // // ------------------------------video type start ----------------------- + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 128 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_01 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_01 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_01 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_01 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_01 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_01 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 256 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_02 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_02 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_02 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_02 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_02 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_02 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by no arg + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 256, height: 256 }; + // const pixelmap = await asset.getThumbnail(); + // console.info('MediaLibraryTest : getThumbnail 002_03 Successfull ' + pixelmap); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_03 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_03 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_03 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_03 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_03 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_03 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1, height: 1 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_04 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_04 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_04 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 001_05 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 001_05 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_04 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 0, height: 0 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_05 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_05 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_05 pixel height ' + info.size.height); + // console.info('MediaLibraryTest : getThumbnail 002_05 failed'); + // expect(true).assertTrue(); + // done(); + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_05 passed'); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: -128, height: -128 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_06 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_06 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_06 pixel height ' + info.size.height); + // console.info('MediaLibraryTest : getThumbnail 003_01 failed'); + // expect(true).assertTrue(); + // done(); + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_06 passed'); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1024, height: 1024 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_07 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_07 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_07 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + // // ------------------------------video type end-------------------------- + + // // ------------------------------audio type start ----------------------- + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 128 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_01 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_01 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_01 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_01 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_01 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_01 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 256 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_02 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_02 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_02 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_02 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_02 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_02 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by no arg + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 256, height: 256 }; + // const pixelmap = await asset.getThumbnail(); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_03 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_03 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_03 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_03 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_03 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_03 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1, height: 1 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_04 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_04 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_04 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_04 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_04 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_04 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 0, height: 0 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : getThumbnail 003_06 failed'); + // console.info('MediaLibraryTest : 003_05 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_05 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_05 pixel height ' + info.size.height); + // expect(true).assertTrue(); + // done(); + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_05 passed'); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: -128, height: -128 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + // console.info('MediaLibraryTest : getThumbnail 003_06 failed'); + + // expect(true).assertTrue(); + // done(); + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_06 passed'); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1024, height: 1024 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + // console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_07 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 003_07 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 003_07 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + // ------------------------------audio type end-------------------------- +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/List.test.js index 0c2c72f8ea243de9e6880cc367660523cd926946..d122d3828f309f39da758aeeaab9604fc0199624 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 @@ -1,23 +1,37 @@ -/* - * 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. - */ -require('./favoriteTestCallBack.test.js') -require('./fileTestPromise.test.js') -require('./favoriteTestPromise.test.js') -require('./fileAsset2.test.js') -require('./fileAssetTestPromise.test.js') -require('./mediaLibraryTestPromise.test.js') -require('./albumGetFileAssetsPromise.test.js') -require('./albumTestPromise.test.js') - +/* + * 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. + */ +require('./FileAssetGetThumbnailCallBack.test.js') +require('./FileAssetGetThumbnailPromise.test.js') +require('./albumGetFileAssetsPromise.test.js') +require('./albumTestCallBack.test.js') +require('./albumTestPromise.test.js') +require('./distributed.test.js') +require('./favoriteTestCallBack.test.js') +require('./favoriteTestPromise.test.js') +require('./fetchFileResultCallBack.test.js') +require('./fetchFileResultPromise.test.js') +require('./fileAsset2.test.js') +require('./fileAssetTestPromise.test.js') +require('./fileAssetUriTestCallBack.test.js') +require('./fileTestCallBack.test.js') +require('./fileTestPromise.test.js') +require('./filekeyTestPromise.test.js') +require('./getAllPeersDeviceTestPromise.test.js') +require('./getAllPeersTestPromise.test.js') +require('./mediaLibraryTestPromise.test.js') +require('./mediaLibraryTestPromiseOnOff.test.js') +require('./favtrashTestCallBack.test.js') +require('./favtrashTestPromise.test.js') + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsPromise.test.js index 73bc633a82b56e5ee34ee69bf75b44fb0b1c74ab..f7d775f1381a3e9d49aa2b19b32f805c80add5e0 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsPromise.test.js @@ -16,7 +16,7 @@ import mediaLibrary from '@ohos.multimedia.medialibrary'; import featureAbility from '@ohos.ability.featureAbility'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -describe('fileAssetTestPromise.test.js', async function () { +describe('albumGetFileAssetsPromise.test.js', async function () { var context = featureAbility.getContext(); console.info('MediaLibraryTest : getMediaLibrary IN'); var media = mediaLibrary.getMediaLibrary(context); 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 fc508a42ef32f6af1b9e5da8d472beda9ee19ff7..c31f4bbfe6d3ce7a798317fbf8279ad7f58b41cc 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 @@ -1,633 +1,633 @@ -/* - * 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'; -let fileKeyObj = mediaLibrary.FileKey; -let mediaType = mediaLibrary.MediaType.IMAGE; -let AlbumNoArgsfetchOp = { - selections: '', - selectionArgs: [], -}; -let AlbumHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [mediaType.toString()], -}; - -let fileHasArgsfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [mediaType.toString()], -}; -let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], -}; - -describe('album.callback.test.js', 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 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 - */ - - 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(); - } - }); - }); - - /** - * @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 - */ - - 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_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_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_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_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 - */ - - 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(); - }); - - /** - * @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(); - }); - - /** - * @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(); - } - }); - }); - - /** - * @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 - */ - - 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 : ALBUM_CALLBACK getAllObjectInfo no album'); - } - } -}); +/* + * 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'; +let fileKeyObj = mediaLibrary.FileKey; +let mediaType = mediaLibrary.MediaType.IMAGE; +let AlbumNoArgsfetchOp = { + selections: '', + selectionArgs: [], +}; +let AlbumHasArgsfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [mediaType.toString()], +}; + +let fileHasArgsfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [mediaType.toString()], +}; +let fileNoArgsfetchOp = { + selections: '', + selectionArgs: [], +}; + +describe('album.callback.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 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 + */ + + 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(); + } + }); + }); + + /** + * @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 + */ + + 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_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_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_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_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 + */ + + 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(); + }); + + /** + * @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(); + }); + + /** + * @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(); + } + }); + }); + + /** + * @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 + */ + + 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 : ALBUM_CALLBACK getAllObjectInfo no album'); + } + } +}); 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 5f5f2485f1e45f4b5df034df2804ebbfcf502299..dcc4519c62b3139421883cf18d45cfb59d9c6523 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 @@ -75,7 +75,7 @@ function checkAlbumAttr(done, album) { } } -describe('album.promise.test.js', async function () { +describe('albumTestPromise.test.js', async function () { var context = featureAbility.getContext(); var media = mediaLibrary.getMediaLibrary(context); beforeAll(function () {}); @@ -392,9 +392,7 @@ describe('album.promise.test.js', async function () { }; try { const albumList = await media.getAlbums(fileHasArgsfetchOp3); - console.info( - 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length - ); + console.info('GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length); expect(albumList.length == 0).assertTrue(); done(); } catch (error) { @@ -419,9 +417,7 @@ describe('album.promise.test.js', async function () { }; try { const albumList = await media.getAlbums(fileHasArgsfetchOp4); - console.info( - 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length - ); + console.info('GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length); expect(albumList.length == 0).assertTrue(); done(); } catch (error) { @@ -447,9 +443,7 @@ describe('album.promise.test.js', async function () { try { const albumList = await media.getAlbums(fileHasArgsfetchOp5); - console.info( - 'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length - ); + console.info('GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length); expect(albumList.length == 0).assertTrue(); done(); } catch (error) { diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssets.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssets.test.js deleted file mode 100644 index 0803af5642ccd304f03ce8c4c8bc4168c6803861..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssets.test.js +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('Create_File_Assets.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - console.info('MediaLibraryTest : createAsset : release begin'); - if (media != undefined) { - media.release(); - } - console.info('MediaLibraryTest : createAsset : release end'); - }) - - /** - * @tc.number : 01 - * @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 - * @tc.desc : Create an image file asset in predefined relative path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01', 0, async function (done) { - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayName = "02image.jpg"; - let rp = "Pictures/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => { - if (fileObj != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri); - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - console.info('MediaLibraryTest : createAsset end'); - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 end'); - - /** - * @tc.number : 02 - * @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 - * @tc.desc : Create an image file asset in not predefined relative path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02', 0, async function (done) { - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayName = "02image.jpg"; - let rp = "Pictures/test/001/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => { - if (fileObj != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri); - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 : PASS'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - console.info('MediaLibraryTest : createAsset end'); - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 end'); - - /** - * @tc.number : 03 - * @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 - * @tc.desc : Repeat to create same image file asset expect return error - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03', 0, async function (done) { - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayName = "02image.jpg"; - let rp = "Pictures/test/001/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => { - if (fileObj == undefined) { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 : PASS'); - expect(true).assertTrue(); - done(); - } - console.info('MediaLibraryTest : createAsset : FAIL'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 : FAIL'); - expect(false).assertTrue(); - done(); - }); - console.info('MediaLibraryTest : createAsset end'); - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 end'); - - - /** - * @tc.number : 04 - * @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 - * @tc.desc : Create image file asset in invalid relative path expect return error - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04', 0, async function (done) { - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayName = "04image.jpg"; - let rp = "test/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => { - if (createAssetErr != undefined) { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 : PASS'); - expect(true).assertTrue(); - done(); - } - console.info('MediaLibraryTest : createAsset : FAIL'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 : FAIL'); - expect(false).assertTrue(); - done(); - }); - console.info('MediaLibraryTest : createAsset end'); - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 end'); - - /** - * @tc.number : 07 - * @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 - * @tc.desc : After create an image file asset, open and close it - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07', 0, async function (done) { - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayName = "03image.jpg"; - - media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE, (err, rp) => { - if (rp != undefined) { - console.info('MediaLibraryTest : getPublicDirectory Successfull ' + rp); - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, data) => { - if (data != undefined) { - console.info('MediaLibraryTest : createAsset Successfull '); - getObjectInfo(data); - - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - console.info('MediaLibraryTest : createAsset end'); - - } else { - console.info('MediaLibraryTest : getPublicDirectory : FAIL'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - - } - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 end'); - }); - - function getObjectInfo(fileAsset) { - console.info('MediaLibraryTest : getObjectInfo uri is ' + fileAsset.uri); - - console.info("==========================fileAsset.open begin=======================>"); - fileAsset.open('Rw').then((openError, fd) => { - if (openError == undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL'); - expect(false).assertTrue(); - done(); - } - console.info("==========================fileAsset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================fileAsset.close begin=======================>"); - fileAsset.close(fd).then((closeErr) => { - if (closeErr == undefined) { - console.info('MediaLibraryTest : close : FAIL ' + closeErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL'); - expect(false).assertTrue(); - done(); - } - console.info("==========================fileAsset.close success=======================>"); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : PASS'); - expect(true).assertTrue(); - done(); - }); - console.info("==========================fileAsset.close end=======================>"); - }); - console.info("==========================fileAsset.open end=======================>"); - } -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssetsPerformance.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssetsPerformance.test.js deleted file mode 100644 index c274ebebbad6190db75462d9e597c87d6290e92f..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/createFileAssetsPerformance.test.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('createFileAssetsPerformance.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - let times = 100; - - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 - * @tc.name : Create an image file asset in predefined path - * @tc.desc : Create an image file asset in predefined path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01', 0, async function (done) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 begin1'); - if (media == null || media == undefined) { - console.info('MediaLibraryTest : media == null'); - } else { - let mediaType = mediaLibrary.MediaType.IMAGE; - let displayNamePrefix = "image"; - let extendStr = ".jpg" - let rp = "Pictures/"; - let displayName; - let conteEnd = 0; - for (let i = 0; i < times; i++) { - displayName = displayNamePrefix + i + extendStr; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp).then((fileObj) => { - if (fileObj != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri); - conteEnd++; - if (conteEnd == times) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 : PASS'); - expect(true).assertTrue(); - done(); - } else if (i == times) { - console.info('MediaLibraryTest : createAsset has error'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 :Partial success'); - expect(false).assertTrue(); - done(); - } - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull '); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - console.info('MediaLibraryTest : createAsset end'); - } - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 end'); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/deleteFileAssetsPerformance.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/deleteFileAssetsPerformance.test.js deleted file mode 100644 index 235bd2e3faad65f1d4d0ceaa437436bf4ecb9003..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/deleteFileAssetsPerformance.test.js +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('deleteFileAssetsPerformance.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let fileList_; - let fileKeyObj = mediaLibrary.FileKey - let type = mediaLibrary.MediaType.IMAGE - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + " = ? ", - selectionArgs: [type.toString()], - order: fileKeyObj.DATE_ADDED, - } - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 - * @tc.name : Create an image file asset in predefined path - * @tc.desc : Create an image file asset in predefined path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01', 0, async function (done) { - media.getFileAssets(fetchOp, (getFileAssetsErr, queryResultSet) => { - if (queryResultSet != undefined) { - console.info('MediaLibraryTest : getAllObject Successfull ' + queryResultSet.getCount()); - if (queryResultSet.getCount() > 0) { - queryResultSet.getAllObject((getAllObjectErr, fileList) => { - if (fileList != undefined) { - fileList_ = fileList; - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :PASS'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :FAIL' - + getAllObjectErr.message); - expect(false).assertTrue(); - done(); - } - }); - } else { - console.info('MediaLibraryTest : getFileAssets :No data'); - expect(true).assertTrue(); - done(); - } - } else { - console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + getFileAssetsErr.message); - console.info('MediaLibraryTest : getFileAssets :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 end'); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_ASSET_01 - * @tc.name : Create an image file asset in predefined path - * @tc.desc : Create an image file asset in predefined path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01', 0, async function (done) { - if (fileList_ != undefined) { - let counteEnd = 0; - for (let i = 0; i < fileList_.length; i++) { - let fileAsset = fileList_[i]; - console.info('MediaLibraryTest : uri is ' + fileAsset.uri); - media.deleteAsset(fileAsset.uri, (deleteAssetErr, deleteRows) => { - if (deleteRows >= 0) { - console.info('MediaLibraryTest : Delete Asset Successfull ' + deleteRows); - counteEnd++; - if (counteEnd == fileList_.length) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 : PASS'); - expect(true).assertTrue(); - done(); - } else if (i == fileList_.length - 1) { - console.info('MediaLibraryTest : delete has error'); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :Partial success'); - expect(false).assertTrue(); - done(); - } - } else { - console.info('MediaLibraryTest : delete error ' + deleteAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL'); - expect(false).assertTrue(); - done(); - } - }); - } - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL' - + getAllObjectErr.message); - expect(false).assertTrue(); - done(); - } - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 end'); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributed.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributed.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f92d9ed33a400f6a1833c31039495af05871b3db --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributed.test.js @@ -0,0 +1,93 @@ +/* + * 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 image from '@ohos.multimedia.image'; + +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} from 'deccjsunit/index' +describe('distributed.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 () { + onsole.info('Distributed. Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + + }) + + beforeEach(function () { + console.info('Distributed. Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); + + }) + afterEach(function () { + console.info('Distributed. Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + + }) + afterAll(function () { + console.info('Distributed. Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + + }) + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_distributed_001_01 + * @tc.name : getActivePeers + * @tc.desc : getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01', 0, async function (done) { + try { + done(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 begin'); + let peers = await media.getActivePeers(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 done'); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 fail, message = ' + error); + done(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02 + * @tc.name : getAllPeers + * @tc.desc : getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02', 0, async function (done) { + try { + done(); + let peers = await media.getAllPeers(); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02 fail, message = ' + error); + done(); + } + done(); + }); +}) \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestCallBack.test.js deleted file mode 100644 index 9518e8a68163fe568a390f5a9480bb85d5fac5cc..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestCallBack.test.js +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -describe('favSmartAlbum.promise.test.js', function () { - - let mediaType = mediaLibrary.MediaType.IMAGE; - let path = "Pictures/" - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - var asset; - var favSmartAlbum; - beforeAll(function () { - console.info('Smart Album Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); - }) - - beforeEach(function () { - console.info('Smart Album Callback MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); - }) - afterEach(function () { - console.info('Smart Album Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); - }) - afterAll(function () { - console.info('Smart Album Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_CALLBACK_001 - * @tc.name : Get PrivateSmartAlbum by fav - * @tc.desc : Get PrivateSmartAlbum by fav - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_CALLBACK_001', 0, async function (done) { - try { - asset = await media.createAsset(mediaType, "imagefavtest.jpg", path); - media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_FAVORITE, getPrivateAlbumCallBack); - done(); - } catch (error) { - console.info('MediaLibraryTest : CALLBACK_001 getPrivateAlbum fail, message = ' + error); - done(); - } - }); - - function getPrivateAlbumCallBack(err, favSmartAlbums) { - if (favSmartAlbums != undefined) { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbum favSmartAlbums'); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK favSmartAlbums ' + favSmartAlbums[0].albumName); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK favSmartAlbums ' + favSmartAlbums[0].albumCapacity); - favSmartAlbum = favSmartAlbums[0]; - favSmartAlbum.addAsset(asset.uri, addAssetCallBack); - done(); - } else { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbumCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbumCallBack : FAIL'); - done(); - } - } - - function addAssetCallBack(err, data) { - if (data != undefined) { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK fav addAsset success'); - favSmartAlbum.getFileAssets(getFileAssetsCallBack); - favSmartAlbum.removeAsset(asset.uri, removeAssetCallBack); - done(); - } else { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK addAssetCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK addAssetCallBack : FAIL'); - done(); - } - } - function removeAssetCallBack(err, data) { - if (data != undefined) { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK fav removeAsset success'); - favSmartAlbum.getFileAssets(getFileAssetsCallBack); - done(); - } else { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK removeAssetCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateremoveAssetCallBackAlbumCallBack : FAIL'); - done(); - } - } - function getFileAssetsCallBack(err, fSmartFetchFileResult) { - if (fSmartFetchFileResult != undefined) { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack Successfull fSmartFetchFileResult = ' + - fSmartFetchFileResult.getCount()); - done(); - } else { - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack Unsuccessfull ' + err); - console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack : FAIL'); - done(); - } - } -}) diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestPromise.test.js deleted file mode 100644 index 054273d8f888ef8b56c4e8bb80b0ae5029d0e71c..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favTestPromise.test.js +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -describe('favSmartAlbum.promise.test.js', function () { - - let mediaType = mediaLibrary.MediaType.IMAGE; - let path = "Pictures/" - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - var asset; - var favSmartAlbum; - var trashSmartAlbum; - beforeAll(function () { - onsole.info('Smart Album Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); - - }) - - beforeEach(function () { - console.info('Smart Album Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); - - }) - afterEach(function () { - console.info('Smart Album Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); - - }) - afterAll(function () { - console.info('Smart Album Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); - - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001 - * @tc.name : Get PrivateSmartAlbum by fav - * @tc.desc : Get PrivateSmartAlbum by fav - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_01', 0, async function (done) { - try { - asset = await media.createAsset(mediaType, "imageGetPrivatealbum002.jpg", path); - const favSmartAlbums = await media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_FAVORITE); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum favSmartAlbums 001_01'); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE favSmartAlbums 001_01 ' + favSmartAlbums[0].albumName); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE favSmartAlbums 001_01 ' + - favSmartAlbums[0].albumCapacity); - favSmartAlbum = favSmartAlbums[0]; - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - done(); - }); - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_02', 0, async function (done) { - try { - const trashSmartAlbums = await media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_TRASH); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum trashSmartAlbums 001_02'); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE trashSmartAlbums 001_02 ' + - trashSmartAlbums[0].albumName); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE trashSmartAlbums 001_02 ' + - trashSmartAlbums[0].albumCapacity); - trashSmartAlbum = trashSmartAlbums[0]; - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_02 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_03', 0, async function (done) { - try { - const favSmartAlbums = await media.getPrivateAlbum(666); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_03 success'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_03 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_04', 0, async function (done) { - try { - const favSmartAlbums = await media.getPrivateAlbum("666"); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_04'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_04 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_05', 0, async function (done) { - try { - const favSmartAlbums = await media.getPrivateAlbum(6.66666); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_05'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_05 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_06', 0, async function (done) { - try { - const favSmartAlbums = await media.getPrivateAlbum(); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_06'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_06 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002 - * @tc.name : Add asset - * @tc.desc : Add asset - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_01', 0, async function (done) { - try { - await favSmartAlbum.addAsset(asset.uri); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_01 uri = ', asset.uri); - let fSmartFetchFileResult = await favSmartAlbum.getFileAssets(); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets 002_01 Successfull fSmartFetchFileResult = ' - + fSmartFetchFileResult.getCount()); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_02', 0, async function (done) { - try { - await favSmartAlbum.addAsset(666); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_02 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_03', 0, async function (done) { - try { - await favSmartAlbum.addAsset("666"); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_03 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_04', 0, async function (done) { - try { - await favSmartAlbum.addAsset(0.666); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_04 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_05', 0, async function (done) { - try { - await favSmartAlbum.addAsset(); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_05 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003 - * @tc.name : Remove asset - * @tc.desc : Remove asset - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_01', 0, async function (done) { - try { - await favSmartAlbum.removeAsset(asset.uri); - let fSmartFetchFileResultNew = await favSmartAlbum.getFileAssets(); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets Successfull removeAsset 003_01 fSmartFetchFileResultNew = ' + - fSmartFetchFileResultNew.getCount()); - await media.deleteAsset(asset.uri); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_01 fail, message = ' + error); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_02', 0, async function (done) { - try { - await favSmartAlbum.removeAsset(666); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_02 success'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_02 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_03', 0, async function (done) { - try { - await favSmartAlbum.removeAsset("666"); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_03 success'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_03 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_04', 0, async function (done) { - try { - await favSmartAlbum.removeAsset(0.666); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_04 success'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_04 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_05', 0, async function (done) { - try { - await favSmartAlbum.removeAsset(); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_05 success'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_05 fail, message = ' + error); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETASSET_PROMISE_004 - * @tc.name : get FileAssets - * @tc.desc : get FileAssets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GETASSET_PROMISE_004_01', 0, async function (done) { - try { - let fSmartFetchFileResultGet = await favSmartAlbum.getFileAssets(); - console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets Successfull 004_01 fSmartFetchFileResultGet = ' + - fSmartFetchFileResultGet.getCount()); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav getFileAssets 004_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); -}) 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 index 3b2776a01135449057f3a5220ae2c82fbddbd5a9..1c94e83fb468db259c4a04a05fc15124cb476c63 100644 --- 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 @@ -1,1389 +1,1375 @@ -/* - * 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 ------------------------ -}); +/* + * 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('favoriteTestCallBack.test.js', function () { + var context = featureAbility.getContext(); + console.info('getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('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('FAV_ASSET_CALLBACK 001_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('FAV_ASSET_CALLBACK 001_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 001_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('FAV_ASSET_CALLBACK 001_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 001_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_03 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 001_03 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_04 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 001_04 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_05 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 001_05 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_06 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 001_06 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_07 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 001_07 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 001_08 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 001_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 001_09 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_01 failed'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('FAV_ASSET_CALLBACK 002_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 002_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('FAV_ASSET_CALLBACK 002_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 002_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_03 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 002_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_04 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 002_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_05 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 002_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_06 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 002_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_07 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 002_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 002_08 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 002_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 002_09 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('FAV_ASSET_CALLBACK 003_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 003_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('FAV_ASSET_CALLBACK 003_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 003_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_03 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 003_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_04 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 003_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_05 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 003_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_06 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 003_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_07 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 003_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 003_08 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 003_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 003_09 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(true, () => { + asset.isFavorite((err1, isFavorite) => { + if (isFavorite) { + console.info('FAV_ASSET_CALLBACK 004_01 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 004_01 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + } + asset.favorite(false, () => { + asset.isFavorite((err1, isFavorite) => { + if (!isFavorite) { + console.info('FAV_ASSET_CALLBACK 004_02 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 004_02 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_03 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 004_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_04 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 004_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_05 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 004_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_06 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 004_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_07 fail'); + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('FAV_ASSET_CALLBACK 004_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_08 fail'); + expect(false).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 004_08 pass'); + expect(true).assertTrue(); + done(); + } + }); + }); + }); + } catch (error) { + console.info('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('FAV_ASSET_CALLBACK 004_09 pass'); + expect(true).assertTrue(); + done(); + } else { + console.info('FAV_ASSET_CALLBACK 004_09 fail'); + expect(false).assertTrue(); + done(); + } + }); + }); + }); + }); + } catch (error) { + console.info('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 index e9ce86074c6b6b3bdb55ad546a0c6482e6aed90e..a180a8414c97ac04f4ce576a79fb39432495513c 100644 --- 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 @@ -1,1112 +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 ------------------------ -}); +/* + * 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('favoriteTestPromise.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/fetchFileResultCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fetchFileResultCallBack.test.js new file mode 100644 index 0000000000000000000000000000000000000000..bb7bfde9eeb8e59197c683a0eaca529fd9587cf2 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fetchFileResultCallBack.test.js @@ -0,0 +1,733 @@ +/* + * 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'; +let fileKeyObj = mediaLibrary.FileKey; +let fileType = mediaLibrary.MediaType.IMAGE; +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; + +let getFileCountOneOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED, + extendArgs: 'LIMIT 0,1', +}; + +let getFileCountTwoOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED, + extendArgs: 'LIMIT 0,2', +}; + +let getFileCountTenOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED, + extendArgs: 'LIMIT 0,10', +}; + +let getFileCountOneHundredOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED, + extendArgs: 'LIMIT 0,100', +}; + +let getFirstObjectOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID, + extendArgs: 'LIMIT 0,5', +}; + +let getAllObjectLimitOneOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID, + extendArgs: 'LIMIT 0,1', +}; + +let getAllObjectLimitTwoOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID, + extendArgs: 'LIMIT 0,1', +}; + +let getAllObjectLimitOneHundredOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID, + extendArgs: 'LIMIT 0,100', +}; + +let getFileCountZeroOp = { + selections: + fileKeyObj.DISPLAY_NAME + + '= "The world has kissed my soul with its pain, asking for its return in songs."', +}; + +let targetAttrs = { + 3: { + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + }, + 4: { + id: 4, + // uri: 'dataability:///media/audio', + mimeType: 'image/*', + mediaType: imageType, + displayName: '02.jpg', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 348113, + dateAdded: 1501923717, + dateModified: 1501923707, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 1279, + height: 1706, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + }, + 9: { + id: 9, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: audioType, + displayName: '02.mp3', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923710, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + }, +}; + +function checkAssetAttr(done, asset, attr, test_num) { + if ( + !( + ( + asset.id == attr.id && + // asset.uri == attr.uri && + asset.mimeType == attr.mimeType && + asset.mediaType == attr.mediaType && + asset.displayName == attr.displayName && + asset.title == attr.title && + asset.relativePath == attr.relativePath && + asset.parent == attr.parent && + asset.size == attr.size && + asset.dateAdded == attr.dateAdded && + asset.dateModified == attr.dateModified && + asset.dateTaken == attr.dateTaken && + // asset.artist == attr.artist && + // asset.audioAlbum == attr.audioAlbum && + asset.width == attr.width && + asset.height == attr.height && + asset.orientation == attr.orientation && + asset.duration == attr.duration + ) + // asset.albumId == attr.albumId && + // asset.albumUri == attr.albumUri && + // asset.albumName == attr.albumName + ) + ) { + console.info(`MediaLibraryTest : ASSET_CHECK ${test_num} failed`); + expect(false).assertTrue(); + } +} + +function objectCheckCallback(err, targetObject) { + if (err) { + expect(false).assertTrue(); + } + if (targetObject == undefined) { + expect(false).assertTrue(); + } + var targetAttr = targetAttrs[targetObject.id.toString()]; + checkAssetAttr(targetObject, targetAttr, ''); + expect(true).assertTrue(); +} + +function objectCheckErrorCallback(err, targetObject) { + if (targetObject == undefined) { + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } +} + +function AllObjectCheckCallback(err, targetObjects) { + if (err) { + expect(false).assertTrue(); + } else if (targetObjects == undefined) { + expect(false).assertTrue(); + } else if (targetObjects.length > 0) { + for (var i = 0; i < targetObjects.length; i++) { + var targetObject = targetObjects[i]; + let targetAttr = attrs[i]; + checkAssetAttr(targetObject, targetAttr, ''); + } + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } +} + +function AllObjectCheckOneCallback(err, targetObjects) { + if (err) { + expect(false).assertTrue(); + } else if (targetObjects == undefined) { + expect(false).assertTrue(); + } else if (targetObjects.length > 0) { + var targetObject = targetObjects[0]; + let targetAttr = attrs[i]; + checkAssetAttr(targetObject, targetAttr, ''); + expect(true).assertTrue(); + } else { + expect(false).assertTrue(); + } +} + +describe('fetch.file.result.callback.test.js', async function () { + var context = featureAbility.getContext(); + var media = mediaLibrary.getMediaLibrary(context); + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(function () { }); + afterAll(function () { }); + + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Call'ba'c'k) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_01', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneOp); + const fetchCount = fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 1).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getCount 001_01 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_02', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTwoOp); + const fetchCount = fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 2).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getCount 001_02 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_03', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneHundredOp); + const fetchCount = fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 100).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getCount 001_03 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_CALLBACK_001_04', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountZeroOp); + const fetchCount = fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 0).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getCount 001_04 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_CALLBACK_002 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTenOp, check the return value of the interface (by Callback) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_CALLBACK_002', 0, async function (done) { + try { + console.info('MediaLibraryTest : isAfterLast begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTenOp); + const fetchCount = fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + let fileAsset = await fetchFileResult.getFirstObject(); + for (var i = 1; i < fetchCount; i++) { + fileAsset = await fetchFileResult.getNextObject(); + if (i == fetchCount - 1) { + console.info('MediaLibraryTest : isLast'); + var result = fetchFileResult.isAfterLast(); + console.info('MediaLibraryTest : isAfterLast:' + result); + expect(true).assertTrue(); + console.info('MediaLibraryTest : isAfterLast end'); + fetchFileResult.close(); + done(); + } + } + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT isAfterLast 002 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 002 test end ------------------------- + + // ------------------------------ 003 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_CALLBACK_003 + * @tc.name : getCount + * @tc.desc : Get FetchResult, close it, check if result closed + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_CALLBACK_003', 0, async function (done) { + try { + console.info('MediaLibraryTest : CLOSE begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTenOp); + fetchFileResult.close(); + try { + fetchFileResult.getCount(); + console.info('MediaLibraryTest : CLOSE failed'); + expect(false).assertTrue(); + done(); + } catch { + console.info('MediaLibraryTest : CLOSE closed'); + expect(true).assertTrue(); + done(); + } + console.info('MediaLibraryTest : CLOSE end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT close 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 003 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETFIRSTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getFirstObject(objectCheckCallback); + fetchFileResult.close(); + console.info('MediaLibraryTest : GETFIRSTOBJECT end'); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getFirstObject 004 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 004 test end ------------------------- + + // ------------------------------ 005 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETNEXTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let firstObject = await fetchFileResult.getFirstObject(); + fetchFileResult.getNextObject(objectCheckCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETNEXTOBJECT end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getNextObject 005 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 005 test end ------------------------- + + // ------------------------------ 006 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETLASTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getLastObject(objectCheckCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETLASTOBJECT end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getLastObject 006 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 006 test end ------------------------- + + // ------------------------------ 007 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 0 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it( + 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01', + 0, + async function (done) { + try { + console.info('MediaLibraryTest : GETPOSITIONOBJECT 0 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getPositionObject(0, objectCheckCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT 0 end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getPositionObject 007_01 failed, message = ' + + error + ); + expect(false).assertTrue(); + done(); + } + } + ); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it( + 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02', + 0, + async function (done) { + try { + nowDone = done; + console.info('MediaLibraryTest : GETPOSITIONOBJECT 1 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getPositionObject(1, objectCheckCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT 1 end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getPositionObject 007_02 failed, message = ' + + error + ); + expect(false).assertTrue(); + done(); + } + } + ); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it( + 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03', + 0, + async function (done) { + try { + nowDone = done; + console.info('MediaLibraryTest : GETPOSITIONOBJECT last begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = fetchFileResult.getCount(); + fetchFileResult.getPositionObject(count - 1, objectCheckCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT last end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getPositionObject 007_03 failed, message = ' + + error + ); + expect(false).assertTrue(); + done(); + } + } + ); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it( + 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04', + 0, + async function (done) { + try { + nowDone = done; + console.info('MediaLibraryTest : GETPOSITIONOBJECT out of index begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = fetchFileResult.getCount(); + try { + fetchFileResult.getPositionObject(count + 100, objectCheckErrorCallback); + if (targetObject == undefined) { + expect(true).assertTrue(); + fetchFileResult.close(); + done(); + } + expect(false).assertTrue(); + fetchFileResult.close(); + done(); + } catch (err) { + expect(true).assertTrue(); + fetchFileResult.close(); + done(); + } + console.info('MediaLibraryTest : GETPOSITIONOBJECT out of index end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getPositionObject 007_04 failed, message = ' + + error + ); + expect(false).assertTrue(); + done(); + } + } + ); + // ------------------------------ 007 test end ------------------------- + + // ------------------------------ 008 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01', 0, async function (done) { + try { + nowDone = done; + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneOp); + fetchFileResult.getAllObject(AllObjectCheckCallback); + console.info('MediaLibraryTest : GETALLOBJECT end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getAllObject 008_01 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02', 0, async function (done) { + try { + nowDone = done; + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitTwoOp); + fetchFileResult.getAllObject(AllObjectCheckCallback); + console.info('MediaLibraryTest : GETALLOBJECT end'); + fetchFileResult.close(); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getAllObject 008_02 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneHundredOp); + fetchFileResult.getAllObject(AllObjectCheckOneCallback); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETALLOBJECT end'); + } catch (error) { + console.info( + 'MediaLibraryTest : FETCHRESULT getAllObject 008_03 failed, message = ' + error + ); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 008 test end ------------------------- +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fetchFileResultPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fetchFileResultPromise.test.js new file mode 100644 index 0000000000000000000000000000000000000000..bd53ff35e830e91a48cd426b66c51f98799475a3 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fetchFileResultPromise.test.js @@ -0,0 +1,822 @@ +/* + * 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'; +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 getFileCountOneOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC LIMIT 0,1", + extendArgs: "", +}; + +let getFileCountTwoOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC LIMIT 0,2", + extendArgs: "", +}; + +let getFileCountTenOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC LIMIT 0,10", + extendArgs: "", +}; + +let getFileCountOneHundredOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + order: fileKeyObj.DATE_ADDED + " DESC LIMIT 0,100", + extendArgs: "", +}; + +let getFirstObjectOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID + " DESC LIMIT 0,5", + extendArgs: "", +} + +let getAllObjectLimitOneOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID + " DESC LIMIT 0,1", + extendArgs: "", +} + +let getAllObjectLimitTwoOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID + " DESC LIMIT 0,1", + extendArgs: "", +} + +let getAllObjectLimitOneHundredOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs: ['camera/'], + order: fileKeyObj.ID + " DESC LIMIT 0,100", + extendArgs: "", +} + +let getFileCountZeroOp = { + selections: fileKeyObj.DISPLAY_NAME + '=?', + selectionArgs: ['The world has kissed my soul with its pain, asking for its return in songs.'], +}; + +function checkAssetAttr(done, asset, attr, test_num) { + expect(asset.id != undefined).assertTrue(); + expect(asset.mimeType != undefined).assertTrue(); + expect(asset.displayName != undefined).assertTrue(); + expect(asset.title != undefined).assertTrue(); + expect(asset.relativePath != undefined).assertTrue(); + expect(asset.parent != undefined).assertTrue(); + expect(asset.size != undefined).assertTrue(); + expect(asset.dateAdded != undefined).assertTrue(); + expect(asset.dateModified != undefined).assertTrue(); + expect(asset.dateTaken != undefined).assertTrue(); + expect(asset.width != undefined).assertTrue(); + expect(asset.height != undefined).assertTrue(); + expect(asset.orientation != undefined).assertTrue(); + expect(asset.duration != undefined).assertTrue(); + done(); +} + +describe('fetch.file.result.promise.test.js', async function () { + var context = featureAbility.getContext(); + var media = mediaLibrary.getMediaLibrary(context); + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_01', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 1).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + // fetchFileResult.close(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getCount 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTwoOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_02', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTwoOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 2).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + // fetchFileResult.close(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getCount 001_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountOneHundredOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_03', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneHundredOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount <= 100).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + // fetchFileResult.close(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getCount 001_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountZeroOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETCOUNT_PROMISE_001_04', 0, async function (done) { + try { + console.info('MediaLibraryTest : Get Count begin'); + let fetchFileResult = await media.getFileAssets(getFileCountZeroOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + expect(fetchCount == 0).assertTrue(); + console.info('MediaLibraryTest : Get Count end'); + // fetchFileResult.close(); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getCount 001_04 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + // ------------------------------ 001 test end ------------------------- + + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002 + * @tc.name : getCount + * @tc.desc : Get FetchResult by getFileCountTenOp, check the return value of the interface (by Promise) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_ISAFTERLAST_PROMISE_002', 0, async function (done) { + try { + console.info('MediaLibraryTest : isAfterLast begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTenOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : count:' + fetchCount); + let fileAsset = await fetchFileResult.getFirstObject(); + for (var i = 1; i < fetchCount; i++) { + fileAsset = await fetchFileResult.getNextObject(); + if (i == fetchCount - 1) { + console.info('MediaLibraryTest : isLast'); + var result = fetchFileResult.isAfterLast(); + console.info('MediaLibraryTest : isAfterLast:' + result); + expect(true).assertTrue(); + console.info('MediaLibraryTest : isAfterLast end'); + // fetchFileResult.close(); + done(); + } + } + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT isAfterLast 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 002 test end ------------------------- + + // // ------------------------------ 003 test start ------------------------- + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003 + // * @tc.name : getCount + // * @tc.desc : Get FetchResult, close it, check if result closed + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_CLOSE_PROMISE_003', 0, async function (done) { + // try { + // console.info('MediaLibraryTest : CLOSE begin'); + // let fetchFileResult = await media.getFileAssets(getFileCountTenOp); + // // fetchFileResult.close(); + // try { + // await fetchFileResult.getCount(); + // console.info('MediaLibraryTest : CLOSE failed'); + // expect(false).assertTrue(); + // done(); + // } catch { + // console.info('MediaLibraryTest : CLOSE closed'); + // expect(true).assertTrue(); + // done(); + // } + // console.info('MediaLibraryTest : CLOSE end'); + // } catch (error) { + // console.info('MediaLibraryTest : FETCHRESULT close 003 failed, message = ' + error); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // ------------------------------ 003 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_PROMISE_004', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETFIRSTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let firstObject = await fetchFileResult.getFirstObject(); + let targetAttr = { + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + } + checkAssetAttr(done, firstObject, targetAttr, '004'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETFIRSTOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getFirstObject 004 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + + // ------------------------------ 004 test end ------------------------- + + // ------------------------------ 005 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_PROMISE_005', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETNEXTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let firstObject = await fetchFileResult.getFirstObject(); + let nextObject = await fetchFileResult.getNextObject(); + let targetAttr = { + id: 4, + // uri: 'dataability:///media/audio', + mimeType: 'image/*', + mediaType: imageType, + displayName: '02.jpg', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 348113, + dateAdded: 1501923717, + dateModified: 1501923707, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 1279, + height: 1706, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + } + checkAssetAttr(done, nextObject, targetAttr, '005'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETNEXTOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 005 test end ------------------------- + + // ------------------------------ 006 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006 + * @tc.name : getNextObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETLASTOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let lastObject = await fetchFileResult.getLastObject(); + let targetAttr = { + id: 9, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: audioType, + displayName: '02.mp3', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923710, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + } + checkAssetAttr(done, lastObject, targetAttr, '006'); + expect(true).assertTrue(); + done(); + // fetchFileResult.close(); + console.info('MediaLibraryTest : GETLASTOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getLastObject 006 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 006 test end ------------------------- + + // ------------------------------ 007 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 0 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_01', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETPOSITIONOBJECT 0 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let targetObject = await fetchFileResult.getPositionObject(0); + let targetAttr = { + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + } + checkAssetAttr(done, targetObject, targetAttr, '007_01'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT 0 end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETPOSITIONOBJECT 1 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let targetObject = await fetchFileResult.getPositionObject(1); + let targetAttr = { + id: 4, + // uri: 'dataability:///media/audio', + mimeType: 'image/*', + mediaType: imageType, + displayName: '02.jpg', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 348113, + dateAdded: 1501923717, + dateModified: 1501923707, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 1279, + height: 1706, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + } + checkAssetAttr(done, targetObject, targetAttr, '007_02'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT 1 end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_02 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_03', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETPOSITIONOBJECT last begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = await fetchFileResult.getCount(); + let targetObject = await fetchFileResult.getPositionObject(count - 1); + let targetAttr = { + id: 9, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: audioType, + displayName: '02.mp3', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923710, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + } + checkAssetAttr(done, targetObject, targetAttr, '007_03'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : GETPOSITIONOBJECT last end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04 + * @tc.name : getPositionObject + * @tc.desc : Get FetchResult, get position 1 object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_PROMISE_007_04', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETPOSITIONOBJECT out of index begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = await fetchFileResult.getCount(); + try { + let targetObject = await fetchFileResult.getPositionObject(count + 100); + if (targetObject == undefined) { + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + } + expect(false).assertTrue(); + // fetchFileResult.close(); + done(); + } catch (err) { + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + } + console.info('MediaLibraryTest : GETPOSITIONOBJECT out of index end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_04 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 007 test end ------------------------- + + // ------------------------------ 008 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_01', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneOp); + var targetObjects = await fetchFileResult.getAllObject(); + if (targetObjects.length > 0) { + var targetObject = targetObjects[0]; + let targetAttr = { + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + } + checkAssetAttr(done, targetObject, targetAttr, '008_01'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + } + console.info('MediaLibraryTest : GETALLOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_02', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitTwoOp); + var targetObjects = await fetchFileResult.getAllObject(); + var targetAttrs = [{ + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + }, + { + id: 4, + // uri: 'dataability:///media/audio', + mimeType: 'image/*', + mediaType: imageType, + displayName: '02.jpg', + title: '02', + relativePath: 'camera/', + parent: 1, + size: 348113, + dateAdded: 1501923717, + dateModified: 1501923707, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 1279, + height: 1706, + orientation: 0, + duration: 0, + // albumId: 0, + // albumUri: '', + // albumName: '', + }, + ]; + + console.info('MediaLibraryTest : targetObjects.length:' + targetObjects.length); + if (targetObjects.length >= 1) { + for (var i = 0; i < targetObjects.length; i++) { + var targetObject = targetObjects[i]; + let targetAttr = targetAttrs[i]; + checkAssetAttr(done, targetObject, targetAttr, '008_02'); + } + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + } + console.info('MediaLibraryTest : GETALLOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : ==5='); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03 + * @tc.name : getAllObject + * @tc.desc : Get FetchResult, get all object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_PROMISE_008_03', 0, async function (done) { + try { + console.info('MediaLibraryTest : GETALLOBJECT begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneHundredOp); + var targetObjects = await fetchFileResult.getAllObject(); + if (targetObjects.length > 0) { + var targetObject = targetObjects[0]; + let targetAttr = { + id: 3, + // uri: 'dataability:///media/audio', + mimeType: 'audio/*', + mediaType: videoType, + displayName: '01.mp3', + title: '01', + relativePath: 'camera/', + parent: 1, + size: 3513962, + dateAdded: 1501923717, + dateModified: 1501923708, + dateTaken: 0, + // artist: '', + // audioAlbum: '', + width: 0, + height: 0, + orientation: 0, + duration: 0, + albumId: 0, + albumUri: '', + // albumName: '', + } + checkAssetAttr(done, targetObject, targetAttr, '008_03'); + expect(true).assertTrue(); + // fetchFileResult.close(); + done(); + } + console.info('MediaLibraryTest : GETALLOBJECT end'); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 008 test end ------------------------- + +}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestPromise.test.js index 357671896e6b01e8c946d59d438573cf275926d5..7f320b423d4b4246d8f05fa9a8ba095cc1e1bddb 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestPromise.test.js @@ -1,893 +1,952 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' -import fileio from '@ohos.fileio'; -import { - describe, - beforeAll, - beforeEach, - afterEach, - afterAll, - it, - expect -} from 'deccjsunit/index'; - -describe('fileAsset.test.js', async function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - const fileKeyObj = mediaLibrary.FileKey; - - //======================== FILE BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let fileType = mediaLibrary.MediaType.FILE; - let fileFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - expect(fd > 0).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write > 0).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (fd > 0 && res.bytesRead > 0 && write > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 - * @tc.name : open('r') - * @tc.desc : open -r the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 error:' + error); - if (fd > 0) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 - * @tc.name : open('w') - * @tc.desc : open -w the type of FILE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(fd > 0).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== FILE END ================================== - - //======================== ALBUM BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of ALBUM - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.ALBUM; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + error); - expect(true).assertTrue(); - if (fd > 0) { - asset.close(fd); - } - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 - * @tc.name : open('r') - * @tc.desc : open -r the type of ALBUM - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.ALBUM; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 error:' + error); - expect(true).assertTrue(); - if (fd > 0) { - asset.close(fd); - } - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 - * @tc.name : open('w') - * @tc.desc : open -w the type of ALBUM - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.ALBUM; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06 error:' + error); - expect(true).assertTrue(); - if (fd > 0) { - asset.close(fd); - } - done(); - } - }); - - //======================== ALBUM END ================================== - - //======================== IMAGE BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let fileType = mediaLibrary.MediaType.IMAGE; - let fileFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - expect(fd > 0).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write > 0).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (fd > 0 && res.bytesRead > 0 && write > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 - * @tc.name : open('r') - * @tc.desc : open -r the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 error:' + error); - if (fd > 0) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 - * @tc.name : open('w') - * @tc.desc : open -w the type of IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(fd > 0).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - - //======================== IMAGE END ================================== - - //======================== AUDIO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let fileType = mediaLibrary.MediaType.AUDIO; - let fileFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - expect(fd > 0).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write > 0).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (fd > 0 && res.bytesRead > 0 && write > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 - * @tc.name : open('r') - * @tc.desc : open -r the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 error:' + error); - if (fd > 0) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 - * @tc.name : open('w') - * @tc.desc : open -w the type of AUDIO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(fd > 0).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== AUDIO END ================================== - - - //======================== VIDEO BEGIN ================================== - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 - * @tc.name : open('rw') - * @tc.desc : open -rw the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - let fileType = mediaLibrary.MediaType.VIDEO; - let fileFetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], - }; - let fetchFileResult = await media.getFileAssets(fileFetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('rw'); - expect(fd > 0).assertTrue(); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - asset1 = dataList[1]; - fd1 = await asset1.open('r'); - let buf2 = new ArrayBuffer(4096); - let res2 = await fileio.read(fd1, buf2); - let write = await fileio.write(fd, buf2); - expect(write > 0).assertTrue(); - - await asset.close(fd); - await asset1.close(fd1); - - if (fd > 0 && res.bytesRead > 0 && write > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 success'); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 failed'); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 error' + error); - await asset.close(fd); - await asset1.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 - * @tc.name : open('r') - * @tc.desc : open -r the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14', 0, async function (done) { - let asset; - let fd; - try { - - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - expect(fd > 0).assertTrue(); - - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead > 0).assertTrue(); - let write = await fileio.write(fd, buf); - await asset.close(fd); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 error:' + error); - if (fd > 0) { - expect(true).assertTrue(); - } - await asset.close(fd); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 - * @tc.name : open('w') - * @tc.desc : open -w the type of VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15', 0, async function (done) { - let asset; - let asset1; - let fd; - let fd1; - try { - - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - asset1 = dataList[1]; - - fd = await asset.open('w'); - expect(fd > 0).assertTrue(); - fd1 = await asset1.open('r'); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd1, buf); - let write = await fileio.write(fd, buf); - - let buf1 = new ArrayBuffer(4096); - let res1 = await fileio.read(fd, buf1); - done(); - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 error:' + error); - expect(true).assertTrue(); - await asset.close(fd); - await asset1.close(fd1); - done(); - } - }); - - //======================== VIDEO END ================================== - - - //======================== CLOSE BEGIN ================================ - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 - * @tc.name : close - * @tc.desc : asset close the type of file - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.FILE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - - console.info('MediaLibraryTest : ==1 fd:' + fd); - await asset.close(fd); - - fd1 = await asset.open('r'); - console.info('MediaLibraryTest : ==2 fd2:' + fd1); - await asset.close(fd1); - if (fd > 0 && fd1 > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 false'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 - * @tc.name : close - * @tc.desc : asset close the type of image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.IMAGE; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - - console.info('MediaLibraryTest : ==1 fd:' + fd); - await asset.close(fd); - - fd1 = await asset.open('r'); - console.info('MediaLibraryTest : ==2 fd2:' + fd1); - await asset.close(fd1); - if (fd > 0 && fd1 > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 false'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 - * @tc.name : close - * @tc.desc : asset close the type of audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.AUDIO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - await asset.close(fd); - fd1 = await asset.open('r'); - await asset.close(fd1); - if (fd > 0 && fd1 > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 false'); - expect(false).assertTrue(); - done(); - } - done - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 - * @tc.name : close - * @tc.desc : asset close the type of video - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35', 0, async function (done) { - let asset; - let fd; - let fd1; - try { - let type = mediaLibrary.MediaType.VIDEO; - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], - }; - let fetchFileResult = await media.getFileAssets(fetchOp); - const dataList = await fetchFileResult.getAllObject(); - asset = dataList[0]; - fd = await asset.open('r'); - await asset.close(fd); - fd1 = await asset.open('r'); - await asset.close(fd1); - if (fd > 0 && fd1 > 0) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 false'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 error' + error); - await asset.close(fd); - await asset.close(fd1); - expect(false).assertTrue(); - done(); - } - }); - - //======================== CLOSE BEGIN ================================ - -}); \ No newline at end of file +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('fileAssetTestPromise.test.js', async function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + const fileKeyObj = mediaLibrary.FileKey; + + //======================== FILE BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let fileType = mediaLibrary.MediaType.FILE; + let fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + }; + let fetchFileResult = await media.getFileAssets(fileFetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('rw'); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + + await asset.close(fd); + await asset1.close(fd1); + + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 success' + ); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 failed' + ); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 error' + + error + ); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 + * @tc.name : open('r') + * @tc.desc : open -r the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.FILE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 error:' + + error + ); + if (fd > 0) { + expect(true).assertTrue(); + } + await asset.close(fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 + * @tc.name : open('w') + * @tc.desc : open -w the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.FILE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset1 = dataList[1]; + + fd = await asset.open('w'); + expect(fd > 0).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + + error + ); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== FILE END ================================== + + //======================== ALBUM BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of ALBUM + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.ALBUM; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('rw'); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + + error + ); + expect(true).assertTrue(); + if (fd > 0) { + asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 + * @tc.name : open('r') + * @tc.desc : open -r the type of ALBUM + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.ALBUM; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 error:' + + error + ); + expect(true).assertTrue(); + if (fd > 0) { + asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 + * @tc.name : open('w') + * @tc.desc : open -w the type of ALBUM + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.ALBUM; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06 error:' + + error + ); + expect(true).assertTrue(); + if (fd > 0) { + asset.close(fd); + } + done(); + } + }); + + //======================== ALBUM END ================================== + + //======================== IMAGE BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let fileType = mediaLibrary.MediaType.IMAGE; + let fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + }; + let fetchFileResult = await media.getFileAssets(fileFetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('rw'); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + + await asset.close(fd); + await asset1.close(fd1); + + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 success' + ); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 failed' + ); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 error' + + error + ); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 + * @tc.name : open('r') + * @tc.desc : open -r the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 error:' + + error + ); + if (fd > 0) { + expect(true).assertTrue(); + } + await asset.close(fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 + * @tc.name : open('w') + * @tc.desc : open -w the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset1 = dataList[1]; + + fd = await asset.open('w'); + expect(fd > 0).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 error:' + + error + ); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== IMAGE END ================================== + + //======================== AUDIO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let fileType = mediaLibrary.MediaType.AUDIO; + let fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + }; + let fetchFileResult = await media.getFileAssets(fileFetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('rw'); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + + await asset.close(fd); + await asset1.close(fd1); + + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 success' + ); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 failed' + ); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 error' + + error + ); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 + * @tc.name : open('r') + * @tc.desc : open -r the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.AUDIO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 error:' + + error + ); + if (fd > 0) { + expect(true).assertTrue(); + } + await asset.close(fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 + * @tc.name : open('w') + * @tc.desc : open -w the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.AUDIO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset1 = dataList[1]; + + fd = await asset.open('w'); + expect(fd > 0).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 error:' + + error + ); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== AUDIO END ================================== + + //======================== VIDEO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let fileType = mediaLibrary.MediaType.VIDEO; + let fileFetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], + }; + let fetchFileResult = await media.getFileAssets(fileFetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('rw'); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + + await asset.close(fd); + await asset1.close(fd1); + + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 success' + ); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 failed' + ); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 error' + + error + ); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 + * @tc.name : open('r') + * @tc.desc : open -r the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14', 0, async function (done) { + let asset; + let fd; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 error:' + + error + ); + if (fd > 0) { + expect(true).assertTrue(); + } + await asset.close(fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 + * @tc.name : open('w') + * @tc.desc : open -w the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15', 0, async function (done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + asset1 = dataList[1]; + + fd = await asset.open('w'); + expect(fd > 0).assertTrue(); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + done(); + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 error:' + + error + ); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== VIDEO END ================================== + + //======================== CLOSE BEGIN ================================ + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 + * @tc.name : close + * @tc.desc : asset close the type of file + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31', 0, async function (done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.FILE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + + console.info('MediaLibraryTest : ==1 fd:' + fd); + await asset.close(fd); + + fd1 = await asset.open('r'); + console.info('MediaLibraryTest : ==2 fd2:' + fd1); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 success' + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 false' + ); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 error' + + error + ); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 + * @tc.name : close + * @tc.desc : asset close the type of image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33', 0, async function (done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + + console.info('MediaLibraryTest : ==1 fd:' + fd); + await asset.close(fd); + + fd1 = await asset.open('r'); + console.info('MediaLibraryTest : ==2 fd2:' + fd1); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 success' + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 false' + ); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 error' + + error + ); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 + * @tc.name : close + * @tc.desc : asset close the type of audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34', 0, async function (done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.AUDIO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + await asset.close(fd); + fd1 = await asset.open('r'); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 success' + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 false' + ); + expect(false).assertTrue(); + done(); + } + done; + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 error' + + error + ); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35', 0, async function (done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + await asset.close(fd); + fd1 = await asset.open('r'); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 success' + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 false' + ); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 error' + + error + ); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + //======================== CLOSE BEGIN ================================ +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestCallBack.test.js new file mode 100644 index 0000000000000000000000000000000000000000..2938d54262bfba597e6418e2c9b8a8fa503cfdfb --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestCallBack.test.js @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility' +import fileio from '@ohos.fileio'; +import { + describe, + it, + expect +} from 'deccjsunit/index'; + +describe('fileAsset.callback.test.js', async function () { + var context = featureAbility.getContext(); + console.info('MediaLibraryTest : getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('MediaLibraryTest : getMediaLibrary OUT'); + const fileKeyObj = mediaLibrary.FileKey; + + function executeAtError(testNum, bool, error, done) { + console.info( + `SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} failed, error: ${error}` + ); + expect(bool).assertTrue(); + if (typeof done === "function") { + done(); + } + } + //======================== FILE BEGIN ================================== + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35', 0, async function (done) { + const testNum = "_005_35"; + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + uri: 'dataability://123456789/media/external/images/media/10', + networkId: '123456789', + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [type.toString()], + }; + media.getFileAssets(fetchOp, (error, fetchFileResult) => { + try{ + console.info(`MediaLibraryTest : ==1==`); + fetchFileResult.getAllObject((error, dataList) => { + console.info(`MediaLibraryTest : ==2==`); + try{ + console.info(`MediaLibraryTest : ==3==`); + asset = dataList[0]; + console.info(`MediaLibraryTest : ==4==`); + asset.open('r', (error, innerFd) => { + fd = innerFd; + try{ + asset.close(fd, (error) => { + try{ + asset.open('r', (error, innerFd1) => { + fd1 = innerFd1; + try{ + asset.close(fd1, (error) => { + try{ + if (fd > 0 && fd1 > 0) { + console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} success`); + expect(true).assertTrue(); + done(); + } else { + console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} failed`); + expect(false).assertTrue(); + done(); + } + }catch(error){ + executeAtError(testNum, false, error, done); + } + }); + }catch(error){ + executeAtError(testNum, false, error, done); + } + }); + }catch(error){ + executeAtError(testNum, false, error, done); + } + }); + }catch(error){ + executeAtError(testNum, false, error, done); + } + }); + }catch(error){ + executeAtError(testNum, true, error, done); + } + }); + }catch(error){ + executeAtError(testNum, true, error, done); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : ==5==`); + console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} error:${error}`); + asset.close(fd, () =>{ + try{ + console.info(`MediaLibraryTest : ==6==`); + asset1.close(fd1, () => { + console.info(`MediaLibraryTest : ==7==`); + expect(false).assertTrue(); + done(); + }); + }catch(error){ + console.info(`MediaLibraryTest : ==8==`); + expect(false).assertTrue(); + done(); + } + }); + } + }); + + //======================== CLOSE BEGIN ================================ + +}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestCallBack.test.js index 4a2d6c475aa57a297632cb47d6c77e3979f1a7b9..f47abdd4791c1745600cb406756336aff06d0469 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestCallBack.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileTestCallBack.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,787 +14,3041 @@ */ 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: [], +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, test_num, asset, checkType) { + if (checkType && asset[attr] != checkType) { + console.info(`MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed`); + expect(false).assertTrue(); + done(); + } else if (asset[attr] == undefined) { + console.info(`MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed`); + expect(false).assertTrue(); + done(); + } } -describe('file.callback.test.js', function () { - var asset; - var asset1; - var asset2; - var asset3; +function executeAtError(test_num, error, done) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed, message = ${error}` + ); + expect(false).assertTrue(); + if (typeof done === 'function') { + done(); + } +} +describe('fileTestCallBack.test', 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.'); - }) + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(function () { }); + afterAll(function () { }); - 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'); - }) + function copyFile(fd1, fd2, test_num, done, callback) { + try { + fileio.fstat(fd1, (error, stat) => { + let buf = new ArrayBuffer(stat.size); + try { + fileio.read(fd1, buf, () => { + try { + fileio.write(fd2, buf, () => { + try { + if (typeof callback === 'function') { + callback(); + } + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + // ------------------------------- image type start ---------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001 - * @tc.name : Create an asset in predefined path - * @tc.desc : Create an asset in predefined path + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01', 0, async function (done) { + const test_num = '001_01'; 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'); - let mediaType = mediaLibrary.MediaType.IMAGE; - let path = "Pictures/"; - media.createAsset(mediaType, "imageCallBack000001.jpg", path, createAssetCallBack); + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE, (error, path) => { + try { + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + imageType, + 'image03.jpg', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + const asset2 = + dataList[1]; + media.createAsset( + imageType, + 'image04.jpg', + path, + ( + error, + creatAsset2 + ) => { + try { + asset2.open( + 'rw', + ( + error, + fd2 + ) => { + try { + creatAsset2.open( + 'rw', + ( + error, + creatAssetFd2 + ) => { + try { + copyFile( + fd2, + creatAssetFd2, + test_num, + done, + () => { + creatAsset2.close( + creatAssetFd2, + () => { + asset2.close( + fd2, + () => { + if ( + creatAsset1.id != + creatAsset2.id + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } + ); + } + ); + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK createasset 001_01 fail, message = ' + error); + executeAtError(test_num, error, done); } - done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_CALLBACK_002 - * @tc.name : Modify asset - * @tc.desc : Modify asset + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02 + * @tc.name : createAsset + * @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_CALLBACK_002_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02', 0, async function (done) { + const test_num = '001_02'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - let path = "Pictures/"; - let pathMove = "Pictures/Move/"; - asset = await media.createAsset(mediaType, "image0000111.jpg", path); - await media.createAsset(mediaType, "imageMove00001.jpg", pathMove); - asset.title = "image00003"; - asset.relativePath = "Pictures/Move/"; - asset.displayName = "image0000222.jpg"; - asset.orientation = 1000; - asset.commitModify(commitModifyCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_01 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', test_num, firstAsset); + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', test_num, midAsset); + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', test_num, lastAsset); + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_01 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_CALLBACK_002_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03 + * @tc.name : createAsset + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03', 0, async function (done) { + const test_num = '001_03'; try { - asset.title = "image0000444"; - asset.commitModify(commitModifyCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_02 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_02 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_CALLBACK_002_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_04 + * @tc.name : createAsset + * @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_CALLBACK_001_04', 0, async function (done) { + const test_num = '001_04'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - let pathMoveCallback = "Pictures/Move/Callback/"; - await media.createAsset(mediaType, "imageMoveCallBack00001.jpg", pathMoveCallback); - asset.relativePath = "Pictures/Move/Callback/"; - asset.commitModify(commitModifyCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_03 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', test_num, lastAsset); + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_03 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_CALLBACK_002_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_05 + * @tc.name : createAsset + * @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_CALLBACK_001_05', 0, async function (done) { + const test_num = '001_05'; try { - asset.displayName = "image0000333.jpg"; - asset.commitModify(commitModifyCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_04 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_04 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_MODIFY_ASSET_CALLBACK_002_05', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07 + * @tc.name : createAsset + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07', 0, async function (done) { + const test_num = '001_07'; try { - asset.orientation = 2000; - asset.commitModify(commitModifyCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_05 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(() => { + try { + const id = asset.id; + const idOP = { + selections: fileKeyObj.ID + '= ?', + selectionArgs: ['' + id], + }; + media.getFileAssets(idOP, (error, newAssets) => { + try { + newAssets.getAllObject((error, newdataList) => { + try { + const newAsset = newdataList[0]; + if (asset.dateModified != undefined) { + if ( + newAsset.dateModified != + asset.dateModified + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify 002_05 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ASSET_CALLBACK_003 - * @tc.name : Get assetList By NoArgsfetchOp - * @tc.desc : Get assetList By NoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_CALLBACK_003', 0, async function (done) { - media.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack); - done(); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_08', 0, async function (done) { + const test_num = '001_08'; + try { + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', test_num, firstAsset, imageType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', test_num, midAsset, imageType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', test_num, lastAsset, imageType); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ASSET_CALLBACK_004 - * @tc.name : Get assetList By HasArgsfetchOp - * @tc.desc : Get assetList By HasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_09 + * @tc.name : createAsset + * @tc.desc : Get the width attribute * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_ASSET_CALLBACK_004', 0, async function (done) { - media.getFileAssets(fileHasArgsfetchOp, getFileAssetsCallBack); - done(); + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_09', 0, async function (done) { + const test_num = '001_09'; + try { + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPEN_ASSET_CALLBACK_005 - * @tc.name : Open asset - * @tc.desc : Open asset + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_OPEN_ASSET_CALLBACK_005_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_10', 0, async function (done) { + const test_num = '001_10'; try { - asset.open('Rw', openCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_01 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'height', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'height', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'height', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_01 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_OPEN_ASSET_CALLBACK_005_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11', 0, async function (done) { + const test_num = '001_11'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - asset1 = await media.createAsset(mediaType, "image00001.jpg", path); - asset1.open('w', openCallBack1); - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_02 success'); - done(); + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'orientation', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'orientation', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'orientation', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_02 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_OPEN_ASSET_CALLBACK_005_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CREATEASSET_CALLBACK_001_12', 0, async function (done) { + const test_num = '001_12'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - asset2 = await media.createAsset(mediaType, "image00002.jpg", path); - asset2.open('wts', openCallBack2); - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_03 success'); - done(); + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE, (error, path) => { + try { + media.getFileAssets(imagesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + imageType, + 'image3.jpg', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + if ( + creatAsset1.mediaType == + imageType + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_03 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); + // ------------------------------- image type end ----------------------------- - it('SUB_MEDIA_MEDIALIBRARY_OPEN_ASSET_CALLBACK_005_04', 0, async function (done) { + // ------------------------------- video type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01', 0, async function (done) { + const test_num = '002_01'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - asset3 = await media.createAsset(mediaType, "image00003.jpg", path); - asset3.open('wa', openCallBack3); - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_04 success'); - done(); + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO, (error, path) => { + try { + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + videoType, + 'video03.mp4', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + const asset2 = + dataList[0]; + media.createAsset( + videoType, + 'video04.mp4', + path, + ( + error, + creatAsset2 + ) => { + try { + asset2.open( + 'rw', + ( + error, + fd2 + ) => { + try { + creatAsset2.open( + 'rw', + ( + error, + creatAssetFd2 + ) => { + try { + copyFile( + fd2, + creatAssetFd2, + test_num, + done, + () => { + try { + creatAsset2.close( + creatAssetFd2, + () => { + try { + asset2.close( + fd2, + () => { + try { + if ( + creatAsset1.id != + creatAsset2.id + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_04 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_OPEN_ASSET_CALLBACK_005_05', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02 + * @tc.name : createAsset + * @tc.desc : Access to the file displayName and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02', 0, async function (done) { + const test_num = '002_02'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - var asset4 = await media.createAsset(mediaType, "image00004.jpg", path); - asset4.open('', openCallBack4); - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_05 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK open 005_05 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CLOSE_ASSET_CALLBACK_006 - * @tc.name : Close asset - * @tc.desc : Close asset + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03 + * @tc.name : createAsset + * @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_CLOSE_ASSET_CALLBACK_006_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03', 0, async function (done) { + const test_num = '002_03'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - var asset5 = await media.createAsset(mediaType, "image00005.jpg", path); - fd = await asset5.open('Rw'); - asset5.close(-1, closeCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_01 success'); - expect(true).assertTrue(); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_01 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_CLOSE_ASSET_CALLBACK_006_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_04 + * @tc.name : createAsset + * @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_CALLBACK_002_04', 0, async function (done) { + const test_num = '002_04'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - var asset6 = await media.createAsset(mediaType, "image00006.jpg", path); - fd = await asset6.open('Rw'); - asset6.close(0, closeCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_02 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_02 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_CLOSE_ASSET_CALLBACK_006_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_05 + * @tc.name : createAsset + * @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_CALLBACK_002_05', 0, async function (done) { + const test_num = '002_05'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - var asset7 = await media.createAsset(mediaType, "image00007.jpg", pathMove); - fd = await asset7.open('Rw'); - asset7.close("666", closeCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_03 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_03 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_CLOSE_ASSET_CALLBACK_006_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07 + * @tc.name : createAsset + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07', 0, async function (done) { + const test_num = '002_07'; try { - let mediaType = mediaLibrary.MediaType.IMAGE; - var asset8 = await media.createAsset(mediaType, "image00008.jpg", pathMoveCallback); - fd = await asset8.open('Rw'); - asset8.close(closeCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_04 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(() => { + try { + const id = asset.id; + const idOP = { + selections: fileKeyObj.ID + '= ?', + selectionArgs: ['' + id], + }; + media.getFileAssets(idOP, (error, newAssets) => { + try { + newAssets.getAllObject((error, newdataList) => { + try { + const newAsset = newdataList[0]; + if (asset.dateModified != undefined) { + if ( + newAsset.dateModified != + asset.dateModified + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK close 006_04 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007 - * @tc.name : Favourite - * @tc.desc : Favourite + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08', 0, async function (done) { + const test_num = '002_08'; try { - asset.isFavorite(isFavoriteCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK favourite 007_01 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', test_num, firstAsset, videoType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', test_num, midAsset, videoType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', test_num, lastAsset, videoType); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK favourite 007_01 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ASSET_CALLBACK_008 - * @tc.name : Trash - * @tc.desc : Trash + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_09 + * @tc.name : createAsset + * @tc.desc : Get the width attribute * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SSUB_MEDIA_MEDIALIBRARY_TRASH_ASSET_CALLBACK_008_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_09', 0, async function (done) { + const test_num = '002_09'; try { - asset.isTrash(isTrashCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK trash 008_01 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK trash 008_01 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_DIR_ASSET_CALLBACK_009 - * @tc.name : dir - * @tc.desc : dir + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_DIR_ASSET_CALLBACK_009_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_10', 0, async function (done) { + const test_num = '002_10'; try { - asset.isDirectory(isDirectoryCallBack); - console.info('MediaLibraryTest : ASSET_CALLBACK dir 009_01 success'); - done(); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'height', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'height', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'height', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); } catch (error) { - console.info('MediaLibraryTest : ASSET_CALLBACK dir 009_01 fail, message = ' + error); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010 - * @tc.name : On - * @tc.desc : On + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11', 0, async function (done) { + const test_num = '002_11'; try { - media.on(['image'], function (mediaChangeListener) { - console.log('MediaLibraryTest on mediaChangeListener 010_01 success'); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'orientation', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'orientation', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'orientation', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest on mediaChangeListener 010_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CALLBACK_002_12', 0, async function (done) { + const test_num = '002_12'; try { - media.on(['file'], function (mediaChangeListener) { - console.log('MediaLibraryTest on mediaChangeListener 010_02 success'); + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'duration', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'duration', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'duration', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest on mediaChangeListener 010_02 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } - }); - it('SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CREATEASSET_CALLBACK_002_13', 0, async function (done) { + const test_num = '002_13'; try { - media.on(['audio'], function (mediaChangeListener) { - console.log('MediaLibraryTest on mediaChangeListener 010_03 success'); + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO, (error, path) => { + try { + media.getFileAssets(videosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + videoType, + 'video3.mp4', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + if ( + creatAsset1.mediaType == + videoType + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest on mediaChangeListener 010_03 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } - }); + // ------------------------------- video type end ----------------------------- - it('SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010_04', 0, async function (done) { + // ------------------------------- audio type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01', 0, async function (done) { + const test_num = '003_01'; try { - media.on(['video', "smartalbum", "device"], function (mediaChangeListener) { - console.log('MediaLibraryTest on mediaChangeListener 010_04 success'); + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO, (error, path) => { + try { + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + audioType, + 'audio03.mp3', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + const asset2 = + dataList[0]; + media.createAsset( + audioType, + 'audio04.mp3', + path, + ( + error, + creatAsset2 + ) => { + try { + asset2.open( + 'rw', + ( + error, + fd2 + ) => { + try { + creatAsset2.open( + 'rw', + ( + error, + creatAssetFd2 + ) => { + try { + copyFile( + fd2, + creatAssetFd2, + test_num, + done, + () => { + try { + creatAsset2.close( + creatAssetFd2, + () => { + try { + asset2.close( + fd2, + () => { + try { + if ( + creatAsset1.id != + creatAsset2.id + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest on mediaChangeListener 010_04 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_ON_CALLBACK_010_05', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02 + * @tc.name : createAsset + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02', 0, async function (done) { + const test_num = '003_02'; try { - media.on(function (mediaChangeListener) { - console.log('MediaLibraryTest on mediaChangeListener 010_05 success'); + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(false).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest on mediaChangeListener 010_05 fail, message = ' + error); - expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_OFF_CALLBACK_011 - * @tc.name : Off - * @tc.desc : Off + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03 + * @tc.name : createAsset + * @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_OFF_CALLBACK_011_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03', 0, async function (done) { + const test_num = '003_03'; try { - media.off(['image'], function (mediaChangeListener) { - console.log('MediaLibraryTest off mediaChangeListener 011_01 success'); + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest off mediaChangeListener 011_01 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_OFF_CALLBACK_011_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_04 + * @tc.name : createAsset + * @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_CALLBACK_003_04', 0, async function (done) { + const test_num = '003_04'; try { - media.off(['file'], function (mediaChangeListener) { - console.log('MediaLibraryTest off mediaChangeListener 011_02 success'); + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest off mediaChangeListener 011_02 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } - }); - it('SUB_MEDIA_MEDIALIBRARY_OFF_CALLBACK_011_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_05 + * @tc.name : createAsset + * @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_CALLBACK_003_05', 0, async function (done) { + const test_num = '003_05'; try { - media.off(['audio'], function (mediaChangeListener) { - console.log('MediaLibraryTest off mediaChangeListener 011_03 success'); + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest off mediaChangeListener 011_03 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } - }); - it('SUB_MEDIA_MEDIALIBRARY_OFF_CALLBACK_011_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07 + * @tc.name : createAsset + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07', 0, async function (done) { + const test_num = '003_07'; try { - media.off(['video', "smartalbum", "device"], function (mediaChangeListener) { - console.log('MediaLibraryTest off mediaChangeListener 011_04 success'); + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(() => { + try { + const id = asset.id; + const idOP = { + selections: fileKeyObj.ID + '= ?', + selectionArgs: ['' + id], + }; + media.getFileAssets(idOP, (error, newAssets) => { + try { + newAssets.getAllObject((error, newdataList) => { + try { + const newAsset = newdataList[0]; + if (asset.dateModified != undefined) { + if ( + newAsset.dateModified != + asset.dateModified + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - expect(true).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest off mediaChangeListener 011_04 fail, message = ' + error); - expect(false).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - it('SUB_MEDIA_MEDIALIBRARY_OFF_CALLBACK_011_05', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08', 0, async function (done) { + const test_num = '003_08'; try { - media.off(['666'], function (mediaChangeListener) { - console.log('MediaLibraryTest off mediaChangeListener 011_05 success'); + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', test_num, firstAsset, audioType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', test_num, midAsset, audioType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', test_num, lastAsset, audioType); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } }); - //expect(false).assertTrue(); - done(); } catch (error) { - console.log('MediaLibraryTest off mediaChangeListener 011_05 fail, message = ' + error); - //expect(true).assertTrue(); - done(); + executeAtError(test_num, error, done); } }); - - function getAllObjectInfo(data) { - if (data != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK id is ' + data.id); - console.info('MediaLibraryTest : ASSET_CALLBACK uri is ' + data.uri); - console.info('MediaLibraryTest : ASSET_CALLBACK displayName is ' + data.displayName); - console.info('MediaLibraryTest : ASSET_CALLBACK mediaType is ' + data.title); - console.info('MediaLibraryTest : ASSET_CALLBACK relativePath is ' + data.relativePath); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK getAllObjectInfo no assets'); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_09 + * @tc.name : createAsset + * @tc.desc : Get the artist attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_09', 0, async function (done) { + const test_num = '003_09'; + try { + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'width', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'width', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'width', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } - } + }); - function createAssetCallBack(err, asset) { - if (asset != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK createAsset Successfull ' + asset.uri); - console.info('MediaLibraryTest : ASSET_CALLBACK createAsset : PASS'); - media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE, getPublicDirectory); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK createAsset Unsuccessfull ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK createAsset : FAIL'); - expect(false).assertTrue(); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CALLBACK_003_10', 0, async function (done) { + const test_num = '003_10'; + try { + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'albumName', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'albumName', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'albumName', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } + }); - } - - function getPublicDirectory(err, publicDirectory) { - if (publicDirectory != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK publicDirectory = ' + publicDirectory); - media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK publicDirectory Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK publicDirectory : FAIL'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CALLBACK_003_11', 0, async function (done) { + const test_num = '003_11'; + try { + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'duration', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'duration', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'duration', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } + }); - } - - function commitModifyCallBack(err, commitModify) { - if (commitModify != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify success'); - expect(true).assertTrue(); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK commitModify : FAIL'); - expect(false).assertTrue(); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CALLBACK_003_12', 0, async function (done) { + const test_num = '003_12'; + try { + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO, (error, path) => { + media.getFileAssets(audiosfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + audioType, + 'audio3.mp3', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + if ( + creatAsset1.mediaType == + audioType + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + }); + } catch (error) { + executeAtError(test_num, error, done); } + }); + // ------------------------------- audio type end ----------------------------- - } - - function getFileAssetsCallBack(err, fetchFileResult) { - if (fetchFileResult != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK fetchFileResult success'); - fetchFileResult.getAllObject((err1, data1) => { - if (data1 != undefined) { - data1.forEach(getAllObjectInfo); - console.info('MediaLibraryTest : getAllObject :PASS'); - expect(true).assertTrue(); - done(); - } - console.info('MediaLibraryTest : getFileAssets :No data'); - done(); - }); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK fetchFileResult Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK fetchFileResult : FAIL'); - expect(false).assertTrue(); - done(); + // ------------------------------- file type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01', 0, async function (done) { + const test_num = '004_01'; + try { + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD, (error, path) => { + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + fileType, + 'file03.txt', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + const asset2 = + dataList[0]; + media.createAsset( + fileType, + 'file04.txt', + path, + ( + error, + creatAsset2 + ) => { + try { + asset2.open( + 'rw', + ( + error, + fd2 + ) => { + try { + creatAsset2.open( + 'rw', + ( + error, + creatAssetFd2 + ) => { + try { + copyFile( + fd2, + creatAssetFd2, + test_num, + done, + () => { + try { + creatAsset2.close( + creatAssetFd2, + () => { + try { + asset2.close( + fd2, + () => { + try { + if ( + creatAsset1.id != + creatAsset2.id + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } - } + }); - function openCallBack(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - expect(false).assertTrue(); - done(); - } else { - console.info("==========================asset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================asset.close begin=======================>"); - asset.close(fd, closeCallBack); - console.info("==========================asset.close end=======================>"); - expect(true).assertTrue(); - done(); - } - } - function openCallBack(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - expect(false).assertTrue(); - done(); - } else { - console.info("==========================asset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================asset.close begin=======================>"); - asset.close(fd, closeCallBack); - console.info("==========================asset.close end=======================>"); - expect(true).assertTrue(); - done(); - } - } - function openCallBack1(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - expect(false).assertTrue(); - done(); - } else { - console.info("==========================asset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================asset.close begin=======================>"); - asset1.close(fd, closeCallBack); - console.info("==========================asset.close end=======================>"); - expect(true).assertTrue(); - done(); - } - } - function openCallBack2(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - expect(false).assertTrue(); - done(); - } else { - console.info("==========================asset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================asset.close begin=======================>"); - asset2.close(fd, closeCallBack); - console.info("==========================asset.close end=======================>"); - expect(true).assertTrue(); - done(); - } - } - function openCallBack3(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - expect(false).assertTrue(); - done(); - } else { - console.info("==========================asset.open success=======================>"); - console.debug("open success fd = " + JSON.stringify(fd)); - console.info("==========================asset.close begin=======================>"); - asset3.close(fd, closeCallBack); - console.info("==========================asset.close end=======================>"); - expect(true).assertTrue(); - done(); - } - } - function openCallBack4(openError, fd) { - if (openError != undefined) { - console.info('MediaLibraryTest : open : FAIL ' + openError.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - done(); - } else { - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02 + * @tc.name : createAsset + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02', 0, async function (done) { + const test_num = '004_02'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'displayName', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'displayName', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'displayName', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } - } + }); - function closeCallBack(closeErr) { - if (closeErr != undefined) { - console.info('MediaLibraryTest : close : FAIL ' + closeErr.message); - console.info('MediaLibraryTest : ASSET_CALLBACK : FAIL'); - done(); - } else { - console.info("==========================asset.close success=======================>"); - done(); - } - } - function isDirectoryCallBack(err, isDirectory) { - if (isDirectory != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isDirectory = ' + isDirectory); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK isDirectory Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK isDirectory : FAIL'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03 + * @tc.name : createAsset + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03', 0, async function (done) { + const test_num = '004_03'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'relativePath', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'relativePath', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'relativePath', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } + }); - } - function favoriteCallBack(err, favorite) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK favorite'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_04 + * @tc.name : createAsset + * @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_CALLBACK_004_04', 0, async function (done) { + const test_num = '004_04'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'size', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'size', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'size', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); - } - function isFavoriteCallBack(err, isFavorite) { - if (isFavorite != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isFavorite = ' + isFavorite); - asset.favorite(true, favoriteCallBack); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite : FAIL'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_05 + * @tc.name : createAsset + * @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_CALLBACK_004_05', 0, async function (done) { + const test_num = '004_05'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'dateAdded', test_num, firstAsset); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'dateAdded', test_num, midAsset); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'dateAdded', test_num, lastAsset); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset 004_05 failed, message = ${error}` + ); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } + }); - } - function trashCallBack(err, trash) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash'); - done(); - } - function isTrashCallBack(err, isTrash) { - if (isTrash != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isTrash = ' + isTrash); - asset.trash(true, trashCallBack); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK isTrash Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK isTrash : FAIL'); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07 + * @tc.name : createAsset + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07', 0, async function (done) { + const test_num = '004_07'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(() => { + const id = asset.id; + const idOP = { + selections: fileKeyObj.ID + '= ?', + selectionArgs: ['' + id], + }; + media.getFileAssets(idOP, (error, newAssets) => { + try { + newAssets.getAllObject((error, newdataList) => { + try { + const newAsset = newdataList[0]; + if (asset.dateModified != undefined) { + if ( + newAsset.dateModified != asset.dateModified + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect(false).assertTrue(); + done(); + } + + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } - } - 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); - - media.deleteAsset(data3.uri, (err4, data4) => { - if (data4 == 0) { - console.info('MediaLibraryTest : Delete Album Successfull ' + data4); - console.info('MediaLibraryTest : Delete Asset : PASS'); - } else { - console.info('MediaLibraryTest : Album is not modified ' + err4.message); - console.info('MediaLibraryTest : Modify Asset : FAIL'); - } - }); - } - function deleteAssetCallBack(err, deleteAsset) { - if (deleteAsset != undefined) { - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK deleteAssetCode = ' + deleteAsset); - console.info('MediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK deleteAssetCode success'); - done(); - } else { - console.info('MediaLibraryTest : ASSET_CALLBACK deleteAsset Unsuccessfull = ' + err); - console.info('MediaLibraryTest : ASSET_CALLBACK deleteAsset : FAIL'); - done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_08', 0, async function (done) { + const test_num = '004_08'; + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const firstAsset = dataList[0]; + checkAssetAttr(done, 'mediaType', test_num, firstAsset, fileType); + + const midAsset = dataList[Math.floor(dataList.length / 2)]; + checkAssetAttr(done, 'mediaType', test_num, midAsset, fileType); + + const lastAsset = dataList[dataList.length - 1]; + checkAssetAttr(done, 'mediaType', test_num, lastAsset, fileType); + + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect(true).assertTrue(); + done(); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); } - } + }); -}) + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_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_CALLBACK_004_09', 0, async function (done) { + const test_num = '004_09'; + try { + media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD, (error, path) => { + try { + media.getFileAssets(filesfetchOp, (error, fileAssets) => { + try { + fileAssets.getAllObject((error, dataList) => { + try { + const asset1 = dataList[0]; + media.createAsset( + fileType, + 'file3.txt', + path, + (error, creatAsset1) => { + try { + asset1.open('rw', (error, fd1) => { + try { + creatAsset1.open( + 'rw', + (error, creatAssetFd1) => { + try { + copyFile( + fd1, + creatAssetFd1, + test_num, + done, + () => { + try { + creatAsset1.close( + creatAssetFd1, + () => { + try { + asset1.close( + fd1, + () => { + try { + if ( + creatAsset1.mediaType == + fileType + ) { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} passed` + ); + expect( + true + ).assertTrue(); + done(); + } else { + console.info( + `MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed` + ); + expect( + false + ).assertTrue(); + done(); + } + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError( + test_num, + error, + done + ); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + } + ); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + } catch (error) { + executeAtError(test_num, error, done); + } + }); + // ------------------------------- file 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 ab64bfe344385a861a68d6bb41a29ff2626efd47..87184929201867efc3897edd0f4bda4f1ba24c46 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,729 +1,728 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility'; -import fileio from '@ohos.fileio'; - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; -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(`ASSET_PROMISE getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } else if (asset[attr] == undefined) { - console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`); - expect(false).assertTrue(); - done(); - } -} - -let path; -let presetAsset; -let displayName; -let id; -let mediaType; -let orientation = 0; -describe('fileTestPromise.test.js', function () { - var context = featureAbility.getContext(); - console.info('getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('getMediaLibrary OUT'); - 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_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(imagesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - presetAsset = asset1; - const creatAsset1 = await media.createAsset( - imageType, - `${new Date().getTime()}.jpg`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.jpg`; - const asset2 = dataList[1]; - const creatAsset2 = await media.createAsset(imageType, displayName, path); - const fd2 = await asset2.open('rw'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = imageType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 001_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file displayName and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(imagesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - await asset.commitModify(); - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_PROMISE getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 001_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 001_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 001_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11 - * @tc.name : createAsset - * @tc.desc : Get the orientaion attribute - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.orientation == orientation).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 001_11 failed, message = ' + error); - } - }); - - // ------------------------------- image type end ----------------------------- - - // ------------------------------- video type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset( - videoType, - `${new Date().getTime()}.mp4`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp4`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(videoType, displayName, path); - const fd2 = await asset2.open('rw'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = videoType; - - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 002_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file displayName and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - await asset.commitModify(); - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_PROMISE getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 002_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 002_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 002_08 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11 - * @tc.name : createAsset - * @tc.desc : Get the orientaion attribute - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.orientation == orientation).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 002_11 failed, message = ' + error); - } - }); - // ------------------------------- video type end ----------------------------- - - // ------------------------------- audio type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset( - audioType, - `${new Date().getTime()}.mp3`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.mp3`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(audioType, displayName, path); - const fd2 = await asset2.open('rw'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = audioType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 003_01 failed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file name and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.displayName == displayName).assertTrue(); - - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - await asset.commitModify(); - - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_PROMISE getFileAssets 003_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 003_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 003_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 003_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 003_08 failed, message = ' + error); - } - }); - - // ------------------------------- audio type end ----------------------------- - - // ------------------------------ file type start ---------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01 - * @tc.name : createAsset - * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 0, async function (done) { - try { - path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset( - fileType, - `${new Date().getTime()}.bat`, - path - ); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - displayName = `${new Date().getTime()}.bat`; - const asset2 = dataList[0]; - const creatAsset2 = await media.createAsset(fileType, displayName, path); - const fd2 = await asset2.open('rw'); - const creatAssetFd2 = await creatAsset2.open('rw'); - await copyFile(fd2, creatAssetFd2); - await creatAsset2.close(creatAssetFd2); - await asset2.close(fd2); - id = creatAsset2.id; - mediaType = fileType; - expect(creatAsset1.id != creatAsset2.id).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 004_01 failed' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02 - * @tc.name : getFileAssets - * @tc.desc : Access to the file name and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.displayName == displayName).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03 - * @tc.name : getFileAssets - * @tc.desc : Access to the file relativePath and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.relativePath == path).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_07 - * @tc.name : getFileAssets - * @tc.desc : Access to the file dateModified and validation is not undefined - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_07', 0, async function (done) { - try { - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset = dataList[0]; - asset.title = `title_${new Date().getTime()}`; - await asset.commitModify(); - const id = asset.id; - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const newAssets = await media.getFileAssets(idOP); - const newdataList = await newAssets.getAllObject(); - const newAsset = newdataList[0]; - - if (asset.dateModified != undefined) { - if (newAsset.dateModified != asset.dateModified) { - console.info('ASSET_PROMISE getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - } else if (newAsset.dateModified != undefined) { - console.info('ASSET_PROMISE getFileAssets 004_07 passed'); - expect(true).assertTrue(); - done(); - } else { - console.info('ASSET_PROMISE getFileAssets 004_07 failed'); - expect(false).assertTrue(); - done(); - } - } catch (error) { - console.info('ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08 - * @tc.name : createAsset - * @tc.desc : Insert a picture record, the retrieve attributes for images - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08', 0, async function (done) { - try { - const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; - const fileAssets = await media.getFileAssets(idOP); - const asset = await fileAssets.getFirstObject(); - expect(asset.mediaType == mediaType).assertTrue(); - done(); - } catch (error) { - console.info('ASSET_PROMISE createAsset 004_08 failed, message = ' + error); - } - }); - - // ------------------------------- file type end ----------------------------- -}); - +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +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(`ASSET_PROMISE getFileAssets ${testNum} failed`); + expect(false).assertTrue(); + done(); + } else if (asset[attr] == undefined) { + console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`); + expect(false).assertTrue(); + done(); + } +} + +let path; +let presetAsset; +let displayName; +let id; +let mediaType; +let orientation = 0; +describe('fileTestPromise.test.js', function () { + var context = featureAbility.getContext(); + console.info('getMediaLibrary IN'); + var media = mediaLibrary.getMediaLibrary(context); + console.info('getMediaLibrary OUT'); + 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_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_01', 0, async function (done) { + try { + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + presetAsset = asset1; + const creatAsset1 = await media.createAsset( + imageType, + `${new Date().getTime()}.jpg`, + path + ); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.jpg`; + const asset2 = dataList[1]; + const creatAsset2 = await media.createAsset(imageType, displayName, path); + const fd2 = await asset2.open('rw'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = imageType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file displayName and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + + expect(asset.displayName == displayName).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.relativePath == path).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + await asset.commitModify(); + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_PROMISE getFileAssets 001_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_PROMISE getFileAssets 001_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.mediaType == mediaType).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 001_08 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.orientation == orientation).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 001_11 failed, message = ' + error); + } + }); + + // ------------------------------- image type end ----------------------------- + + // ------------------------------- video type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01', 0, async function (done) { + try { + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset( + videoType, + `${new Date().getTime()}.mp4`, + path + ); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.mp4`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(videoType, displayName, path); + const fd2 = await asset2.open('rw'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = videoType; + + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 002_01 failed' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file displayName and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + + expect(asset.displayName == displayName).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + + expect(asset.relativePath == path).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + await asset.commitModify(); + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_PROMISE getFileAssets 002_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_PROMISE getFileAssets 002_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.mediaType == mediaType).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 002_08 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11 + * @tc.name : createAsset + * @tc.desc : Get the orientaion attribute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.orientation == orientation).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 002_11 failed, message = ' + error); + } + }); + // ------------------------------- video type end ----------------------------- + + // ------------------------------- audio type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 0, async function (done) { + try { + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset( + audioType, + `${new Date().getTime()}.mp3`, + path + ); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.mp3`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(audioType, displayName, path); + const fd2 = await asset2.open('rw'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = audioType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 003_01 failed'); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.displayName == displayName).assertTrue(); + + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.relativePath == path).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + await asset.commitModify(); + + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_PROMISE getFileAssets 003_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_PROMISE getFileAssets 003_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.mediaType == mediaType).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 003_08 failed, message = ' + error); + } + }); + + // ------------------------------- audio type end ----------------------------- + + // ------------------------------ file type start ---------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01 + * @tc.name : createAsset + * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 0, async function (done) { + try { + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset( + fileType, + `${new Date().getTime()}.bat`, + path + ); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.bat`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(fileType, displayName, path); + const fd2 = await asset2.open('rw'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = fileType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 004_01 failed' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02 + * @tc.name : getFileAssets + * @tc.desc : Access to the file name and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.displayName == displayName).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03 + * @tc.name : getFileAssets + * @tc.desc : Access to the file relativePath and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.relativePath == path).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_07 + * @tc.name : getFileAssets + * @tc.desc : Access to the file dateModified and validation is not undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_07', 0, async function (done) { + try { + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + await asset.commitModify(); + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_PROMISE getFileAssets 004_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_PROMISE getFileAssets 004_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_PROMISE getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); + } + } catch (error) { + console.info('ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08 + * @tc.name : createAsset + * @tc.desc : Insert a picture record, the retrieve attributes for images + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08', 0, async function (done) { + try { + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.mediaType == mediaType).assertTrue(); + done(); + } catch (error) { + console.info('ASSET_PROMISE createAsset 004_08 failed, message = ' + error); + } + }); + + // ------------------------------- file type end ----------------------------- +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestPromise.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a6a490e2214f98d9b28376b3ab440b62fa9e1b2d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestPromise.test.js @@ -0,0 +1,283 @@ +/* + * 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'; +let fileKeyObj = mediaLibrary.FileKey; + +let fileType = mediaLibrary.MediaType.FILE; +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; + +let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; + +let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; + +let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let allsfetchOp = { + selections: '', + selectionArgs: [], +}; + +const context = featureAbility.getContext(); +const media = mediaLibrary.getMediaLibrary(context); + +const filekeys = { + // parent: 'PARENT', + mimeType: 'MIME_TYPE', + size: 'SIZE', + dateAdded: 'DATE_ADDED', + title: 'TITLE', + // duration: 'DURATION', + // width: 'WIDTH', + // height: 'HEIGHT', + // orientation: 'ORIENTATION', + albumId: 'ALBUM_ID', + albumName: 'ALBUM_NAME', + artist: 'ARTIST', + // audioAlbum: 'AUDIOALBUM', + dateModified: 'DATE_MODIFIED', + // dateTaken: 'DATE_TAKEN', +} + +async function getFileAssetsBy(done, type) { + let assetOp = imagesfetchOp + if(type == 'audioAlbum' || type == 'artist' || type == 'duration') { + assetOp = audiosfetchOp + } + const fetchFileResult = await media.getFileAssets(assetOp); + const asset = await fetchFileResult.getFirstObject(); + let Op = { + selections: fileKeyObj[filekeys[type]] + '= ?', + selectionArgs: [asset[type] + ''], + }; + + try { + let fetchFileResult = await media.getFileAssets(Op); + const fetchCount = fetchFileResult.getCount(); + if(type == 'audioAlbum' || type == 'parent') { + expect(fetchCount == 0).assertTrue(); + } else{ + expect(fetchCount > 0).assertTrue(); + } + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } +} +function printAttr (done, asset, tNum) { + +} +describe('filekeyTestPromise.test.js', async function () { + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + // /** + // * @tc.number : test_fileKey_001 + // * @tc.name : getFileAssets + // * @tc.desc : filekey parentOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + + // it('test_fileKey_001', 0, async function (done) { + // getFileAssetsBy(done, 'parent'); + // }); + + /** + * @tc.number : test_fileKey_002 + * @tc.name : getFileAssets + * @tc.desc : filekey mimeTypeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_002', 0, async function (done) { + getFileAssetsBy(done, 'mimeType'); + }); + + /** + * @tc.number : test_fileKey_003 + * @tc.name : getFileAssets + * @tc.desc : filekey sizeOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_003', 0, async function (done) { + getFileAssetsBy(done, 'size'); + }); + + /** + * @tc.number : test_fileKey_004 + * @tc.name : getFileAssets + * @tc.desc : filekey dateAddedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_004', 0, async function (done) { + + getFileAssetsBy(done, 'dateAdded'); + }); + + /** + * @tc.number : test_fileKey_005 + * @tc.name : getFileAssets + * @tc.desc : filekey dateModifiedOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_005', 0, async function (done) { + getFileAssetsBy(done, 'dateModified'); + }); + + // /** + // * @tc.number : test_fileKey_006 + // * @tc.name : getFileAssets + // * @tc.desc : filekey dateTakenOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_006', 0, async function (done) { + // getFileAssetsBy(done, 'dateTaken'); + // }); + + /** + * @tc.number : test_fileKey_007 + * @tc.name : getFileAssets + * @tc.desc : filekey titleOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_007', 0, async function (done) { + getFileAssetsBy(done, 'title'); + }); + + // /** + // * @tc.number : test_fileKey_008 + // * @tc.name : getFileAssets + // * @tc.desc : filekey durationOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_008', 0, async function (done) { + // getFileAssetsBy(done, 'duration'); + // }); + + // /** + // * @tc.number : test_fileKey_009 + // * @tc.name : getFileAssets + // * @tc.desc : filekey widthOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_009', 0, async function (done) { + // getFileAssetsBy(done, 'width'); + // }); + + // /** + // * @tc.number : test_fileKey_010 + // * @tc.name : getFileAssets + // * @tc.desc : filekey heightOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_010', 0, async function (done) { + // getFileAssetsBy(done, 'height'); + // }); + + // /** + // * @tc.number : test_fileKey_011 + // * @tc.name : getFileAssets + // * @tc.desc : filekey orientationOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_011', 0, async function (done) { + // getFileAssetsBy(done, 'orientation'); + // }); + + /** + * @tc.number : test_fileKey_012 + * @tc.name : getFileAssets + * @tc.desc : filekey widthOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_012', 0, async function (done) { + getFileAssetsBy(done, 'albumId'); + }); + + /** + * @tc.number : test_fileKey_0013 + * @tc.name : getFileAssets + * @tc.desc : filekey albumNameOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_0013', 0, async function (done) { + getFileAssetsBy(done, 'albumName'); + }); + + /** + * @tc.number : test_fileKey_0014 + * @tc.name : getFileAssets + * @tc.desc : filekey artistOp + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('test_fileKey_0014', 0, async function (done) { + getFileAssetsBy(done, 'artist'); + }); + + // /** + // * @tc.number : test_fileKey_0015 + // * @tc.name : getFileAssets + // * @tc.desc : filekey audioAlbumOp + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('test_fileKey_0015', 0, async function (done) { + // getFileAssetsBy(done, 'audioAlbum'); + // }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAlbumsPerformance.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAlbumsPerformance.test.js deleted file mode 100644 index baefb1da3c49e6368dc4e9f6e8ad755c403173f8..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAlbumsPerformance.test.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('getAlbumsPerformance.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let times = 25; - - let AlbumNoArgsfetchOp = { - selections: "", - selectionArgs: [""], - } - - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01', 0, async function (done) { - for (let i = 0; i < times; i++) { - const albumArray = await media.getAlbums(AlbumNoArgsfetchOp); - if (albumArray != undefined) { - console.info('MediaLibraryTest : getAlbums : PASS ' + albumArray.length); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getAlbums : FAIL'); - expect(false).assertTrue(); - } - } - console.info('MediaLibraryTest : for : end'); - done(); - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 end'); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestPromise.test.js new file mode 100644 index 0000000000000000000000000000000000000000..af84459b2994b0bf81447e68374173345bbeb59d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestPromise.test.js @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect +} from 'deccjsunit/index'; + +describe('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 () {}); + + + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02 begin'); + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02', 0, async function (done) { + done(); + let allPeerList = await media.getAllPeers(); + expect(allPeerList[1].DeviceType.TYPE_UNKNOWN).assertEqual(0); + expect(allPeerList[1].DeviceType.TYPE_LAPTOP).assertEqual(1); + expect(allPeerList[1].DeviceType.TYPE_PHONE).assertEqual(2); + expect(allPeerList[1].DeviceType.TYPE_TABLET).assertEqual(3); + expect(allPeerList[1].DeviceType.TYPE_WATCH).assertEqual(4); + expect(allPeerList[1].DeviceType.TYPE_CAR).assertEqual(5); + expect(allPeerList[1].DeviceType.TYPE_TV).assertEqual(6); + done(); + }); + + // it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_03', 0, async function (done) { + // try { + // let allPeerList = await media.getAllPeers(); + // deviceType = allPeerList[1].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_04', 0, async function (done) { + // try { + // let allPeerList = await media.getAllPeers(); + // deviceType = allPeerList[2].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + + // it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_05', 0, async function (done) { + // try { + // let allPeerList = await media.getAllPeers(); + // deviceType = allPeerList[3].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_05 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + // it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_06', 0, async function (done) { + // try { + // let allPeerList = await media.getAllPeers(); + // deviceType = allPeerList[4].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_06 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_DEVICETYPE_PROMISE_001_02', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // deviceType = allPeerList[0].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_02 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_PROMISE_001_02', 0, async function (done) { + try { + done(); + let allPeerList = await media.getActivePeers(); + networkId = allPeerList[0].networkId; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_01 peer.networkId = ' + networkId); + } catch (error) { + done(); + } + }); + + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_ISONLINE_PROMISE_001_02', 0, async function (done) { + try { + done(); + let allPeerList = await media.getActivePeers(); + isOnline = allPeerList[0].isOnline; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_01 peer.isOnline = ' + isOnline); + } catch (error) { + done(); + } + }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_DEVICETYPE_PROMISE_001_03', 0, async function (done) { + // try { + // done(); + // let allPeerList = await media.getActivePeers(); + // deviceType = allPeerList[1].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_PROMISE_001_03', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // networkId = allPeerList[1].networkId; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 peer.networkId = ' + networkId); + // if(networkId != undefined && networkId != '') { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_ISONLINE_PROMISE_001_03', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // isOnline = allPeerList[1].isOnline; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 peer.isOnline = ' + isOnline); + // if(isOnline) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_DEVICETYPE_PROMISE_001_04', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // deviceType = allPeerList[2].deviceType; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 peer.deviceType = ' + deviceType); + // if(deviceType == mediaLibrary.DeviceType.TYPE_UNKNOWN + // || deviceType == mediaLibrary.DeviceType.TYPE_LAPTOP + // || deviceType == mediaLibrary.DeviceType.TYPE_PHONE + // || deviceType == mediaLibrary.DeviceType.TYPE_TABLET + // || deviceType == mediaLibrary.DeviceType.TYPE_WATCH + // || deviceType == mediaLibrary.DeviceType.TYPE_CAR + // || deviceType == mediaLibrary.DeviceType.TYPE_TV) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_PROMISE_001_04', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // networkId = allPeerList[2].networkId; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 peer.networkId = ' + networkId); + // if(networkId != undefined && networkId != '') { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); + + + // it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_ISONLINE_PROMISE_001_04', 0, async function (done) { + // try { + // let allPeerList = await media.getActivePeers(); + // isOnline = allPeerList[2].isOnline; + // console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 peer.isOnline = ' + isOnline); + // if(isOnline) { + // expect(true).assertTrue(); + // done(); + // } + // } catch (error) { + // expect(false).assertTrue(); + // done(); + // } + // }); +}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestPromise.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a697d7e4d06468a351197e82b6ccfede4fc75f8d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestPromise.test.js @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import 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 () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_01', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_01 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_01 fail, message = ' + error); + done(); + } + }); + + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_02', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + peer = allPeerList[0]; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_02 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_02 fail, message = ' + error); + done(); + } + }); + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_03', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + peer = allPeerList[1]; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_03 fail, message = ' + error); + done(); + } + }); + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + peer = allPeerList[2]; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_04 fail, message = ' + error); + done(); + } + }); + + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_05', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + peer = allPeerList[3]; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_05 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_05 fail, message = ' + error); + done(); + } + }); + + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_06', 0, async function (done) { + try { + done(); + let allPeerList = await media.getAllPeers(); + peer = allPeerList[4]; + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_06 peer.deviceName = ' + peer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_PROMISE getAllPeers 001_06 fail, message = ' + error); + done(); + } + }); + + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_01', 0, async function (done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[0]; + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_01 activePeer.deviceName = ' + activePeer.deviceName); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_01 fail, message = ' + error); + done(); + } + }); + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_02', 0, async function (done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[0]; + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_02 activePeer.deviceName = ' + activePeer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_02 fail, message = ' + error); + done(); + } + }); + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_03', 0, async function (done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[1]; + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_03 activePeer.deviceName = ' + activePeer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_03 fail, message = ' + error); + done(); + } + }); + + + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_04', 0, async function (done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[2]; + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_04 activePeer.deviceName = ' + activePeer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_PROMISE getActivePeers 001_04 fail, message = ' + error); + done(); + } + }); +}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance.test.js deleted file mode 100644 index 1a87a92686976630b504564fd9892f8679a11ebb..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance.test.js +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('getFileAssetsPerformance.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let times = 25; - let queryResultSet_; - let fileList_; - let fileKeyObj = mediaLibrary.FileKey - let type = mediaLibrary.MediaType.IMAGE - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + " = ? ", - selectionArgs: [type.toString()], - order: fileKeyObj.DATE_ADDED, - } - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01 - * @tc.name : Create an image file asset in predefined path - * @tc.desc : Create an image file asset in predefined path - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01', 0, async function (done) { - for (let i = 0; i < times; i++) { - const queryResultSet = await media.getFileAssets(fetchOp); - if (queryResultSet != undefined) { - console.info('MediaLibraryTest : getFileAssets : PASS ' + queryResultSet.getCount()); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getFileAssets : FAIL'); - expect(false).assertTrue(); - } - } - console.info('MediaLibraryTest : for : end'); - done(); - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01 end'); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance_object.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance_object.test.js deleted file mode 100644 index 5df5e6bd9ac37d7a661dd7ade596adcd15e579d0..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getFileAssetsPerformance_object.test.js +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('getFileAssetsPerformance_object.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let times = 100; - let queryResultSet_; - let fileList_; - let fileKeyObj = mediaLibrary.FileKey - let type = mediaLibrary.MediaType.IMAGE - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + " = ? ", - selectionArgs: [type.toString()], - order: fileKeyObj.DATE_ADDED, - } - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ALL_OBJECT_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALL_OBJECT_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_ALL_OBJECT_PERFORMANCE_01', 0, async function (done) { - console.info('MediaLibraryTest : getFileAssets begin'); - const queryResultSet = await media.getFileAssets(fetchOp); - queryResultSet_ = queryResultSet; - console.info('MediaLibraryTest : getFileAssets after'); - if (queryResultSet_ == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALL_OBJECT_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < 3; i++) { - console.info('MediaLibraryTest : getAllObject begin :times: ' + i); - const data1 = await queryResultSet_.getAllObject(); - if (data1 != undefined) { - console.info('MediaLibraryTest : getAllObject :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getAllObject :FAIL times: ' + i); - expect(false).assertTrue(); - } - - console.info('MediaLibraryTest : getAllObject after :times: ' + i); - } - } - - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALL_OBJECT_PERFORMANCE_01 end'); - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FIRST_OBJECT_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FIRST_OBJECT_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_FIRST_OBJECT_PERFORMANCE_01', 0, async function (done) { - if (queryResultSet_ == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FIRST_OBJECT_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : getFirstObject begin :times: ' + i); - const fileAsset = await queryResultSet_.getFirstObject(); - if (fileAsset != undefined) { - console.info('MediaLibraryTest : getFirstObject :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getFirstObject :FAIL times: ' + i); - expect(false).assertTrue(); - } - - console.info('MediaLibraryTest : getFirstObject after :times: ' + i); - } - } - - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FIRST_OBJECT_PERFORMANCE_01 end'); - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_IS_AFTER_LAST_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_IS_AFTER_LAST_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_IS_AFTER_LAST_PERFORMANCE_01', 0, async function (done) { - if (queryResultSet_ == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_IS_AFTER_LAST_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : isAfterLast begin :times: ' + i); - const isAfterLastBool = queryResultSet_.isAfterLast(); - expect(!isAfterLastBool).assertTrue(); - - console.info('MediaLibraryTest : isAfterLast after :times: ' + i); - } - } - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_IS_AFTER_LAST_PERFORMANCE_01 end'); - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_LAST_OBJECT_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_LAST_OBJECT_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_LAST_OBJECT_PERFORMANCE_01', 0, async function (done) { - if (queryResultSet_ == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_LAST_OBJECT_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : getLastObject begin :times: ' + i); - const fileAsset = await queryResultSet_.getLastObject(); - if (fileAsset != undefined) { - console.info('MediaLibraryTest : getLastObject :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getLastObject :FAIL times: ' + i); - expect(false).assertTrue(); - } - - console.info('MediaLibraryTest : getLastObject after :times: ' + i); - } - } - - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_LAST_OBJECT_PERFORMANCE_01 end'); - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_POSITION_OBJECT_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_POSITION_OBJECT_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_POSITION_OBJECT_PERFORMANCE_01', 0, async function (done) { - if (queryResultSet_ == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_POSITION_OBJECT_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : getPositionObject begin :times: ' + i); - const fileAsset = await queryResultSet_.getPositionObject(i); - if (fileAsset != undefined) { - console.info('MediaLibraryTest : getPositionObject :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getPositionObject :FAIL times: ' + i); - expect(false).assertTrue(); - } - - console.info('MediaLibraryTest : getPositionObject after :times: ' + i); - } - } - - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_POSITION_OBJECT_PERFORMANCE_01 end'); - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_NEXT_OBJECT_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_NEXT_OBJECT_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_NEXT_OBJECT_PERFORMANCE_01', 0, async function (done) { - console.info('MediaLibraryTest : getFileAssets begin'); - const queryResultSet = await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets after'); - if (queryResultSet == undefined) { - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_NEXT_OBJECT_PERFORMANCE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } else { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : getNextObject begin :times: ' + i); - const fileAsset = await queryResultSet.getNextObject(); - if (fileAsset != undefined) { - console.info('MediaLibraryTest : getNextObject :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getNextObject :FAIL isAfterLast: ' + queryResultSet_.isAfterLast()); - console.info('MediaLibraryTest : getNextObject :FAIL times: ' + i); - expect(false).assertTrue(); - } - - console.info('MediaLibraryTest : getNextObject after :times: ' + i); - } - } - - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_NEXT_OBJECT_PERFORMANCE_01 end'); - done(); - }); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getMediaFileAssetStatus.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getMediaFileAssetStatus.test.js deleted file mode 100644 index 64c98ad2d3c33dafd9ac8909e085e2c91b6fa9c5..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getMediaFileAssetStatus.test.js +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - -let fileKeyObj = mediaLibrary.FileKey -let type = mediaLibrary.MediaType.IMAGE -let fetchOp = { - selections : fileKeyObj.MEDIA_TYPE + " = ? ", - selectionArgs : [type.toString()], - order : fileKeyObj.DATE_ADDED, -} - -describe('getMediaFileAssetStatus', function () { - console.info("MediaLibraryTest Instance before"); - const media = mediaLibrary.getMediaLibrary(); - console.info("MediaLibraryTest Instance after"); - - /* - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_01 - * @tc.name : judge file asset trash or not - * @tc.desc : judge file asset trash or not - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_01', 0, async function () { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - const cur = Date.now() - let displayName = "FILE_ASSETS_TRASH_STATUS_01.jpg" + cur; - let rp = "Pictures/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileAsset) => { - if (fileAsset != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileAsset.uri); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS'); - fileAsset.isTrash((err, istrash) => { - console.info("MediaLibraryTest SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_01 " +istrash) - expect(istrash == false).assertTrue; - done(); - }) - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - } - catch (e) { - console.log('MediaLibraryTest has failed for ' + e); - expect(null).assertFail(); - } - }); - - /* - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_02 - * @tc.name : judge file asset trash or not - * @tc.desc : judge file asset trash or not - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_02', 0, async function () { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - const cur = Date.now() - let displayName = "FILE_ASSETS_TRASH_STATUS_02.jpg" + cur; - let rp = "Pictures/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileAsset) => { - if (fileAsset != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileAsset.uri); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS'); - - fileAsset.trash(true, (err) => { - fileAsset.isTrash((err, istrash) => { - console.info("MediaLibraryTest SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_02 " +istrash) - expect(istrash == true).assertTrue; - done(); - }) - }) - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - } - catch (e) { - console.log('MediaLibraryTest has failed for ' + e); - expect(null).assertFail(); - } - }); - - /* - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_03 - * @tc.name : judge file asset trash or not - * @tc.desc : judge file asset trash or not - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_03', 0, async function () { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - const cur = Date.now() - let displayName = "FILE_ASSETS_TRASH_STATUS_03.jpg" + cur; - let rp = "Pictures/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileAsset) => { - if (fileAsset != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileAsset.uri); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS'); - - fileAsset.trash(false, (err) => { - fileAsset.isTrash((err, istrash) => { - console.info("MediaLibraryTest SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_03 " +istrash) - expect(istrash == false).assertTrue; - done(); - }) - }) - - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - } - catch (e) { - console.log('MediaLibraryTest has failed for ' + e); - expect(null).assertFail(); - } - }); - - - /* - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_04 - * @tc.name : judge file asset trash or not - * @tc.desc : judge file asset trash or not - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_04', 0, async function () { - try { - let mediaType = mediaLibrary.MediaType.IMAGE; - const cur = Date.now() - let displayName = "FILE_ASSETS_TRASH_STATUS_03.jpg" + cur; - let rp = "Pictures/"; - console.info('MediaLibraryTest : createAsset begin'); - media.createAsset(mediaType, displayName, rp, (createAssetErr, fileAsset) => { - if (fileAsset != undefined) { - console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileAsset.uri); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS'); - - fileAsset.trash(true, (err) => { - fileAsset.isTrash((err, istrash) => { - console.info("SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_TRASH_STATUS_04 istrash " +istrash) - expect(istrash == false).assertFalse; - done(); - }) - }) - - } else { - console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL'); - expect(false).assertTrue(); - done(); - } - }); - } - catch (e) { - console.log('MediaLibraryTest has failed for ' + e); - expect(null).assertFail(); - } - }); - - -}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getPrivateAlbumsPerformance.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getPrivateAlbumsPerformance.test.js deleted file mode 100644 index 767820f0a01e685793fca83c8ec073f65e069048..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getPrivateAlbumsPerformance.test.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('getPrivateAlbumsPerformance.test.js', function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let times = 50; - - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01', 0, async function (done) { - for (let i = 0; i < times; i++) { - const albums = await media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_TRASH); - if (albums != undefined) { - console.info('MediaLibraryTest : getAlbums : PASS ' + albums[0].albumName); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : getAlbums : FAIL'); - expect(false).assertTrue(); - } - } - console.info('MediaLibraryTest : for : end'); - done(); - }); - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 end'); -}); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromise.test.js index 7847858cb312c8aec0329303618e226e725352a5..afc5187ad6b9625695d53c6d0d54b7b652f84165 100644 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromise.test.js +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromise.test.js @@ -52,9 +52,9 @@ let filesfetchOp = { selectionArgs: [fileType.toString()], }; -let imageAndAudiofetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ', - selectionArgs: [imageType.toString(), audioType.toString()], +let imageAndVideofetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), videoType.toString()], }; let imageAndVideoAndfilefetchOp = { selections: @@ -96,7 +96,7 @@ async function copyFile(fd1, fd2) { await fileio.write(fd2, buf); } -describe('GET_ALBUM.test.js', function () { +describe('mediaLibraryTestPromise.test.js', function () { const context = featureAbility.getContext(); const media = mediaLibrary.getMediaLibrary(context); @@ -130,8 +130,6 @@ describe('GET_ALBUM.test.js', function () { } }); - - /** * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 * @tc.name : getFileAssets @@ -222,7 +220,7 @@ describe('GET_ALBUM.test.js', function () { */ it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { try { - const fetchFileResult = await media.getFileAssets(imageAndAudiofetchOp); + const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); expect(fetchFileResult != undefined).assertTrue(); done(); } catch (error) { @@ -396,11 +394,11 @@ describe('GET_ALBUM.test.js', function () { */ it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { try { - let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; + let DIR_CDSA = mediaLibrary.DirectoryType.DIR_CDSA; - const dicResult = await media.getPublicDirectory(DIR_CAMERA); + const dicResult = await media.getPublicDirectory(DIR_CDSA); - expect(dicResult == 'Camera/').assertTrue(); + expect(dicResult == 'CDSA/').assertTrue(); done(); } catch (error) { console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); @@ -423,7 +421,7 @@ describe('GET_ALBUM.test.js', function () { const dicResult = await media.getPublicDirectory(DIR_VIDEO); console.log(dicResult); - expect(dicResult == 'Videos/').assertTrue(); + expect(dicResult == 'Movies/').assertTrue(); done(); } catch (error) { console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); @@ -830,5 +828,4 @@ describe('GET_ALBUM.test.js', function () { done(); } }); - }); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromiseOnOff.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromiseOnOff.test.js new file mode 100644 index 0000000000000000000000000000000000000000..776264207de269e490a0d5f491b0309358d9a62d --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestPromiseOnOff.test.js @@ -0,0 +1,550 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import fileio from '@ohos.fileio'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +describe('mediaLibraryTestPromiseOnOff.test.js', async function () { + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + + let fileKeyObj = mediaLibrary.FileKey; + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + let fileType = mediaLibrary.MediaType.FILE; + + let imagesfetchOp = { + selections: fileKeyObj.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()], + }; + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001 + * @tc.name : ON + * @tc.desc : ON Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) { + try { + let conut = 0; + media.on('imageChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + + const dataList = await fetchFileResult.getAllObject(); + + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + + expect(conut > 0).assertTrue(); + media.off('imageChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 001 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002 + * @tc.name : ON + * @tc.desc : ON Video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) { + try { + let conut = 0; + media.on('videoChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 1).assertTrue(); + media.off('videoChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 002 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003 + * @tc.name : ON + * @tc.desc : ON Audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) { + try { + let conut = 0; + media.on('audioChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 1).assertTrue(); + media.off('audioChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 003 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004 + * @tc.name : ON + * @tc.desc : ON File ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) { + try { + let conut = 0; + media.on('fileChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 1).assertTrue(); + media.off('fileChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 004 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005 + * @tc.name : ON + * @tc.desc : ON ALBUM ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) { + try { + let conut = 0; + media.on('albumChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 0).assertTrue(); + media.off('albumChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 005 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('albumChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON DEVICE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('deviceChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 0).assertTrue(); + media.off('deviceChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006 + * @tc.name : ON + * @tc.desc : ON REMOTE_FILE ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) { + try { + let conut = 0; + expect(true).assertTrue(); + done(); + media.on('remoteFileChange', () => { + conut++; + }); + const fetchFileResult = await media.getFileAssets(filesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + await new Promise((res) => setTimeout(() => res(), 3000)); + expect(conut == 0).assertTrue(); + media.off('remoteFileChange'); + done(); + } catch (error) { + console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001 + * @tc.name : off + * @tc.desc : off Image ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) { + try { + media.on('imageChange', () => { + console.info('MediaLibraryTest : off 001 failed'); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + }); + + media.off('imageChange'); + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 001 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('imageChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002 + * @tc.name : off + * @tc.desc : off video ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) { + try { + media.on('videoChange', () => { + console.info('MediaLibraryTest : off 002 failed'); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + }); + + media.off('videoChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 002 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 002 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('videoChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003 + * @tc.name : off + * @tc.desc : off audio ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) { + try { + media.on('audioChange', () => { + console.info('MediaLibraryTest : off 003 failed'); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + }); + + media.off('audioChange'); + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 003 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 003 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('audioChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004 + * @tc.name : off + * @tc.desc : off file ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) { + try { + media.on('fileChange', () => { + console.info('MediaLibraryTest : off 004 failed'); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + }); + + media.off('fileChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'changename'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 004 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 004 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005 + * @tc.name : off + * @tc.desc : off album ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { + try { + media.on('albumChange', () => { + console.info('MediaLibraryTest : off 004 failed'); + expect(false).assertTrue(); + media.off('albumChange'); + done(); + }); + + media.off('albumChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'albumChange'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 005 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 005 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006 + * @tc.name : off + * @tc.desc : off device ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006', 0, async function (done) { + try { + media.on('deviceChange', () => { + console.info('MediaLibraryTest : off 004 failed'); + expect(false).assertTrue(); + media.off('deviceChange'); + done(); + }); + + media.off('deviceChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'deviceChange'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 006 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007 + * @tc.name : off + * @tc.desc : off remoteFile ASSET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_007', 0, async function (done) { + try { + media.on('remoteFileChange', () => { + console.info('MediaLibraryTest : off 004 failed'); + expect(false).assertTrue(); + media.off('remoteFileChange'); + done(); + }); + + media.off('remoteFileChange'); + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + asset.title = 'remoteFileChange'; + await asset.commitModify(); + + await new Promise((res) => setTimeout(() => res(), 3000)); + + console.info('MediaLibraryTest : off 007 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : off 006 failed, error: ${error}`); + expect(false).assertTrue(); + media.off('fileChange'); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001 + * @tc.name : release + * @tc.desc : Release MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) { + try { + await media.release(); + console.info('MediaLibraryTest : release 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : release 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/smartAlbumOperatePerformance_object.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/smartAlbumOperatePerformance_object.test.js deleted file mode 100644 index 0c41b61da97672d065255dc470324349cdb7d626..0000000000000000000000000000000000000000 --- a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/smartAlbumOperatePerformance_object.test.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import mediaLibrary from '@ohos.multimedia.medialibrary'; -import featureAbility from '@ohos.ability.featureAbility' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -describe('smartAlbumOperatePerformance_object.test.js', async function () { - var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); - var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - - let times = 50; - - beforeAll(function () { - onsole.info('MediaLibraryTest: beforeAll'); - }) - - beforeEach(function () { - console.info('MediaLibraryTest: beforeEach'); - }) - afterEach(function () { - console.info('MediaLibraryTest: afterEach'); - }) - afterAll(function () { - console.info('MediaLibraryTest: afterAll'); - }) - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01 - * @tc.name : - * @tc.desc : - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01 begin'); - it('SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01', 0, async function (done) { - for (let i = 0; i < times; i++) { - console.info('MediaLibraryTest : createSmartAlbum begin :times: ' + i); - const smartAlbum = await media.createSmartAlbum("laoxu886"); - if (smartAlbum != undefined) { - console.info('MediaLibraryTest : createSmartAlbum albumuri ' + smartAlbum.albumUri); - console.info('MediaLibraryTest : createSmartAlbum :PASS times: ' + i); - expect(true).assertTrue(); - } else { - console.info('MediaLibraryTest : createSmartAlbum : FAIL'); - expect(false).assertTrue(); - } - console.info('MediaLibraryTest : createSmartAlbum after :times: ' + i); - } - console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01 end'); - done(); - }); -}); \ No newline at end of file